Architecture Overview
Relevant source files
The following files were used as context for generating this wiki page:
The WHK project is a specialized static site generation and content management system designed for hosting science-oriented educational notes. It utilizes a hybrid technology stack that combines Python-based Markdown processing with Node.js/Bun-based build optimizations and AI-driven content enhancement.
The system's primary goal is the high-fidelity rendering of scientific content, specifically mathematics and chemistry, using a customized KaTeX server-side rendering (SSR) pipeline. The architecture is divided into content authoring, automated metadata generation, site building, and post-processing optimization.
Content and Knowledge Structure
The project organizes knowledge into a hierarchical structure within the docs/ directory, primarily focusing on science and cultural subjects. Content is written in enhanced Markdown that supports advanced LaTeX, chemical equations via mhchem, and custom physical units.
Directory Organization
| Directory | Description |
|---|---|
docs/science/ | Core science notes (Mathematics, Physics, Chemistry, Biology) |
docs/cultural/ | Humanities and social sciences |
docs/blog/ | AI-assisted blog posts |
dev/supplement/ | Raw content awaiting integration into formal documentation |
Sources: README.md:46-56, scripts/workflows/supplement-integration-v2.md:27-28
Core Technical Stack
The architecture leverages various specialized tools to manage different stages of the document lifecycle:
- Static Site Generator: MkDocs with the Material for MkDocs theme.
- Math/Science Rendering: A custom KaTeX SSR plugin supporting macro definitions and chemical formulas.
- Package Management:
uvfor Python dependencies andnpm/bunfor JavaScript-based build tools. - Post-processing: A custom Bun-based script (
build.ts) for CSS/JS/HTML minification.
Sources: README.md:63-78, pyproject.toml:1-17, build.ts:1-12
Build and Optimization Pipeline
The build process follows a multi-stage pipeline where Markdown is first converted to HTML, and then the static assets are heavily optimized for performance and SEO.
The diagram above illustrates the transition from raw Markdown content to the final optimized production site.
Sources: README.md:126-135, build.ts:1-20, scripts/frontmatter/generate_frontmatter.js:15-30
Build Script (build.ts)
The build.ts script performs "in-place" optimization of the generated site. It utilizes several toolsets:
- CSS: PostCSS with
autoprefixer,postcss-nested, andcssnano. - JavaScript: Terser for deep compression and sourcemap generation.
- HTML: PostHTML for structural optimizations, including deduplicating meta tags, reordering
<head>elements for performance, and minification viahtml-minifier-terser.
Sources: build.ts:31-60, build.ts:210-235
AI Agent and Automation Layer
A significant portion of the architecture is dedicated to AI-driven workflows that ensure content quality and discoverability.
Metadata Generation
The generate_frontmatter.js script uses NVIDIA NIM API (specifically models like nemotron-3-nano-30b-a3b) to analyze article content and generate SEO-optimized Frontmatter.
| Field | Requirement |
|---|---|
| Title | 20-25 Chinese characters, SEO creative style |
| Description | 100-200 characters explaining technical/physical mechanisms |
| Tags | 15-25 tags covering Disciplines, Core Terms, and Application Scenarios |
Sources: scripts/frontmatter/generate_frontmatter.js:145-175
Review and Read Skills
The project defines "Skills" for AI agents to interact with the codebase:
- Read Skill: Tools like
dir_h1.js(scanning titles),file_headings.js(structural analysis), andfile_prelimit.js(content preview). - Review Skill: A linting system that checks for typography rules (e.g., spaces between CJK and alphanumeric characters) and fixes common errors in Markdown and formulas.
Sources: AGENTS.md:10-40, scripts/review/SKILL.md:1-15, REVIEW.md:5-25
Scientific Rendering Architecture
The project employs a custom KaTeX SSR solution to ensure math formulas are rendered server-side, improving load times and SEO.
This sequence shows how the KaTeX SSR plugin intercepts the build process to render mathematical and chemical notations before the final HTML is generated.
Sources: scripts/template.serve.yml:25-85, overrides/partials/integrations/head.html:65-75
Custom Macros and Shorthands
The architecture includes an extensive set of LaTeX macros for science subjects:
- Mathematics:
\RR,\rank,\vec(bold vectors). - Chemistry:
\ce(mhchem),\poly(polymer structures),\con(molar concentration). - Typography: Automatic mapping of full-width Chinese punctuation to standard LaTeX equivalents within math blocks.
Sources: scripts/template.serve.yml:38-84
Conclusion
The WHK architecture represents a sophisticated integration of modern web development tools and AI automation tailored for academic content. By combining the extensibility of MkDocs with custom-built Node.js optimization scripts and AI-driven quality control, it achieves a high-performance, SEO-friendly platform for complex scientific documentation.