How the AI Agent Book MkDocs Site Is Built and Deployed: Complete Pipeline Guide
The AI Agent Book's MkDocs site is built via a three-stage pipeline that assembles documentation into a _web/ directory using scripts/build_site.sh, renders it with MkDocs Material configured in mkdocs.yml, and deploys automatically to GitHub Pages via .github/workflows/deploy-pages.yml on every push to the main branch.
The bojieli/ai-agent-book repository contains a multilingual technical book about AI agents. Understanding how its MkDocs site is built and deployed reveals a sophisticated static site generation process that handles multiple language editions, chapter restructuring, and automated CI/CD while maintaining clean separation between source content and generated output.
The Three-Stage Build Pipeline
The deployment process consists of distinct assembly, rendering, and deployment stages orchestrated by shell scripts and GitHub Actions.
Stage 1: Assembling the Documentation Tree
The assembly stage prepares a clean documentation directory (_web/) that MkDocs will consume. This is handled by scripts/build_site.sh, which performs several critical transformations:
- Copies core content: Root
index.md, language-specific homepages (index.*.md), androbots.txtare copied to the root of_web/. - Handles multilingual editions: Each
book-<lang>directory (including associated images) is copied to support multiple language versions. - Promotes chapter files: For the default Chinese edition, the script converts flat chapter files (
book/chapterN.md) into directory indices (book/chapterN/index.md) to support MkDocs URL schemes. This involvessed-based rewriting of relative image paths. - Includes experiment directories: Runnable notebook directories (
chapterN/) are copied verbatim to preserve executable examples. - Processes static assets: The
extras/directory (containing JavaScript/CSS for language switching, Mermaid diagrams, and MathJax) andassets/(logos and Open Graph images) are copied into the tree. - Cleans unwanted files: The script invokes
clean_site_files.pyto remove large data directories (such as law datasets), prunenode_modules, and rewrite relative links in experiment READMEs to resolve correctly under the site's sub-path.
After execution, _web/ contains a fully prepared documentation tree with all paths normalized for MkDocs consumption.
Stage 2: Rendering with MkDocs Material
Once assembled, the _web/ directory serves as the docs_dir specified in mkdocs.yml. The rendering stage applies the Material theme and executes several custom hooks:
- Theme configuration: The
mkdocs.ymlfile declares Material theme settings with SPA-style navigation (navigation.instant) and language tabbing capabilities. - Git revision date handling: The
scripts/git_revision_dates.pyhook rewires the git-revision-date-localized plugin to reference original source paths rather than the generated_web/files (which are ignored by Git). - Internationalization:
scripts/site_i18n.pygenerates a client-side translation catalog enabling the language switcher functionality. - Markdown cleanup:
scripts/mkdocs_pandoc_strip.pyremoves Pandoc-specific attributes and LaTeX syntax that Python-Markdown cannot parse. - Search optimization:
scripts/split_search_index.pysplits the large search index into per-edition JSON chunks for faster loading.
MkDocs reads the configuration, applies these pre-processing hooks, and writes the final static site to the site/ directory.
Stage 3: GitHub Pages Deployment
The deployment stage is fully automated via .github/workflows/deploy-pages.yml. The workflow triggers on pushes to main or manual dispatch:
- Environment setup: Installs Python dependencies from
requirements-docs.txtand setsNO_MKDOCS_2_WARNING=1to suppress MkDocs 2.0 banners. - Site generation: Executes
bash scripts/build_site.shto create_web/, then runsmkdocs build -d siteto render the static files. - Artifact upload: Uploads the
site/directory as a GitHub Pages artifact. - Deployment: Publishes to GitHub Pages using
actions/deploy-pages@v5, but only when the repository matches the canonical owner (bojieli/ai-agent-book).
This ensures the live site at https://bojieli.github.io/ai-agent-book always reflects the latest committed changes.
Local Development Workflow
You can replicate the MkDocs site build and deployment process locally for testing:
# Install dependencies (requires Python 3.11+)
pip install -r requirements-docs.txt
# Assemble the documentation tree
bash scripts/build_site.sh
# Build the static site
mkdocs build -d site
# Or serve locally for development
mkdocs serve
The local server exposes the site at http://127.0.0.1:8000/ with live reload enabled.
Summary
- Assembly:
scripts/build_site.shtransforms raw book sources into the_web/directory, handling chapter promotion, multilingual support, and asset normalization. - Configuration:
mkdocs.ymlorchestrates the Material theme and loads custom hooks fromscripts/for revision dates, i18n, and Markdown cleanup. - CI/CD:
.github/workflows/deploy-pages.ymlautomates the full pipeline from source commit to GitHub Pages deployment usingactions/deploy-pages@v5. - Separation: The pipeline maintains clean separation between source content (root directory) and generated artifacts (
_web/andsite/).
Frequently Asked Questions
How does the build script handle multiple languages?
The build_site.sh script copies each language edition from directories named book-<lang> into the assembled _web/ structure. It also processes index.*.md files for language-specific homepages. The scripts/site_i18n.py hook then generates a client-side translation catalog that powers the language switcher in the Material theme navigation.
Why are chapter files converted to index.md during assembly?
MkDocs expects directory-based URLs (e.g., /book/chapter1/) rather than file-based URLs (e.g., /book/chapter1.html). The assembly script promotes each chapterN.md to chapterN/index.md and uses sed to rewrite relative image paths, ensuring assets resolve correctly under the site's URL scheme while maintaining clean permalinks.
Can I deploy the site to a different hosting provider?
Yes. The mkdocs build command generates a standard static site in the site/ directory containing only HTML, CSS, and JavaScript. You can deploy this folder to any static hosting service (Netlify, Vercel, AWS S3) by modifying the final step in .github/workflows/deploy-pages.yml or by uploading the site/ directory manually after local builds.
What Python version is required for local builds?
The project requires Python 3.11 or higher as specified in the CI workflow and dependency constraints. The requirements-docs.txt file pins compatible versions of MkDocs Material (9.x) and plugins to ensure reproducible builds across local environments and GitHub Actions runners.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →