Menu

Documentation Site Generation

Relevant source files

This document describes the MkDocs-based static site generation system that transforms the LeetCode solutions repository into a bilingual documentation website deployed to GitHub Pages. The system preprocesses problem solutions, generates navigation structures, builds separate Chinese and English sites, and deploys them automatically via GitHub Actions.

For information about the data acquisition and content structure feeding into this system, see Data Acquisition System and Content Generation Pipeline. For the CI/CD workflows orchestrating the build process, see CI/CD and Deployment.


System Architecture

The documentation site generation system operates as a multi-stage pipeline that merges content from two branches, preprocesses it, builds bilingual static sites, and deploys them to GitHub Pages.

Sources: .github/workflows/deploy.yml1-154

The system consists of:

  1. Content Sources: Problem solutions from main branch, configuration from docs branch
  2. Preprocessing: Python script transforms raw content into MkDocs-compatible structure
  3. Build Stage: MkDocs generates static HTML for both languages
  4. Deployment: Compressed site uploaded to GitHub Pages

Dual-Branch Content Strategy

The documentation generation merges content from two branches to separate concerns between content and configuration:

Sources: .github/workflows/deploy.yml25-42

Branch Merge Process

The deploy.yml workflow performs the following merge operations:

StepCommandPurpose
Checkout mainactions/checkout@v4Fetch problem solutions and metadata
Checkout docsref: docs, path: mkdocs/Fetch MkDocs configuration separately
Merge contentrsync -a --remove-source-files --exclude='.git' mkdocs/ ./Copy docs branch content to workspace root
Move contest filesmv solution/CONTEST_README*.md docs*/contest.mdRelocate contest documentation

Sources: .github/workflows/deploy.yml38-42


Build Pipeline Execution

The complete build process executes in a Ubuntu environment with Python and MkDocs Material theme:

Sources: .github/workflows/deploy.yml1-124

Dependency Installation

The build requires the following dependencies:

black==24.3.0 Requests==2.32.4 mkdocs-material[imaging] pngquant (system package) 

Sources: requirements.txt1-2 .github/workflows/deploy.yml70-75

The mkdocs-material[imaging] package includes support for social cards and image optimization. The pngquant system package provides additional image compression capabilities.


Preprocessing System

The main.py script executes before MkDocs builds to transform repository content into documentation-ready format:

Sources: .github/workflows/deploy.yml82

Problem Documentation Structure

Each problem's documentation follows a standardized format that the preprocessing system relies on:

ComponentLocationDescription
FrontmatterLines 1-8YAML metadata with difficulty, tags, edit_url
Problem TitleLine 12Chinese/English problem title with number
DescriptionLines 17+Problem statement in HTML/Markdown
SolutionsMultiple sectionsSolution explanations with complexity analysis
Code TabsWithin solutionsMulti-language code snippets

Example Structure:

Sources: solution/0100-0199/0125.Valid Palindrome/README.md1-8 solution/0100-0199/0125.Valid Palindrome/README_EN.md1-8


MkDocs Configuration

The system maintains two separate MkDocs configuration files for bilingual support:

Sources: .github/workflows/deploy.yml83-84

Key Configuration Parameters

Both configuration files specify:

ParameterPurposeValue
docs_dirSource directory for Markdowndocs/ or docs-en/
site_dirOutput directory for HTMLsite/cn/ or site/en/
site_nameWebsite title"LeetCode 题解" / "LeetCode Solutions"
site_urlBase URLhttps://leetcode.doocs.org
themeMkDocs themematerial with custom config

Content Directory Structure

The documentation directories are organized to mirror the repository structure:

docs/ # Chinese documentation ├── contest.md # Contest rankings and history ├── solution/ │ ├── 0000-0099/ │ ├── 0100-0199/ │ └── ... ├── lcof/ # 剑指 Offer problems ├── lcci/ # Cracking the Coding Interview ├── lcp/ # LeetCode Cup problems └── basic/ # Basic algorithms tutorials docs-en/ # English documentation (same structure) 

Sources: .github/workflows/deploy.yml41-42


Deployment to GitHub Pages

The deployment stage uploads the built site to GitHub Pages using the actions/deploy-pages action:

Sources: .github/workflows/deploy.yml114-153

Deployment Job Configuration

The deployment job runs with specific permissions and environment settings:

Sources: .github/workflows/deploy.yml126-134

SettingValuePurpose
needsbuildWait for build job completion
pages: writePermissionWrite access to GitHub Pages
id-token: writePermissionOIDC token for deployment
environmentgithub_pagesNamed environment for tracking

CNAME File

The workflow generates a CNAME file for custom domain configuration:

Sources: .github/workflows/deploy.yml86-87

This ensures the deployed site is accessible at the custom domain leetcode.doocs.org rather than the default doocs.github.io/leetcode URL.


Caching Strategy

The build process implements multi-level caching to reduce build times:

Sources: .github/workflows/deploy.yml54-68 .github/workflows/deploy.yml89-112

Cache Types

  1. Pip Dependencies Cache

    • Path: ~/.cache/pip
    • Key: Based on requirements.txt hash
    • Speeds up Python package installation
  2. MkDocs Material Cache

    • Path: .cache
    • Key: Based on cache_id environment variable
    • Caches theme assets and plugin data
  3. Git Committers Cache

    • Path: .git-committers-cache.json
    • Storage: docs branch
    • Tracks contributor information for git-committers plugin
    • Conditionally committed back to repository

Sources: .github/workflows/deploy.yml95-112

The committer cache commit process includes safety checks:


Integration with Dynamic Assets

The documentation site incorporates dynamically generated assets produced by separate workflows:

Sources: .github/workflows/starcharts.yml1-20 images/starcharts.svg1-2 images/contributors.svg1-2

Starcharts Generation

The starcharts workflow runs on a schedule and generates a visualization of repository star growth:

ParameterValue
Schedule0 0/12 * * * (every 12 hours)
ActionMaoLongLong/actions-starcharts@main
Outputimages/starcharts.svg
Commit message"chore: auto update starcharts"
TokenDOOCS_BOT_ACTION_TOKEN

Sources: .github/workflows/starcharts.yml4-19

These SVG assets are then referenced in the documentation markdown files and included in the final static site build.


Workflow Triggers and Concurrency

The deployment workflow is triggered by specific file changes and implements concurrency control:

Trigger Conditions

Sources: .github/workflows/deploy.yml3-15

The workflow triggers when:

  • Manual workflow dispatch is requested
  • Changes are pushed to main branch affecting problem solution directories

Concurrency Control

Sources: .github/workflows/deploy.yml17-19

This ensures:

  • Only one deployment runs per branch at a time
  • New pushes cancel in-progress builds
  • Prevents conflicting deployments

Summary

The documentation site generation system transforms the repository's problem solutions into a production-ready bilingual website through a sophisticated pipeline:

  1. Content merging from main (solutions) and docs (configuration) branches
  2. Preprocessing via main.py to transform content structure
  3. Dual builds using separate MkDocs configurations for Chinese and English
  4. Artifact compression and upload to GitHub's artifact storage
  5. Automated deployment to GitHub Pages with custom domain support

The system leverages GitHub Actions for automation, MkDocs Material for theming, and implements intelligent caching to optimize build performance. Dynamic assets like star charts integrate seamlessly through scheduled workflows, and the entire pipeline is triggered automatically when problem solutions are updated.

Sources: .github/workflows/deploy.yml1-154 requirements.txt1-2