This guide explains how to build, serve, and deploy the Multi-Modal Academic Research System documentation using MkDocs with Material theme.
- Python 3.9 or higher
- pip package manager
- Git (for deployment to GitHub Pages)
# Install MkDocs and Material theme
pip install -r requirements.txt
# Or install just documentation dependencies
pip install mkdocs==1.5.3 mkdocs-material==9.5.3 mkdocs-material-extensions==1.3.1 pymdown-extensions==10.7# From project root
mkdocs serve
# Documentation will be available at http://127.0.0.1:8000The development server includes:
- Live reload - Changes automatically reflected
- Search - Full-text search functionality
- Navigation - Interactive table of contents
# Build documentation to site/ directory
mkdocs build
# Build with strict mode (fails on warnings)
mkdocs build --strict
# Clean build (remove site/ directory first)
mkdocs build --cleanEdit mkdocs.yml to customize:
theme:
name: material
palette:
- scheme: default
primary: indigo
accent: indigo
features:
- navigation.tabs
- navigation.instant
- search.suggest- Create CSS file in
docs/stylesheets/:
/* docs/stylesheets/custom.css */
.custom-class {
color: #ff0000;
}- Reference in
mkdocs.yml:
extra_css:
- stylesheets/custom.css- Create JS file in
docs/javascripts/:
// docs/javascripts/custom.js
console.log('Custom script loaded');- Reference in
mkdocs.yml:
extra_javascript:
- javascripts/custom.jsMkDocs Material supports extended Markdown syntax:
!!! note "Optional Title"
This is a note admonition.
!!! tip
This is a tip without a custom title.
!!! warning "Caution"
This is a warning.
??? question "Collapsible Question"
This admonition starts collapsed.```python
def hello_world():
print("Hello, World!")
```
```bash
# Commands with highlighting
cd /path/to/directory
ls -la
```=== "Python"
```python
print("Hello from Python")
```
=== "JavaScript"
```javascript
console.log("Hello from JavaScript");
``````mermaid
graph TD
A[Start] --> B{Decision}
B -->|Yes| C[Action 1]
B -->|No| D[Action 2]
```- [x] Completed task
- [ ] Incomplete task
- [ ] Another task:smile: :rocket: :tada:project/
βββ mkdocs.yml # Main configuration
βββ docs/ # Documentation source
β βββ index.md # Home page
β βββ setup/ # Setup guides
β βββ tutorials/ # Tutorials
β βββ api/ # API reference
β βββ stylesheets/ # Custom CSS
β βββ javascripts/ # Custom JS
β βββ assets/ # Images, files
βββ site/ # Built site (generated)
Edit navigation in mkdocs.yml:
nav:
- Home: index.md
- Getting Started:
- Installation: setup/installation.md
- Quick Start: setup/quick-start.md
- Tutorials:
- Tutorial 1: tutorials/tutorial1.md
- Tutorial 2: tutorials/tutorial2.md# Deploy to GitHub Pages
mkdocs gh-deploy
# With custom commit message
mkdocs gh-deploy -m "Update documentation"This command:
- Builds the documentation
- Pushes to
gh-pagesbranch - GitHub Pages automatically serves the site
# Build the site
mkdocs build
# Commit and push site/ directory
git add site/
git commit -m "Update docs"
git push origin gh-pagesCreate .github/workflows/docs.yml:
name: Deploy Documentation
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
pip install mkdocs-material
- name: Deploy
run: mkdocs gh-deploy --force- Connect GitHub repository to Netlify
- Configure build settings:
- Build command:
mkdocs build - Publish directory:
site
- Build command:
- Deploy
Create Dockerfile.docs:
FROM python:3.9-slim
WORKDIR /docs
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["mkdocs", "serve", "--dev-addr=0.0.0.0:8000"]Build and run:
# Build image
docker build -t docs -f Dockerfile.docs .
# Run container
docker run -p 8000:8000 docs- Create
.readthedocs.yml:
version: 2
mkdocs:
configuration: mkdocs.yml
python:
version: "3.9"
install:
- requirements: requirements.txt- Connect repository to ReadTheDocs
- Documentation builds automatically
Enabled by default in mkdocs.yml:
plugins:
- search:
separator: '[\s\-,:!=\[\]()"/]+|\.(?!\d)|&[lg]t;'
lang:
- enplugins:
- search:
separator: '[\s\-,:!=\[\]()"/]+|\.(?!\d)|&[lg]t;'
lang:
- en
- es # Multiple languages
prebuild_index: true # Faster searchAdd to mkdocs.yml:
extra:
analytics:
provider: google
property: G-XXXXXXXXXXAdd tracking code in docs/javascripts/analytics.js:
// Custom analytics tracking
window.addEventListener('load', function() {
// Your tracking code here
});theme:
palette:
# Light mode
- media: "(prefers-color-scheme: light)"
scheme: default
primary: indigo
accent: pink
toggle:
icon: material/brightness-7
name: Switch to dark mode
# Dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
primary: indigo
accent: pink
toggle:
icon: material/brightness-4
name: Switch to light modetheme:
logo: assets/logo.png
favicon: assets/favicon.pngAlready configured in mkdocs.yml:
- search - Full-text search
- minify - HTML/CSS/JS minification
- git-revision-date-localized - Show last update dates
- tags - Tag-based navigation
# Install additional plugins
pip install mkdocs-awesome-pages-plugin
pip install mkdocs-macros-plugin
pip install mkdocs-redirectsAdd to mkdocs.yml:
plugins:
- awesome-pages
- macros
- redirects:
redirect_maps:
'old-page.md': 'new-page.md'# View warnings in detail
mkdocs build --strict --verbose
# Common issues:
# - Broken links: Fix internal links
# - Missing pages: Add to nav or create file
# - Invalid YAML: Check mkdocs.yml syntax# Port already in use
mkdocs serve --dev-addr=127.0.0.1:8001
# Permission denied
sudo mkdocs serve# GitHub Pages not updating
# 1. Check gh-pages branch exists
git branch -a
# 2. Force rebuild
mkdocs gh-deploy --force
# 3. Check GitHub Pages settingsdocs/
βββ index.md # Landing page
βββ getting-started/ # Tutorial content
βββ guides/ # How-to guides
βββ reference/ # API reference
βββ explanations/ # Conceptual docs
- Use lowercase with hyphens:
my-page.md - Avoid spaces and special characters
- Keep filenames descriptive but concise
# Relative links
[Link to page](../other-page.md)
# Anchor links
[Link to section](#section-heading)
# Cross-references
[API Reference](reference/api.md#specific-function)# With caption

*Figure 1: Screenshot of the UI*
# With sizing
{ width="300" }# With title and line numbers
```python title="example.py" linenums="1"
def example():
return "Hello"
```
# With highlighting
```python hl_lines="2 3"
def example():
# This line is highlighted
# This line is highlighted
return "Hello"
```Add to .gitignore:
# MkDocs
site/
.cache/
# Python
__pycache__/
*.pyc
venv/
# Good commit messages
git commit -m "docs: Add API reference for collectors"
git commit -m "docs: Update installation guide with Docker"
git commit -m "docs: Fix broken links in tutorials"# Development
mkdocs serve # Start dev server
mkdocs serve --strict # With strict mode
mkdocs build # Build site
mkdocs build --clean # Clean build
# Deployment
mkdocs gh-deploy # Deploy to GitHub Pages
mkdocs gh-deploy --force # Force deploy
# Other
mkdocs new project-name # Create new project
mkdocs --version # Check version
mkdocs --help # Show help-
Optimize Images
- Compress images before adding
- Use appropriate formats (WebP, PNG, JPG)
- Resize to appropriate dimensions
-
Minimize Custom Code
- Keep custom CSS/JS minimal
- Use built-in features when possible
-
Enable Caching
- Use browser caching
- Enable CDN for assets
-
Lazy Loading
- Defer non-critical scripts
- Lazy load images when possible
Need Help?
- Check MkDocs Material Documentation
- Visit GitHub Discussions
- Review Examples and Tutorials