ficgen
A static site generator for personal fiction archives. Reads Markdown story documents and KDL metadata (kdl-py) from a stories/ directory and outputs clean, literary static HTML, CSS (with light/dark mode), static taxonomy browse pages, and an Atom 1.0 feed.
Installation
Requires Python 3.12+.
pip install ficgen
Or install globally as a CLI tool with pipx:
pipx install ficgen
For local development inside a virtual environment:
pip install -r requirements-dev.txt
1. The ficgen Command
ficgen (also runnable as python -m ficgen) has four subcommands: build (the default when no subcommand is given), new (alias init), import, and stamp.
Building the Archive (ficgen / ficgen build)
ficgen # build published stories from ./stories into .
ficgen build # explicit equivalent
ficgen --drafts # include published false stories and chapters
ficgen --stories path/to/stories --output path/to/out
Build Options
| Flag | Default | Description |
|---|---|---|
--stories PATH |
./stories (or ../stories) |
Source directory containing story subdirectories. |
--output PATH |
. (or ..) |
Output directory for generated HTML, CSS, and feed. |
--config PATH |
<stories>/../site.kdl if present |
Optional KDL site configuration file. |
--title TEXT |
"Fiction Archive" |
Archive title (overrides site.kdl). |
--subtitle TEXT |
"" |
Subtitle shown on the archive index page. |
--author TEXT |
"" |
Default author name for stories and Atom feed entries. |
--base-url URL |
"https://example.com/" |
Canonical base URL used for Atom <id> and <link> elements. |
--drafts |
false |
Include stories and chapters marked published false, with [Draft] badges. |
Site Configuration (site.kdl)
If site.kdl exists next to stories/, ficgen loads it automatically. CLI flags override values in site.kdl.
title "My Fiction Archive"
subtitle "Original fiction and fanworks."
author "Alex Rivera"
base-url "https://example.com/fic/"
// include-drafts false
Generated Output
output/
├── index.html # Main Table of Contents listing all stories
├── style.css # Shared stylesheet (light/dark mode)
├── feed.xml # Atom 1.0 feed of published stories & chapters
├── browse/
│ ├── index.html # Hub listing all fandoms, categories, ships, characters, tags
│ └── <kind>/<slug>.html # Static filtered listing for each taxonomy value
├── <single-doc-slug>/
│ └── index.html # Complete one-shot reading page
└── <multi-chapter-slug>/
├── index.html # Story overview, metadata, and chapter list
├── ch1.html, ch2.html, ... # Individual chapter pages with prev/next/picker nav
└── all.html # "Entire Work" combined view
Rebuilding cleans stale .html files inside known story folders and regenerates browse/ from scratch, while leaving stories/ and non-HTML files untouched. If any published story or chapter is missing an explicit date metadata node, ficgen logs a WARNING to stderr via Python's logging module suggesting ficgen stamp.
Initializing a New Story (ficgen new / ficgen init)
Creates a new story folder under stories/<slug>/ with valid KDL metadata and starter Markdown files:
ficgen new "Midnight Rain" # one-shot: stories/midnight-rain/index.md (draft)
ficgen new --multi "Starlight Drift" # multi-chapter: story.kdl + ch1.md (draft)
ficgen new --chapters 3 "Long Arc" # multi-chapter: story.kdl + ch1.md..ch3.md
ficgen new "Quick Shot" --published --fandom "Original Work" --category "F/F" --tag "fluff"
ficgen init "Alias Example" --slug custom-slug # `init` is an alias for `new`
New Story Options
| Flag | Default | Description |
|---|---|---|
--slug SLUG |
slugified from title | Explicit folder/URL slug (lowercase letters, digits, hyphens). |
-m, --multi |
false |
Create a multi-chapter layout (story.kdl + ch1.md) instead of index.md. |
--chapters N |
1 |
Number of starter chapter files (ch1.md..chN.md); implies --multi when > 1. |
--published |
false |
Omit published false and stamp today's date (default starts stories as drafts). |
--date DATE |
"" |
Explicit ISO-8601 date to include in starter metadata. |
--fandom, --category, --relationship, --character, --tag |
"" |
Repeatable metadata tags to pre-populate. |
--stories PATH |
./stories (or ../stories) |
Stories directory where the new folder is created. |
Importing from AO3-Compatible Archives (ficgen import)
Imports stories directly from AO3, any AO3-compatible archive (such as Superlove or SquidgeWorld), or local AO3 .epub downloads into stories/<slug>/ using ao3fetch:
ficgen import https://archiveofourown.org/works/123456
ficgen import https://superlove.sayitditto.net/works/1269
ficgen import 123456 --archive https://archiveofourown.org
ficgen import path/to/downloaded-work.epub --draft
Import Options
| Flag | Default | Description |
|---|---|---|
--archive URL |
https://archiveofourown.org |
Archive base URL used for bare numeric work IDs (full URLs auto-detect their host). |
--slug SLUG |
slugified from title | Custom directory/URL slug (when importing a single work). |
--stories PATH |
./stories (or ../stories) |
Destination stories directory. |
--draft |
false |
Mark imported story/chapters as published false. |
--force |
false |
Overwrite an existing stories/<slug>/ directory. |
--cookie COOKIE |
"" |
Optional Cookie header for importing restricted/logged-in works. |
Import behavior:
- Automatically wraps network fetches in
withCache(withRetry(...))to respect429 Retry-Afterrate limits and transient5xxerrors. - Converts work/chapter prose, summaries, and start/end notes from HTML into clean Markdown.
- Writes single-chapter works to
index.mdand multi-chapter works tostory.kdl+ch1.md,ch2.md, ..., pulling per-chapter publication dates from/works/<id>/navigatewhen available.
Stamping Publication Dates (ficgen stamp)
Inserts date "YYYY-MM-DD" into the KDL metadata blocks of undated story/chapter source files:
ficgen stamp --dry-run # preview which files would be modified
ficgen stamp # stamp all published, undated stories/chapters with today's date
ficgen stamp starlight-drift --date 2026-10-12 # stamp a specific story slug, directory, or .md file
ficgen stamp stories/midnight-rain/index.md --date 2026-08-03
ficgen stamp --force --date 2026-10-12 # overwrite existing date entries
ficgen stamp --drafts # also stamp files marked published false
Stamp Behavior
- Targets: With no positional arguments, scans every story folder in
--stories. Positional arguments accept story slugs (resolved inside--stories), directory paths, or individual.mdfiles. - Single-doc vs. multi-chapter: Stamps
index.mdfor single-doc stories, and stamps chapter files (chN.md) for multi-chapter stories (leavingstory.kdluntouched, since storyPublishedandUpdateddates derive automatically from chapter dates). - Idempotent & draft-safe: Parses KDL with
kdl-py(so//comments and/-slashdashed nodes are ignored), skips files that already have a non-emptydate/published-datenode (unless--forceis set), fillsdate null/ empty nodes in place, and skipspublished falsefiles (unless--draftsis set). - Formatting preservation: Only modifies the KDL metadata block (or inserts one after
# Title/ at the top if absent), preserving prose, KDL comments, and line endings.
2. Story Structure & KDL Metadata
Each story lives in its own subdirectory under stories/<slug>/. The directory name becomes the story's URL slug (/<slug>/). Directories starting with . or _ are ignored.
Single-Document Stories (One-Shots)
A folder containing index.md with an inline KDL metadata block (```metadata or a leading ```kdl fence):
stories/midnight-rain/
└── index.md
# Midnight Rain
```metadata
fandoms "Original Work"
categories "F/F"
characters "Elena" "Sora"
relationships "Elena/Sora"
tags "rain" "slice of life" "yearning"
date "2026-08-02"
```
<endnotes>
Inspiration track: https://example.com/playlist
Author's endnote here.
</endnotes>
Story prose begins here...
Multi-Chapter Stories
A folder containing a whole-work KDL file (story.kdl) plus chapter Markdown files (ch1.md, ch2.md, ...):
stories/starlight-drift/
├── story.kdl # Whole-work title, shared metadata, optional work-level summary/notes
├── ch1.md # Chapter 1 metadata, optional chapter notes, prose
└── ch2.md # Chapter 2 (can be marked published false while in progress)
story.kdl:
title "Starlight Drift"
fandoms "Original Work"
categories "F/F"
characters "Nadia" "Kira"
relationships "Nadia/Kira"
tags "Sci-Fi" "Slow Burn" "Space Station"
// summary "Optional work-level summary in Markdown."
// notes "Optional work-level top notes."
// endnotes "Optional work-level endnotes."
ch1.md:
# Docking Bay Nine
```metadata
chapter 1
date "2026-03-11"
```
<notes>
Welcome to chapter one!
</notes>
Chapter prose begins here...
Notes on multi-chapter stories:
- Whole-work metadata lives in
story.kdl(also acceptsmeta.kdlorindex.kdlifstory.kdlisn't present). - Chapter headings (
# ...) are optional; if omitted (or identical to the story title), the chapter is titledChapter N. Otherwise it displays asChapter N: <Chapter Title>. - Chapter order uses the
chapterinteger first, falling back to natural numeric filename order (ch2.mdbeforech10.md). Duplicate chapter numbers raise an error. - Any
fandoms,categories,relationships,characters, ortagsplaced on an included chapter are merged (deduplicated) into the story's metadata.
KDL Metadata Reference
All metadata uses KDL syntax parsed with kdl-py. Node names are matched case-insensitively with spaces/underscores normalized to hyphens (so planned-chapters, planned_chapters, and "Planned Chapters" all match).
List fields accept multiple positional arguments, repeated nodes, or child blocks:
// Positional arguments
tags "Slow Burn" "Space Station"
// Repeated nodes
tag "Slow Burn"
tag "Space Station"
// Child block
tags {
- "Slow Burn"
- "Space Station"
}
| Node | Aliases | KDL Value / Default | Description |
|---|---|---|---|
title |
(or leading # Heading) |
string | Overrides # Heading (or humanized folder slug). Required in story.kdl if different from slug. |
author |
— | string (default: site.kdl author) |
Per-story author override. |
fandoms |
fandom |
list of strings | Fandom tags (indexed under browse/fandoms/). |
categories |
relationship-categories, category |
list of strings | e.g. "F/F", "M/M", "F/M", "Gen", "Multi", "Other" (browse/categories/). |
relationships |
relationship, ships |
list of strings | Ship tags (browse/relationships/). |
characters |
character |
list of strings | Character tags (browse/characters/). |
tags |
tag, additional-tags |
list of strings | Freeform tags (browse/tags/). |
rating |
— | string | Optional rating label shown in the story metadata block. |
warnings |
archive-warnings |
list of strings | Highlighted warning pills shown in cards and headers. |
summary |
(or <summary>...</summary>) |
Markdown string | Story or chapter summary (shown on index cards, TOC, and story headers). |
notes |
startnotes, beginnotes (or <notes>) |
Markdown string | Work-level or chapter-level top notes. |
endnotes |
(or <endnotes>) |
Markdown string | Work-level or chapter-level end notes. |
date |
published-date |
"YYYY-MM-DD", (date)"YYYY-MM-DD", or (date-time)"..." |
Publication date. Multi-chapter stories default to the earliest explicit chapter date. Falls back to file mtime for Atom feeds only (HTML hides dates unless explicitly set). |
updated |
updated-date |
ISO-8601 string or (date) / (date-time) |
Last updated date. Defaults to date for one-shots, or latest chapter date for multi-chapter works. Shown in HTML only when different from Published. |
published |
— | boolean (true / false, default true) |
Set false to mark a story or chapter as a draft. |
complete |
status |
boolean (true / false) or "Complete" / "In Progress" |
Defaults to true for one-shots and false for multi-chapter stories. |
planned-chapters |
total-chapters |
integer ≥ 1 | Sets the denominator in chapter counts (e.g. 2/5 instead of 2/?). |
chapter |
— | integer ≥ 1 | Explicit chapter number for chapter files (inferred from chN.md if omitted). |
3. Special Features
Text-Message Chat Bubbles
Lines wrapped in \<...| (or unescaped <...|) and |...> render as styled SMS/chat bubbles:
\<Hey, on my way back from the station now.|
|Sounds good! Dinner is almost ready.>
\<Be there in ten.|
- Consecutive chat lines—even when separated by blank lines—are grouped into a single
<div class="chat" role="region" aria-label="Text messages">container. \<...|/<...|renders as.chat-msg.chat-left(left-aligned bubble);|...>renders as.chat-msg.chat-right(right-aligned accent bubble).- Full inline Markdown (
_italics_,**bold**, smart quotes, emoji, auto-linked URLs) works inside bubbles. - Chat syntax inside fenced code blocks is ignored.
Author's Notes & Summary Blocks
Place <notes>, <endnotes>, or <summary> tags anywhere in a story or chapter Markdown file (outside fenced code blocks), or specify notes, endnotes, or summary strings in story.kdl:
<notes>...</notes>(aliases:<startnotes>,<beginnotes>): Rendered in a styled Notes box above the prose.<endnotes>...</endnotes>: Extracted and rendered in an End Notes box below the prose (id="endnotes"), with an automatic jump link (See the end of the story/chapter for notes.) placed in the header.<summary>...</summary>: Multi-paragraph Markdown summary (combined with anysummaryKDL node).
All three support full Markdown formatting and auto-linked URLs.
Smart Typography & Auto-Linking
- Curly quotes & apostrophes: Straight
"..."and'...'convert to typographic“...”,‘...’, and’, including opening quotes immediately preceding ellipses ("...Wait→“…Wait). - Dashes & ellipses: Prose
--and---convert to em-dashes (—), numeric ranges like1990--1995convert to en-dashes (–), and...converts to…. - Auto-linked URLs: Bare
http://andhttps://URLs are automatically turned into hyperlinks in prose and notes. - Scene breaks: Standard Markdown horizontal rules (
---,* * *, etc.) render as centered✦ ✦ ✦ornaments.
Word Counts, Taxonomies, Atom Feed & Theming
- Word counts: Calculated from rendered story/chapter prose only (excluding metadata and author's notes), ignoring standalone punctuation tokens.
- Static taxonomy browsing: Every fandom, category, relationship, character, and tag gets a collision-safe static page under
browse/<kind>/<slug>.htmllinked from every story card and metadata header. - Atom 1.0 feed:
feed.xmlpublishes one entry per one-shot story and one entry per published chapter of multi-chapter works, ordered newest-first, and is linked via<link rel="alternate" type="application/atom+xml">on every page. - Light & dark mode: Styled with modern CSS
color-scheme: light darkandlight-dark(), following OS preference by default with a progressive-enhancement Light/Dark toggle persisted inlocalStorage.
Development
pip install -r requirements-dev.txt
./lint # runs ruff, black, mypy, pylint (10/10), check-manifest, and pytest
See CONTRIBUTING.md for coding conventions.
Credits & License
Created by Tab Atkins-Bittner (originally for xanthir.com/fic). MIT License — see LICENSE.
Metadata
Release files for ficgen 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ficgen-0.1.0.tar.gz | 63.8 kB | Without provenance | Details for ficgen-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ficgen-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for ficgen-0.1.0-py3-none-any.whl |
Total release size: 118.9 kB
Release files / ficgen-0.1.0.tar.gz
| Download URL | ficgen-0.1.0.tar.gz |
|---|---|
| Size | 63.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c46e9d14e374e60075dae884da6d10cd21caf3851a318e7528625a1fa8821c3b
|
|
BLAKE2b-256 checksum How to use checksums |
aca39f4b6cd56ac7e66804d4508a82d683a839150ae184b6a399688c001c969a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / ficgen-0.1.0-py3-none-any.whl
| Download URL | ficgen-0.1.0-py3-none-any.whl |
|---|---|
| Size | 55.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
09dfba96f3d581a43cbed50a4752b02f1dce3c562e615e7bee690f7fb1e110d3
|
|
BLAKE2b-256 checksum How to use checksums |
489ba0ef01c0a1151d70974acfc17e2c2552137b492b9fd5e48026695014ef85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for ficgen 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.