Project Initialization Hooks
Relevant source files
The following files were used as context for generating this wiki page:
Project Initialization Hooks in the whk repository refer to the sequence of automated scripts and configurations that prepare the environment for document generation, asset optimization, and content verification. These hooks ensure that the environment meets the technical requirements for the static site generator and AI-assisted workflows before the final build or deployment.
The initialization process primarily involves environment checks (dependencies like cairosvg or pillow), configuration generation (rendering mkpandocs.yml via Jinja2), and rule synchronization (managing IDE-specific rules for AI agents). These hooks bridge the gap between raw Markdown content and a fully optimized, searchable, and compliant static site.
Environment and Dependency Verification
Before any build or serve operation, the system executes pre-build checks to determine the availability of critical graphical and data-processing dependencies. This is handled primarily by scripts/generate.py.
Automated Dependency Detection
The project uses importlib to verify the presence of Python packages required for the social plugin, specifically cairosvg and pillow. If these dependencies are missing or fail to load (often due to missing system libraries like libcairo-2.dll), the initialization hook automatically disables specific features to prevent build failures.
Configuration Generation
The core of the project's initialization is the dynamic generation of the mkpandocs.yml configuration file. This file is not stored statically but is rendered from a Jinja2 template (build.yml.jinja2) based on the current environment variables and local project state.
Initialization Parameters
The following table summarizes the data injected into the project configuration during the initialization phase:
| Parameter | Source | Description |
|---|---|---|
info | project.json | General project metadata and descriptions. |
site_url | CLI Argument | The base URL for the generated site. |
nav | docs/nav.json | Dynamic navigation structure derived from JSON. |
social_enabled | Dependency Check | Boolean flag based on cairosvg availability. |
giscus | project.json | Comment system configuration (can be disabled via --disable_giscus). |
Sources: scripts/generate.py:106-121, scripts/generate.py:24-44
AI Agent Rule Synchronization
The project maintains a sophisticated set of rules for AI agents (Cline, Gemini, Kilo, etc.). These rules are synchronized during initialization or via Git pre-commit hooks to ensure consistency across different development environments.
Rule Hierarchy and Maintenance
Rules are divided into manually maintained specifications and automatically synchronized IDE rules.
- Manual Rules: Found in
scripts/rules/style.md, these contain the ground truth for typography and formatting. - Automated Synchronization: A pre-commit/initialization hook synchronizes updates from
scripts/rules/style.mdto IDE-specific directories:.clinerules/.gemini/.kilo/.kilocode/
Sources: AGENTS.md:73-95
Build Pipeline Integration
The initialization hooks feed directly into the build pipeline defined in build.ts. This script handles the post-processing and optimization of the site after the initial generation.
Optimization Workflow
Once the site generator has finished, build.ts executes a series of "native optimization" hooks that modify the output directory in-place.
Sources: build.ts:14-36, build.ts:503-514
Key Optimization Features
- Frontmatter Generation:
scripts/frontmatter/generate_frontmatter.jsacts as an initialization hook for new documents, using AI to generate SEO-optimized titles, descriptions, and tags. - Linting Hooks:
scripts/review/review.jsprovides a hook for checking Markdown formatting against the project style guide (4-space indent, full-width punctuation, and KaTeX spacing).
Sources: scripts/frontmatter/generate_frontmatter.js:20-40, scripts/review/review.js:8-25, AGENTS.md:58-71
Summary
Project Initialization Hooks in the whk repository are essential for maintaining the high standards of a scientific knowledge base. By automating dependency checks, configuration rendering, and rule synchronization, the project ensures that both human contributors and AI agents operate within a consistent, optimized framework. These hooks reduce manual configuration errors and guarantee that the resulting static site is technically robust and SEO-optimized.