Node.js Tooling & Scripts
Relevant source files
The following files were used as context for generating this wiki page:
Node.js tooling and scripts in this project provide a robust automation layer for document management, content review, and production site optimization. These tools are designed to assist both human contributors and AI agents in maintaining high standards for the WHK (高中文化课) learning notes repository.
The system encompasses three primary domains: document analysis (read skills), quality assurance (review skills), and automated metadata generation. While the project uses uv for Python-based generation, Node.js serves as the primary engine for linting, complex Markdown manipulation, and post-build optimization of static assets.
Core Scripting Architecture
The project's Node.js infrastructure is organized into "skills" located within the scripts/ directory. These scripts are typically executed from the project root using node or bun for performance-intensive tasks.
The diagram above illustrates the functional separation between document analysis, content review, and final site optimization.
Sources: AGENTS.md, scripts/skills/read/SKILL.md, build.ts
Document Analysis (Read Skills)
The read skill set provides tools for scanning and analyzing the Markdown document library. These are critical for navigating the 100+ knowledge point documents within the docs/ folder.
| Tool | Purpose | Key Logic |
|---|---|---|
dir_h1.js | Directory scanning | Iterates through docs/ and identifies the first # heading in every file. |
file_headings.js | Structure mapping | Extracts all lines starting with # and appends line numbers for quick navigation. |
file_prelimit.js | Content preview | Reads the first 1000 non-whitespace characters, skipping YAML frontmatter if present. |
file_split.js | Large file handling | Segments files exceeding 20,000 characters into .tmp chunks for AI context window management. |
Sources: scripts/skills/read/SKILL.md:5-95, AGENTS.md:12-32
Content Review and Linting
The review system ensures that all contributions adhere to the project's strict Chinese/English mixed typesetting rules.
Review Dispatcher
The scripts/review/review.js script acts as a command dispatcher. It resolves the project root via Git and spawns sub-processes for specific review commands, ensuring consistent execution regardless of the current working directory.
Sources: scripts/review/review.js:5-35
Linting Workflow
The linting process is iterative, focusing on both automated formatting and deep content comprehension.
The sequence diagram demonstrates the recommended workflow for achieving clean documentation.
Sources: REVIEW.md:9-25, scripts/review/SKILL.md:9-20
Automated Metadata Generation
The scripts/frontmatter/generate_frontmatter.js script uses AI (via NVIDIA NIM API) to generate SEO-optimized metadata. It features:
- Concurrency Control: Uses
Bottleneckto manage API rate limits (30 RPM). - Targeting: Supports
--new(only missing),--days(modified within N days), or--file(specific target). - Validation: Generates titles (20-25 chars), descriptions (100-200 chars), and exactly 15-25 tags across five specific dimensions (Subject, Core Term, Detail Term, Application, Target Group).
Sources: scripts/frontmatter/generate_frontmatter.js:15-230
Production Build Optimization
The build.ts script, executed via the Bun runtime, performs "in-place" optimization on the generated static site. Unlike traditional builders that output to a new directory, it modifies the input directory directly to minimize overhead.
CSS and JavaScript Optimization
- CSS: Utilizes PostCSS with
autoprefixerfor browser compatibility andcssnanofor minification. It supports nested syntax and generates external sourcemaps. - JS: Uses
terserfor deep compression (2 passes) and mangles class/function names while preserving compatibility with ECMA 2020.
Sources: build.ts:60-95, build.ts:460-515
HTML Post-Processing
The HTML pipeline uses posthtml with custom plugins to perform aggressive optimizations:
- Head Reordering: Moves meta tags, titles, and styles to the top, while deferring scripts to optimize Largest Contentful Paint (LCP).
- Deduplication: Automatically removes duplicate meta tags (description, author) and structured data (
ld+json). - Asset Management: Merges multiple
<style>tags into single blocks and ensures all<img>tags havealtattributes derived from filenames if missing.
Sources: build.ts:100-330
Summary
The Node.js tooling in this repository bridges the gap between raw content creation and a professional, SEO-optimized static site. By providing specialized "read" and "review" skills, the project enables AI-assisted workflows that maintain high-quality educational content. The build-time optimizations ensure that the final output is performant, following modern web standards for resource prioritization and minification.