Skip to main content

AI-powered summary generation plugin for MkDocs Material

Project description

MkDocs AI Summary Plugin

PyPI version Python Support License: MIT

Transform your documentation with AI-powered summaries! This intelligent MkDocs plugin automatically generates concise, helpful summaries for your documentation pages using multiple AI services.

🌟 Why Choose This Plugin?

  • 🤖 Multiple AI Services: OpenAI, DeepSeek, Google Gemini, and GLM support with automatic fallback
  • 🚀 Smart Caching: Intelligent caching reduces API costs and speeds up builds
  • 🌍 Multi-language: Generate summaries in Chinese, English, or both
  • 🎯 Easy Setup: Get started in minutes with simple configuration
  • 🔧 CI/CD Ready: Perfect for GitHub Actions and automated deployments
  • Performance First: Minimal impact on build times

🚀 Quick Start

1. Install the Plugin

pip install mkdocs-ai-summary-wcowin

2. Basic Configuration

Add to your mkdocs.yml:

plugins:
  - ai-summary:
      ai_service: "deepseek"        # Recommended: deepseek, openai, gemini, or glm
      summary_language: "en"        # "en", "zh", or "both"
      local_enabled: true           # Enable for local development
      enabled_folders:
        - docs                    # Process files in docs folder
      exclude_patterns:
        - tags.md                # unexclude tags.md file
        - blog/posts/**
        - blog/archive/**

3. Get Your API Key

DeepSeek (Recommended - Cost Effective):

  1. Visit DeepSeek Platform
  2. Create account and get your API key
  3. Add to .env file: DEEPSEEK_API_KEY=your_key_here

Other Services: OpenAI, Gemini, or GLM - follow similar steps on their platforms.

4. Create Environment File

Create .env in your project root:

# Add your chosen AI service API key
DEEPSEEK_API_KEY=sk-your-api-key-here
# OPENAI_API_KEY=sk-your-openai-key
# GEMINI_API_KEY=your-gemini-key
# GLM_API_KEY=your-glm-key

5. Build and Enjoy!

mkdocs build    # Generate summaries
mkdocs serve    # Preview locally

🎉 That's it! Your documentation now has beautiful AI-generated summaries.

⚙️ Configuration

Page-Level Language Control

Override global language settings for specific pages:

---
title: "My Page"
ai_summary_lang: "en"  # "en", "zh", or "both"
---

# Your content here

Common Configuration Options

plugins:
  - ai-summary:
      # AI Service Settings
      ai_service: "deepseek"          # Primary AI service
      fallback_services: ["openai"]   # Backup services
      
      # Language & Content
      summary_language: "en"           # Global language setting
      summary_length: "medium"         # short/medium/long
      
      # File Selection
      enabled_folders:
        - docs
      exclude_patterns:
        - tags.md                # unexclude tags.md file
        - blog/posts/**
        - blog/archive/**
      
      # Performance
      cache_enabled: true              # Smart caching
      local_enabled: true              # Enable locally
      ci_enabled: true                 # Enable in CI/CD

🚀 GitHub Pages Deployment

1. Add API Key to GitHub Secrets

  1. Go to your repository → SettingsSecrets and variablesActions
  2. Click "New repository secret"
  3. Add your API key (e.g., DEEPSEEK_API_KEY)

2. Configure GitHub Actions Workflow

Option A: Create New Workflow

Create .github/workflows/ci.yml:

name: ci
on:
  push:
    branches: [main, master]
  pull_request:
    types: [closed]
    branches: [main, master]

permissions:
  contents: write

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          sparse-checkout: |
            docs
            includes
            requirements.txt
            .ai_cache
      
      - uses: actions/setup-python@v4
        with:
          python-version: 3.x
      
      - name: Set cache ID
        run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
      
      - uses: actions/cache@v3
        with:
          key: mkdocs-material-${{ github.run_number }}
          path: .cache
          restore-keys: |
            mkdocs-material-
      
      # Install your existing dependencies
      - run: pip install mkdocs-material
      - run: pip install mkdocs-ai-summary-wcowin
      
      # Deploy with AI Summary
      - name: Deploy with AI Summary
        env:
          AI_SUMMARY_CI_ENABLED: 'true'
          AI_SUMMARY_CACHE_ENABLED: 'true'
          AI_SUMMARY_CACHE_EXPIRE_DAYS: '300'
          DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}
        run: mkdocs gh-deploy --force
      
      # Auto-commit AI cache files
      - name: Auto-commit AI cache
        run: |
          if [ -d ".ai_cache" ] && [ "$(ls -A .ai_cache 2>/dev/null)" ]; then
            git config --local user.email "action@github.com"
            git config --local user.name "GitHub Action"
            git add .ai_cache/
            if ! git diff --cached --quiet; then
              git commit -m "🤖 Auto-update AI summary cache [skip ci]"
              git push
            fi
          fi

Option B: Add to Existing Workflow

If you already have a ci.yml file, add these steps to your existing workflow:

# Add to your existing dependencies installation
- run: pip install mkdocs-ai-summary-wcowin

# Replace your mkdocs build/deploy step with:
- name: Deploy with AI Summary
  env:
    AI_SUMMARY_CI_ENABLED: 'true'
    AI_SUMMARY_CACHE_ENABLED: 'true'
    DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}
  run: mkdocs gh-deploy --force

# Add after deploy (optional - for cache management)
- name: Auto-commit AI cache
  run: |
    if [ -d ".ai_cache" ] && [ "$(ls -A .ai_cache 2>/dev/null)" ]; then
      git config --local user.email "action@github.com"
      git config --local user.name "GitHub Action"
      git add .ai_cache/
      if ! git diff --cached --quiet; then
        git commit -m "🤖 Auto-update AI summary cache [skip ci]"
        git push
      fi
    fi

3. Integration Steps for Existing Workflows

If you already have a working ci.yml file, follow these steps to add AI summary functionality:

Step 1: Add Plugin Installation

Add this line to your existing dependency installation section:

- run: pip install mkdocs-ai-summary-wcowin

Step 2: Add API Key to Environment

Update your mkdocs build/deploy step to include the API key:

- name: Deploy docs
  env:
    DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}  # Add this line
  run: mkdocs gh-deploy --force

Step 3: Configure AI Summary Settings (Optional)

For better CI performance, add these environment variables:

env:
  AI_SUMMARY_CI_ENABLED: 'true'        # Enable in CI
  AI_SUMMARY_CACHE_ENABLED: 'true'     # Use caching
  AI_SUMMARY_CACHE_EXPIRE_DAYS: '300'  # Cache for 300 days
  DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}

Step 4: Add Cache Management (Optional)

To automatically commit generated cache files, add this step after deployment:

- name: Auto-commit AI cache
  run: |
    if [ -d ".ai_cache" ] && [ "$(ls -A .ai_cache 2>/dev/null)" ]; then
      git config --local user.email "action@github.com"
      git config --local user.name "GitHub Action"
      git add .ai_cache/
      if ! git diff --cached --quiet; then
        git commit -m "🤖 Auto-update AI summary cache [skip ci]"
        git push
      fi
    fi

4. Enable GitHub Pages

  1. Repository SettingsPages
  2. Source: "Deploy from a branch"
  3. Branch: "gh-pages"
  4. Save

🎉 Done! Push to main branch to deploy automatically.

💡 Tips & Troubleshooting

Smart Caching

  • Summaries are cached automatically to save API costs
  • Cache updates when content changes
  • Clear cache: add clear_cache: true to config

Multiple AI Services

  • DeepSeek: Most cost-effective, great quality
  • OpenAI: Premium option, excellent results
  • Gemini: Good balance of cost and quality
  • GLM: Great for Chinese content

Common Issues

Plugin not generating summaries?

  • Check API key in .env file
  • Verify local_enabled: true in config
  • Ensure files are in enabled_folders

Build failing in CI?

  • Add API key to GitHub Secrets
  • Check workflow file syntax
  • Verify plugin installation step

🤝 Support & Contributing

📄 License

MIT License - feel free to use in your projects!


Made with ❤️ for the MkDocs community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mkdocs_ai_summary_wcowin-1.2.0.tar.gz (25.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mkdocs_ai_summary_wcowin-1.2.0-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs_ai_summary_wcowin-1.2.0.tar.gz.

File metadata

File hashes

Hashes for mkdocs_ai_summary_wcowin-1.2.0.tar.gz
Algorithm Hash digest
SHA256 d649aae5cb5b03e07dcfdbe7fb4a70ba5977cacdc83e1f1eed96ccbf21256104
MD5 7227a1aecd7c0a303895a7e38ce2bb0c
BLAKE2b-256 ea46cc34f773e7e3c4371ce8419033be0c352b6fe2d50371308b255ffc2d2b41

See more details on using hashes here.

File details

Details for the file mkdocs_ai_summary_wcowin-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mkdocs_ai_summary_wcowin-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 59ca53c7d03bb3b5612354ef2f560642c044c856900ac2afa6bb3ad675c7957d
MD5 67ef5f64a71329687c2433a42318a51f
BLAKE2b-256 0604fd1c2534b2c7c1a2e9cf9f55333555492923b437086e8c3c02046bd1ce62

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page