contextual docs
Project description
ctxssg
A pandoc-based static site generator designed for technical documentation and content that requires structured output in multiple formats.
Features
Core Capabilities
- Multi-format Output: Generate HTML, XML, JSON, and plain text from single source files
- Pandoc Integration: Leverage pandoc's powerful document conversion with syntax highlighting
- Template-driven Architecture: Jinja2-based templating with customizable output formats
- TOML Configuration: Modern configuration with format-specific options
- Live Development Server: Hot-reload development environment with file watching
Installation
Prerequisites
- Python 3.10+
- Pandoc (required for document conversion)
Install
uv tool install ctxssg
via Pip
pip install ctxssg
Verify Installation
ctxssg doctor # Check system dependencies and configuration
Quick Start
1. Initialize Site
ctxssg init my-docs --title "Technical Documentation"
cd my-docs
2. Configure Output Formats
Edit config.toml to enable multiple formats:
[build]
output_formats = ["html", "xml", "json", "plain"]
[formats.json]
pretty_print = true
include_metadata = true
[formats.xml]
include_namespaces = false
3. Create Content
ctxssg new "API Reference" --type page
ctxssg new "Getting Started" --type post
4. Build and Serve
ctxssg build # Generate all configured formats
ctxssg serve # Development server with hot-reload
Architecture
Project Structure
my-docs/
├── config.toml # TOML configuration
├── content/ # Source content
│ ├── posts/ # Blog posts/articles
│ │ └── *.md
│ └── *.md # Static pages
├── templates/ # Jinja2 templates
│ ├── base.html # Base HTML template
│ ├── default.html # Default page template
│ ├── index.html # Homepage template
│ ├── post.html # Post template
│ └── formats/ # Output format templates
│ ├── document.xml.j2 # XML output template
│ ├── document.json.j2# JSON output template
│ └── document.txt.j2 # Plain text template
├── static/ # Static assets
│ ├── css/
│ └── js/
└── _site/ # Generated output
├── *.html # HTML files
├── *.xml # XML files
├── *.json # JSON files
└── *.txt # Plain text files
Content Format
Content files use Markdown with YAML frontmatter:
---
title: API Authentication
date: 2024-01-15
layout: default
tags: [api, auth, security]
---
# Authentication
API authentication is handled via...
## OAuth 2.0 Flow
1. Obtain authorization code
2. Exchange for access token
3. Include token in requests
Configuration
Basic Configuration (config.toml)
[site]
title = "Technical Documentation"
url = "https://docs.example.com"
description = "Comprehensive API and development documentation"
author = "Development Team"
[build]
output_dir = "_site"
output_formats = ["html", "xml", "json", "plain"]
[formats.json]
pretty_print = true
include_metadata = true
[formats.xml]
include_namespaces = false
[formats.plain]
include_metadata = true
wrap_width = 80
Template Customization
Override default templates by creating files in your templates/ directory. Templates use Jinja2 syntax with access to:
site- Site configurationpage- Current page datacontent- Structured content data (for format templates)metadata- Page metadata
Format Templates
Create custom output formats by modifying templates in templates/formats/:
document.xml.j2- XML output structuredocument.json.j2- JSON API response formatdocument.txt.j2- Plain text documentation
CLI Commands
Site Management
ctxssg init [path] --title "Site Title" # Initialize new site
ctxssg build # Build all configured formats
ctxssg serve --port 8000 --watch # Development server
ctxssg doctor # System diagnostics
Content Creation
ctxssg new "Page Title" --type page # Create new page
ctxssg new "Post Title" --type post # Create new post
ctxssg convert input.md --format xml # Convert single file
Development Commands
ctxssg serve --watch # Hot-reload development
ctxssg build --watch # Continuous building
Output Formats
HTML
Standard web output with responsive design, syntax highlighting, and navigation.
XML
Structured XML output suitable for API consumption:
<document>
<metadata>
<title>API Reference</title>
<date>2024-01-15</date>
</metadata>
<content>
<section id="authentication" level="1">
<title>Authentication</title>
<content>...</content>
</section>
</content>
</document>
JSON
API-friendly JSON structure:
{
"metadata": {
"title": "API Reference",
"date": "2024-01-15"
},
"content": {
"sections": [
{
"id": "authentication",
"level": 1,
"title": "Authentication",
"content": [...]
}
]
}
}
Plain Text
Clean text output for documentation systems and CLIs.
Advanced Usage
Custom Templates
Create format-specific templates for specialized output:
{# templates/formats/api-spec.json.j2 #}
{
"apiVersion": "v1",
"kind": "Documentation",
"metadata": {{ metadata | tojson }},
"spec": {
"sections": [
{% for section in content.sections %}
{
"name": "{{ section.title }}",
"content": "{{ section.content | join(' ') }}"
}{% if not loop.last %},{% endif %}
{% endfor %}
]
}
}
Batch Processing
Process multiple files programmatically:
from ctxssg.generator import Site
from pathlib import Path
site = Site(Path("my-docs"))
site.build() # Generate all formats
Development
Setup Development Environment
git clone https://github.com/kgruel/ctxssg.git
cd ctxssg
python -m venv venv
source venv/bin/activate # or `venv\Scripts\activate` on Windows
pip install -e '.[dev]'
Run Tests
python -m pytest # Run test suite
ruff check . # Lint code
ruff format . # Format code
Project Architecture
ctxssg/generator.py- Core site generation logicctxssg/cli.py- Command-line interfacectxssg/templates/- Package template resourcesctxssg/assets/- Default CSS and static assets
Requirements
System Dependencies
- Pandoc: Document conversion engine
- Python 3.10+: Modern Python with typing support
Python Dependencies
click- CLI frameworkjinja2- Template enginepypandoc- Pandoc integrationpyyaml- YAML configuration supporttomli- TOML configuration supportpython-frontmatter- Frontmatter parsingbeautifulsoup4- HTML parsingwatchdog- File system monitoring
License
Apache-2.0
Contributing
Contributions are welcome! Please read the contributing guidelines and submit pull requests for any enhancements.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ctxssg-0.0.2.tar.gz.
File metadata
- Download URL: ctxssg-0.0.2.tar.gz
- Upload date:
- Size: 31.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c532ae4d0df8dbb8e18a53347b95623d7ec8957cec883da602354a3c12e6893e
|
|
| MD5 |
7fb6fd2cfcd18cb6659f4d0fdba9b465
|
|
| BLAKE2b-256 |
6eee9ce1b68688d55c2a25bf589336fd5d7b2bb5459aacd2a4ef7dc3707d257d
|
Provenance
The following attestation bundles were made for ctxssg-0.0.2.tar.gz:
Publisher:
publish.yml on kgruel/ctxssg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ctxssg-0.0.2.tar.gz -
Subject digest:
c532ae4d0df8dbb8e18a53347b95623d7ec8957cec883da602354a3c12e6893e - Sigstore transparency entry: 233501856
- Sigstore integration time:
-
Permalink:
kgruel/ctxssg@3dc25d9808deca168ccad948532e874c04c120a9 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/kgruel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3dc25d9808deca168ccad948532e874c04c120a9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ctxssg-0.0.2-py3-none-any.whl.
File metadata
- Download URL: ctxssg-0.0.2-py3-none-any.whl
- Upload date:
- Size: 21.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5292485f591a835537ec02e907c89c12bfec1ddb83b9835fe7a0085c91c78098
|
|
| MD5 |
16d5b7fbfd15137397d622ccf9d75b38
|
|
| BLAKE2b-256 |
9c02a938021b013b0192c96a0582ecc7075b2436d8a85f830197e71110d4959c
|
Provenance
The following attestation bundles were made for ctxssg-0.0.2-py3-none-any.whl:
Publisher:
publish.yml on kgruel/ctxssg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ctxssg-0.0.2-py3-none-any.whl -
Subject digest:
5292485f591a835537ec02e907c89c12bfec1ddb83b9835fe7a0085c91c78098 - Sigstore transparency entry: 233501858
- Sigstore integration time:
-
Permalink:
kgruel/ctxssg@3dc25d9808deca168ccad948532e874c04c120a9 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/kgruel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3dc25d9808deca168ccad948532e874c04c120a9 -
Trigger Event:
release
-
Statement type: