A tool and plugin to generate static HTML/CSS documentation for Swift packages that works without JavaScript.
swift-docc-static generates pure HTML/CSS documentation from Swift packages
using the DocC infrastructure.
The output can be viewed locally as file:// URLs or hosted on any static web server
without requiring JavaScript for core functionality.
- Pure HTML/CSS output - Documentation works without JavaScript enabled
- Full DocC support - API documentation, articles, and tutorials
- Light/Dark mode - Automatic theme switching based on system preferences
- Interactive tutorials - Display step-by-step tutorials with code examples and quizzes
- Cross-package linking - Relative links work with
file://URLs for testing - Multi-target support - Document all targets in a package and create a common index page
- Optional search - Client-side search using Lunr.js (requires JavaScript)
- SPM plugin - Integrate documentation generation into your build process
- Swift 6.2+
The easiest way to install on macOS or Linux:
brew tap mipalgu/tap
brew install swift-docc-staticgit clone https://github.com/mipalgu/swift-docc-static.git
cd swift-docc-static
swift build -c releaseThe executable will be at .build/release/docc-static.
The package provides a generate-static-documentation package command plugin
that you can use directly in your own packages by simply adding the following
to your Package.swift:
dependencies: [
.package(url: "https://github.com/mipalgu/swift-docc-static.git", branch: "main"),
]Generate documentation for a Swift package using the command-line tool:
docc-static generate --package-path /path/to/package --output ./docs| Option | Description |
|---|---|
-p, --package-path. |
Path to the package directory (default: .). |
-o, --output |
Output directory (default: .build/documentation) |
--scratch-path |
Scratch path for Swift build operations |
--symbol-graph-dir |
Pre-generated symbol graph directory (skips build). |
-t, --target |
Specific targets to document (can be repeated) |
-I, --include-all-dependencies |
Include documentation for all dependencies |
-i, --include-dependency |
Include a specific dependency (can be repeated) |
-x, --exclude-dependency |
Exclude a specific dependency (can be repeated) |
-e, --external-docs |
External documentation URL (format: PackageName=URL) |
--disable-search |
Disable client-side search (enabled by default) |
--footer |
Custom HTML for the page footer |
-v, --verbose |
Enable verbose output |
Generate documentation with verbose output:
docc-static generate -p ./MyPackage -o ./docs -vGenerate documentation for specific targets:
docc-static generate -t MyLibrary -t MyOtherLibrary -o ./docsInclude all dependencies except specific ones:
docc-static generate -I -x ExcludedPackage -o ./docsLink to external documentation:
docc-static generate -e Foundation=https://developer.apple.com/documentation/foundation -o ./docsRender static HTML from an existing .doccarchive:
docc-static render /path/to/MyPackage.doccarchive --output ./docsStart a local preview server:
docc-static preview --output ./docs --port 8080Then open http://localhost:8080 in your browser.
Use the Swift Package Manager plugin to generate documentation:
swift package generate-static-documentationOr with options:
swift package --scratch-path /tmp/build generate-static-documentationYou can automatically deploy documentation to GitHub Pages using GitHub Actions.
Add the following workflow to .github/workflows/documentation.yml:
name: Documentation
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: true
jobs:
build:
runs-on: macos-15
steps:
- uses: actions/checkout@v4
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "26.1.1"
- name: Build docc-static
run: swift build -c release --product docc-static
- name: Generate documentation
run: |
.build/release/docc-static generate \
--package-path . \
--output .build/documentation
- uses: actions/configure-pages@v5
- uses: actions/upload-pages-artifact@v3
with:
path: .build/documentation
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- id: deployment
uses: actions/deploy-pages@v4Then configure GitHub Pages in your repository settings:
- Go to Settings → Pages
- Under Build and deployment, select Source: GitHub Actions
Your documentation will be deployed to https://<username>.github.io/<repository>/.
docs/
├── index.html # Main landing page
├── css/
│ └── main.css # Stylesheet
├── js/ # Optional JavaScript (search)
├── images/ # Image assets
├── downloads/ # Downloadable files
├── videos/ # Video assets
├── documentation/
│ └── mypackage/
│ ├── index.html # Module overview
│ └── mytype/
│ └── index.html # Type documentation
└── tutorials/
├── tutorials/
│ └── index.html # Tutorials overview
└── mypackage/
└── my-tutorial/
└── index.html # Tutorial page
Add custom HTML to the page footer:
docc-static generate --footer '<a href="https://example.com">My Company</a>'The generated CSS uses CSS custom properties for theming. Override these in your own stylesheet to customise colours:
:root {
--docc-bg: #ffffff;
--docc-fg: #1d1d1f;
--docc-accent: #0066cc;
/* ... */
}
@media (prefers-color-scheme: dark) {
:root {
--docc-bg: #1d1d1f;
--docc-fg: #f5f5f7;
/* ... */
}
}swift-docc-static leverages the existing DocC infrastructure:
- Uses
SwiftDocCfor symbol graph processing and content parsing - Implements
ConvertOutputConsumerto generate static HTML - Renders
RenderNodestructures to pure HTML/CSS pages - Supports all DocC content types: symbols, articles, and tutorials
| Component | Description |
|---|---|
StaticDocumentationGenerator |
Main orchestrator for documentation generation |
StaticHTMLConsumer |
Implements ConvertOutputConsumer protocol |
HTMLPageBuilder |
Builds HTML pages from RenderNode data |
IndexPageBuilder |
Creates the combined index page |
SearchIndexBuilder |
Generates Lunr.js search index |
Contributions are welcome! Please feel free to submit issues and pull requests.
This project is available under the Apache License 2.0. See the LICENCE file for details.
- Swift DocC - Documentation compiler
- Swift DocC Plugin - Package documentation plugin
- Swift Argument Parser - CLI argument parsing
- Lunr.js - Client-side search (optional, requires JavaScript enabled in the browser)