Manual
Almnck.
Price: 50ⓐ

Manual Publishing Implementation Plan

For Claude: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.

Goal: Implement the almnck.manual Django app to publish doc/ at /manual/.

Architecture: Standalone Django app that scans doc/ at request time, builds navigation tree from directory structure, renders markdown with left-side navigation.

Tech Stack: Django, django-distill, markdown, existing Almanack CSS


Task 1: Create Django App Structure

Files: - Create: src/almnck/manual/__init__.py - Create: src/almnck/manual/apps.py - Modify: src/almnck/settings.py

Step 1: Create app directory and files

mkdir -p src/almnck/manual
touch src/almnck/manual/__init__.py

Step 2: Create apps.py

from django.apps import AppConfig

class ManualConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'almnck.manual'
    verbose_name = 'Manual'

Step 3: Add to INSTALLED_APPS in settings.py

Add 'almnck.manual', to INSTALLED_APPS.

Step 4: Commit

git add src/almnck/manual/ src/almnck/settings.py
git commit -m "Create almnck.manual Django app"

Task 2: Create Doc Scanner

Files: - Create: src/almnck/manual/scanner.py

Step 1: Write the scanner

"""Scan doc/ directory and build navigation tree."""
import re
from pathlib import Path
from django.conf import settings
import yaml


def get_doc_root():
    """Return the doc/ directory path."""
    return Path(settings.ALMANACK_ROOT) / 'doc'


def parse_frontmatter(content):
    """Extract YAML frontmatter and body from markdown content."""
    if not content.startswith('---'):
        return {}, content

    parts = content.split('---', 2)
    if len(parts) < 3:
        return {}, content

    try:
        frontmatter = yaml.safe_load(parts[1]) or {}
    except yaml.YAMLError:
        frontmatter = {}

    return frontmatter, parts[2].strip()


def extract_title(content, frontmatter, filename):
    """Extract title from frontmatter, first heading, or filename."""
    if frontmatter.get('title'):
        return frontmatter['title']

    for line in content.split('\n'):
        if line.startswith('# '):
            return line[2:].strip()

    # Strip numeric prefix and extension
    name = re.sub(r'^\d+-', '', filename)
    name = name.replace('.md', '').replace('-', ' ')
    return name.title()


def get_sort_key(path):
    """Get sort key for a path (numeric prefix or alphabetical)."""
    name = path.name
    match = re.match(r'^(\d+)-', name)
    if match:
        return (0, int(match.group(1)), name)
    return (1, 0, name)


def path_to_url(rel_path):
    """Convert a relative doc path to a URL path."""
    # Remove .md extension
    url_path = str(rel_path).replace('.md', '')
    # Strip numeric prefixes from each segment
    parts = url_path.split('/')
    parts = [re.sub(r'^\d+-', '', p) for p in parts]
    url_path = '/'.join(parts)
    # Handle index files
    if url_path.endswith('/index'):
        url_path = url_path[:-6]
    elif url_path == 'index':
        url_path = ''
    return f'/manual/{url_path}/' if url_path else '/manual/'


def scan_docs():
    """Scan doc/ directory and return list of doc entries."""
    doc_root = get_doc_root()
    docs = []

    for md_file in doc_root.rglob('*.md'):
        rel_path = md_file.relative_to(doc_root)
        content = md_file.read_text()
        frontmatter, body = parse_frontmatter(content)

        # Skip private docs
        if frontmatter.get('visibility') == 'private':
            continue

        title = extract_title(body, frontmatter, md_file.name)
        url = path_to_url(rel_path)

        # Determine section from path
        parts = list(rel_path.parts)
        if len(parts) == 1:
            section = ''
        else:
            section = parts[0]

        docs.append({
            'path': md_file,
            'rel_path': rel_path,
            'url': url,
            'title': title,
            'section': section,
            'frontmatter': frontmatter,
            'body': body,
            'is_index': md_file.name == 'index.md',
            'sort_key': get_sort_key(md_file),
        })

    return sorted(docs, key=lambda d: (d['section'], d['sort_key']))


def build_nav_tree(docs, current_url=None):
    """Build navigation tree structure for sidebar."""
    sections = {}

    for doc in docs:
        section = doc['section'] or '_root'

        if section not in sections:
            # Find section index
            section_title = section.replace('-', ' ').title() if section != '_root' else 'Overview'
            section_url = f'/manual/{section}/' if section != '_root' else '/manual/'
            sections[section] = {
                'title': section_title,
                'url': section_url,
                'active': False,
                'children': [],
            }

        if doc['is_index']:
            sections[section]['title'] = doc['title']
            sections[section]['url'] = doc['url']
            sections[section]['active'] = doc['url'] == current_url
        else:
            sections[section]['children'].append({
                'title': doc['title'],
                'url': doc['url'],
                'active': doc['url'] == current_url,
            })

        # Mark section as active if any child is active
        if doc['url'] == current_url:
            sections[section]['active'] = True

    return list(sections.values())


def get_section_children(docs, section_url):
    """Get child docs for a section index page."""
    children = []
    for doc in docs:
        if doc['url'].startswith(section_url) and doc['url'] != section_url:
            # Only direct children, not nested
            remaining = doc['url'][len(section_url):].strip('/')
            if '/' not in remaining:
                children.append(doc)
    return children


def render_nav_placeholder(body, children):
    """Replace  with child listing."""
    if '' not in body:
        return body

    if not children:
        return body.replace('', '')

    nav_html = '<ul class="nav-children">\n'
    for child in children:
        desc = child['frontmatter'].get('description', '')
        if desc:
            nav_html += f'<li><a href="{child["url"]}">{child["title"]}</a> - {desc}</li>\n'
        else:
            nav_html += f'<li><a href="{child["url"]}">{child["title"]}</a></li>\n'
    nav_html += '</ul>'

    return body.replace('', nav_html)

Step 2: Commit

git add src/almnck/manual/scanner.py
git commit -m "Add doc scanner for navigation tree"

Task 3: Create Views

Files: - Create: src/almnck/manual/views.py

Step 1: Write the views

"""Views for the manual."""
from django.shortcuts import render
from django.http import Http404

from .scanner import (
    scan_docs, build_nav_tree, get_section_children, render_nav_placeholder
)


def doc_page(request, path=''):
    """Render a documentation page."""
    docs = scan_docs()

    # Build the target URL
    if path:
        target_url = f'/manual/{path.strip("/")}/'
    else:
        target_url = '/manual/'

    # Find the matching doc
    doc = None
    for d in docs:
        if d['url'] == target_url:
            doc = d
            break

    if not doc:
        raise Http404(f"Doc not found: {target_url}")

    # Build navigation
    nav_sections = build_nav_tree(docs, target_url)

    # Get children for index pages
    children = []
    if doc['is_index']:
        children = get_section_children(docs, target_url)

    # Render nav placeholder
    body = render_nav_placeholder(doc['body'], children)

    return render(request, 'manual/doc.html', {
        'doc': doc,
        'body': body,
        'nav_sections': nav_sections,
    })

Step 2: Commit

git add src/almnck/manual/views.py
git commit -m "Add manual views"

Task 4: Create Templates

Files: - Create: src/almnck/templates/manual/doc.html - Modify: assets/css/almanack.css

Step 1: Create doc template

{% extends "base.html" %}
{% load markdownify %}

{% block meta_left %}Manual{% endblock %}

{% block content %}
<div class="manual-layout">
    <nav class="manual-nav">
        <h3><a href="/manual/">Manual</a></h3>
        <ul>
        {% for section in nav_sections %}
            <li class="nav-section{% if section.active %} active{% endif %}">
                <a href="{{ section.url }}">{{ section.title }}</a>
                {% if section.children %}
                <ul>
                {% for child in section.children %}
                    <li{% if child.active %} class="active"{% endif %}>
                        <a href="{{ child.url }}">{{ child.title }}</a>
                    </li>
                {% endfor %}
                </ul>
                {% endif %}
            </li>
        {% endfor %}
        </ul>
    </nav>
    <article class="manual-content">
        <h1>{{ doc.title }}</h1>
        {{ body|markdownify }}
    </article>
</div>
{% endblock %}

Step 2: Add CSS for manual layout

Add to assets/css/almanack.css:

/* Manual layout */
.manual-layout {
    display: flex;
    gap: 2em;
    max-width: 60em;
    margin: 0 auto;
    padding: 2em 1em;
}

.manual-nav {
    width: 200px;
    flex-shrink: 0;
    position: sticky;
    top: 2em;
    align-self: flex-start;
    font-family: "Cormorant Garamond", Georgia, serif;
}

.manual-nav h3 {
    font-family: "Fell English", serif;
    font-size: 1.2rem;
    margin-bottom: 0.5em;
    border-bottom: 1px solid #1a1a1a;
    padding-bottom: 0.3em;
}

.manual-nav h3 a {
    text-decoration: none;
    color: inherit;
}

.manual-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.manual-nav li {
    margin: 0.3em 0;
}

.manual-nav a {
    text-decoration: none;
    color: #1a1a1a;
}

.manual-nav a:hover {
    text-decoration: underline;
}

.manual-nav li.active > a {
    font-weight: 600;
}

.manual-nav ul ul {
    padding-left: 1em;
    font-size: 0.9em;
}

.manual-content {
    flex: 1;
    min-width: 0;
}

.manual-content h1 {
    font-family: "Fell English", serif;
    font-size: 2rem;
    margin-top: 0;
}

.manual-content h2 {
    font-family: "Fell English", serif;
    font-size: 1.4rem;
    margin-top: 1.5em;
}

.manual-content pre {
    background: #f5f5f5;
    padding: 1em;
    overflow-x: auto;
    font-size: 0.9em;
}

.manual-content code {
    font-family: monospace;
}

.manual-content p code {
    background: #f5f5f5;
    padding: 0.1em 0.3em;
}

.nav-children {
    list-style: none;
    padding: 0;
    margin: 1em 0;
}

.nav-children li {
    margin: 0.5em 0;
}

@media (max-width: 768px) {
    .manual-layout {
        flex-direction: column;
    }

    .manual-nav {
        width: 100%;
        position: static;
        border-bottom: 1px solid #1a1a1a;
        padding-bottom: 1em;
        margin-bottom: 1em;
    }
}

Step 3: Commit

git add src/almnck/templates/manual/doc.html assets/css/almanack.css
git commit -m "Add manual template and CSS"

Task 5: Create URL Patterns

Files: - Create: src/almnck/manual/urls.py - Modify: src/almnck/urls.py

Step 1: Create manual URLs with distill

"""URL patterns for the manual."""
from django_distill import distill_path
from . import views
from .scanner import scan_docs


def get_all_doc_paths():
    """Generate all doc paths for distill."""
    docs = scan_docs()
    for doc in docs:
        path = doc['url'].strip('/').replace('docs/', '', 1)
        if path:
            yield {'path': path + '/'}
        else:
            yield {'path': ''}


urlpatterns = [
    distill_path(
        'docs/',
        views.doc_page,
        name='manual_index',
    ),
    distill_path(
        'docs/<path:path>',
        views.doc_page,
        name='manual_page',
        distill_func=get_all_doc_paths,
    ),
]

Step 2: Include in main urls.py

Add to src/almnck/urls.py:

from django.urls import include

urlpatterns = [
    # ... existing patterns ...
    path('', include('almnck.manual.urls')),
]

Step 3: Commit

git add src/almnck/manual/urls.py src/almnck/urls.py
git commit -m "Add manual URL patterns for distill"

Task 6: Build and Test

Step 1: Sync and build

make sync-django && make build-django-site

Step 2: Verify output

ls -la web/manual/

Expected: HTML files for all documentation.

Step 3: Test locally

make serve

Navigate to: http://localhost:8000/manual/

Expected: Documentation index with left navigation.

Step 4: Fix any issues and commit

git add -A
git commit -m "Fix issues from manual testing"

Summary

Task Description
1 Create Django app structure
2 Create doc scanner for navigation
3 Create views
4 Create templates and CSS
5 Create URL patterns
6 Build and test

Addendum (2026-01-17): Makefile commands were reorganized. sync-django → sync, build-django-site → build.