Skip to main content

contextual docs

Project description

ctxssg

PyPI Changelog Tests License

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 configuration
  • page - Current page data
  • content - 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 structure
  • document.json.j2 - JSON API response format
  • document.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 logic
  • ctxssg/cli.py - Command-line interface
  • ctxssg/templates/ - Package template resources
  • ctxssg/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 framework
  • jinja2 - Template engine
  • pypandoc - Pandoc integration
  • pyyaml - YAML configuration support
  • tomli - TOML configuration support
  • python-frontmatter - Frontmatter parsing
  • beautifulsoup4 - HTML parsing
  • watchdog - 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


Download files

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

Source Distribution

ctxssg-0.0.2.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

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

ctxssg-0.0.2-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

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

Hashes for ctxssg-0.0.2.tar.gz
Algorithm Hash digest
SHA256 c532ae4d0df8dbb8e18a53347b95623d7ec8957cec883da602354a3c12e6893e
MD5 7fb6fd2cfcd18cb6659f4d0fdba9b465
BLAKE2b-256 6eee9ce1b68688d55c2a25bf589336fd5d7b2bb5459aacd2a4ef7dc3707d257d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ctxssg-0.0.2.tar.gz:

Publisher: publish.yml on kgruel/ctxssg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for ctxssg-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5292485f591a835537ec02e907c89c12bfec1ddb83b9835fe7a0085c91c78098
MD5 16d5b7fbfd15137397d622ccf9d75b38
BLAKE2b-256 9c02a938021b013b0192c96a0582ecc7075b2436d8a85f830197e71110d4959c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ctxssg-0.0.2-py3-none-any.whl:

Publisher: publish.yml on kgruel/ctxssg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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