A tool project can publish the documentation that lives in its own repository: guides written in Markdown and a reference generated by a command. This page is the entry point: it describes how guides become pages and how the reference is generated. Nothing is repeated from the page that already exists:
- Where the documentation comes from, the
docsblock ofproject.yaml(source,github,guides,reference), the fetching of git repositories and folders, the cache, git safety, the failures and the manifest entry are described in Where a project’s documentation comes from. That page is the canonical description of thedocsblock. - The page of the project that links to its documentation is described in Projects.
Guides: How They Become Pages
The guides named in the docs block of project.yaml are rendered with the same Markdown pipeline and the same theme as the rest of the site, at /{projects}/{slug}/{docs}/{page}/ (/made/kerfcalc/docs/usage/ with the defaults; urls.projects and urls.docs move them). The files come from the fetched source (Where a project’s documentation comes from); nothing is rendered unless the project has at least one guide.
Which Files, in Which Order
- A guide publishes the Markdown files (
.mdand.markdown) of itsdirthat itsincludepatterns select and itsexcludepatterns leave out (syntax in docs-sources.md)..gitandnode_modulesfolders are never searched, and a symbolic link to a folder is not followed. - No file selected is an error, naming the guide: there is no fallback to empty documentation.
- Sidebar order: the docs index first; then, for each guide in the order they are listed, the files named in
order(in that order), then the remaining files by path (code-point order, soZ.mdis beforea.md). A name inorderthat is not a published file is a warning. A file selected by two guides belongs to the first. - Bounds: at most 500 pages for a project and 1 MiB for a file; a file that is not valid UTF-8 is an error; a byte order mark is dropped and Windows line endings are accepted, with line numbers in findings unchanged.
Addresses
The address of a page is its path in the guide, without .md, in lower case, with every run of characters other than letters (a-z) and digits as one dash, and folders as path segments: Api/Error_Codes.md is .../docs/api/error-codes/. A README or index file in a sub folder stands for the folder (api/README.md is .../docs/api/). A name from which no address can be made (only non-Latin letters) is an error that asks for a rename.
The docs index (/{projects}/{slug}/{docs}/, the target of the documentation link) is the index.md, else README.md, in the folder of the first guide; the other of the two is then an ordinary page (.../docs/readme/). If the folder has neither, the build writes a plain index that lists the pages, so the link always leads somewhere.
Two files with the same address (a_b.md and a-b.md), an address that begins with reference or search (reserved for the generated reference and for search), and a page written to a file another page also uses are errors that name the files.
Titles and Metadata
The title of a page is its first heading of level 1, which is then left out of the body (the template writes it once, with its id, so links to it keep working). A page without one is titled from its file name, how_to-install.md being “How To Install”; the docs index is “Documentation”. The <title>, description (the first words of the text), canonical address and Open Graph tags are made like those of other pages (the preview picture is the project’s card). A page with four or more headings of level 2 or 3 gets the table of contents posts have, from the same partial. Docs pages are in the sitemap and in the manifest: as pages of type docs, and as docs.pages of the project (url, file, source (the path in the documentation source, null for a generated index) and title).
Link Rewriting
A link is resolved from the folder of the page that holds it; a link that starts with / is resolved from the root of the repository, as it is on GitHub. ?query and #anchor are kept. Every finding is located as {repo}:{path}:{line}:{column}, where {repo} is the name of the folder for a folder source and the name of the GitHub repository (else the project’s slug) for a git source: sample-tool:docs/usage.md:7:1 broken link 'gone.md' (...).
| The link leads to | Result |
|---|---|
another published guide file (usage.md, ./usage.md#options), or the folder of the docs index (./) |
the site address of the page, anchor kept; the anchor has to be a heading or an id of that page |
#anchor |
left as it is; it has to be a heading or an id of the page itself (#top always works) |
a file of the repository that is not published (a source file, LICENSE, ../CHANGELOG.md, ../README.md) |
https://github.com/{owner}/{repo}/blob/{ref}/{path} |
| a folder of the repository | https://github.com/{owner}/{repo}/tree/{ref}/{path} (the root is .../tree/{ref}) |
ref:Name, ref:com.example.Name |
the address of that symbol in the project’s reference; an unknown or ambiguous name is an error (see Links to the reference) |
https:, http:, mailto:, //host/... |
left alone |
any other scheme (javascript:, data:, vbscript:, file:) |
error; the page carries # instead |
| a file that does not exist, or one that exists with other capitalisation | error |
| a path that goes above the root of the repository, or through a symbolic link that leads out of it | error |
an unpublished file or folder, when the docs block has no github setting |
error, asking for the setting |
Path segments of GitHub addresses are percent-encoded. The {ref} is the configured ref for a git source (a branch or tag). For a folder source it is the full commit when the folder is itself the root of a git repository (it has a .git) and the commit is known, because a commit never moves; otherwise main, because the commit of a larger repository that merely contains the folder is not a commit of the GitHub repository.
Links written as raw HTML are not rewritten (they are left as written and the output check reports the ones that lead nowhere), but every address in raw HTML is checked for a refused scheme.
Links to the Reference
A guide can name a symbol of the project’s reference instead of writing the address of its page: [text](ref:Name) or [text](ref:com.example.Name). The link becomes the address of that symbol in the reference, and inline code that is exactly the name of a symbol is linked without any markup. How the symbols are found is described in Linking guides to the reference.
Images
A relative image is read from the repository (through the same containment as every other file), must exist, and goes through the image pipeline like a post’s: responsive WebP variants, width and height, lazy loading, a warning without alt text, the site’s metadata policy, the viewer, and an entry in the manifest’s images. http: and https: images are left as they are. SVG images are not published from a guide (a clear error asks for a PNG, WebP or JPEG), and so are data: pictures and anything else that is not JPEG, PNG, WebP or HEIC. A missing image is an error located at the image. Carousels (:::carousel) work as in posts; ::map is left out with a warning; any other directive is an error with its line.
The Template
docs.njk extends base.njk, so the header, footer, theme switch and styles are the site’s. It writes: breadcrumbs (projects, the project, the documentation, the page); a <nav> with the label “{project}: documentation pages” listing the pages in order with the current one marked aria-current="page"; the page; previous and next links; and, when the github repository is known, a link “View this page on GitHub” to the file. On a narrow screen (360 px) the sidebar is above the text; from 60 rem it is beside it and stays in view. No script is needed and nothing is animated. Each part is a block (docs_breadcrumbs, docs_sidebar, docs_header, toc, docs_body, docs_pager, docs_source); a theme can replace one ({% extends "coffer:docs.njk" %}). The template receives project, projectsUrl, toc and docs (isIndex, generated, indexUrl, url, titleId, sidebar ({ title, url, current }), previous, next and sourceUrl).
README Sections on the Project Page
The page of a project that has a docs source can show a section of the README of the project’s repository, so that the marketing page reuses the quick start without copying it:
## Quick start
::readme{section="Quick start"}
section is the text of a heading of the README (white space and capitals do not matter; the first heading that matches is used). The directive inserts what is below that heading, up to the next heading of the same or a higher level, so sub sections come with it; the heading itself does not, because the page writes its own. file takes the section from another Markdown file of the repository, as in ::readme{file="docs/install.md" section="Linux"}; without it the README in the top folder of the source is used (README.md, else any file called readme.md or readme.markdown).
The section is rendered like a guide: relative links are read from the folder of the file, a link to a published guide becomes the address of its page, a link to another file of the repository becomes its address on GitHub, ref: links and inline code that names a symbol of the reference are linked, and a broken link fails the build, naming the README (lathe:README.md:12). Pictures next to the README are published through the image pipeline under the page’s metadata policy; they are shown as plain pictures, not in the image viewer of the page. The insertion is wrapped in <div class="readme-section">.
An unknown file or heading, a section with no content, a ::readme without section and a ::readme on a page whose project has no docs source fail the build with the path of the project’s index.md and the line of the directive. The directive is not available in posts, guides, the home page or press kit descriptions.
The Landing Page and Brand Files
The same docs.source can also hold the page of the project. landing: { file: site/landing.md } in project.yaml makes that file the text of the project’s page instead of a local index.md; brand: { dir: site/brand } names a folder of brand files; card (and the picture keys of a kind that has a docs source) accept repo:site/card.png. The keys require docs.source, take paths inside the source (no .., not absolute), and a folder with landing must not also have an index.md. See A page and pictures from the project’s repository for the rules and The landing file as the page for how the file is rendered. After the fetch the build copies the files of brand.dir unchanged to /assets/{slug}/... (a collision with a theme asset fails the build) and reads a repo: card from the checkout like a picture of the project folder; a missing file fails the build naming the key and the path. The landing file and the commit it was read at are recorded in the manifest and in build-info.json, and coffer rebuild-needed compares the commit of the source, so a push to the project repository rebuilds the site even when the project has landing and docs.source only (see Scheduled rebuilds). See The brand folder and the pictures of the source.
The Link to the Documentation
The tool page and the project block of a post link to /{projects}/{slug}/{docs}/ if and only if the build rendered documentation pages for the project. With guides empty and no reference the docs section is empty and the link is hidden. A docs block with a reference only has a docs index that the build writes (it lists the reference), so the link is there.
Trust
See Trust: raw HTML in a guide is passed through like in your own posts; addresses with unsafe schemes are refused.
The coffer docs fetch command (see Build) fetches the sources without building anything.
The Reference
A tool can also publish a reference, generated from the project’s own source by a command (javadoc or Dokka for a library; a script that reads the commands and configuration keys for a tool that has no API). What generates it is configuration, so coffer assumes no language. The reference is published at /{projects}/{slug}/{docs}/reference/ (/made/kerfcalc/docs/reference/ with the defaults), listed last in the sidebar of the guides, with its configured title, and on the generated docs index.
The reference is deliberately generic. It does not use the site’s theme: a generated folder of HTML is copied as it is, and a JSON reference is rendered by a plain page of coffer’s own with a stylesheet of its own. Both carry a thin bar at the top, “← back to {project} on {site}”, that leads to the project’s page. This is a decision, not a gap: the guides are the part that looks like the site.
# content/projects/kerfcalc/project.yaml
docs:
source: { path: ../../../sample-tool }
reference:
command: [node, scripts/reference.js, "{out}/reference.json"]
format: json
output: "{out}/reference.json"
title: Kerfcalc reference
undocumented:
pattern: '^warning: (?<name>\S+) is not documented$'
| Key | Meaning |
|---|---|
command |
Required. A list (the program and its arguments, run without a shell) or a text (a command line for the system’s shell: cmd.exe on Windows, /bin/sh elsewhere). {repo}, {out} and {site} are replaced. For a tool that starts differently on Windows, a mapping {default, windows} of these: the windows entry is used on Windows, the default entry everywhere else (see the command). |
format |
Required. html or json. |
output |
Required. Where the command leaves its result: a folder for html, a file for json. Relative to the checkout; the placeholders are replaced here too. |
title |
Required. The name of the reference, in the sidebar and on the docs index. |
undocumented |
Optional. {pattern}: a regular expression with a named group name ((?<name>...)), matched line by line (flags gm) against the output of the command; every match names an element without documentation. |
index |
Optional, html only. The index adapter that finds the symbols of the generated folder, so that guides can link to them: its name (dokka) or {adapter, file}. See Linking guides to the reference. |
autoLink |
Optional, true or false (default true). Whether inline code in guides that is exactly the name of a symbol becomes a link to it. |
The Command
It runs with the checkout of the project’s repository as its working directory (the cache folder of the repository for a git source, the folder itself for a path source). The placeholders are:
{repo}: the absolute path of that checkout;{out}: an empty folder made for this run, in.cache/reference/{slug}/, which is removed afterwards. Prefer writing there: a command that writes into the checkout makes apathsource look changed (see the cache);{site}: the root of the content repository, the folder ofcoffer.yaml, for a command that needs something from the site.
In a list, a placeholder is replaced inside each item. In a text, it is replaced by the path, put in quotes for the shell when it needs them. A list is the safer form (no shell parses it); it needs an executable program. A program without a slash is looked up in the absolute folders of the PATH (never in the checkout), and node is the Node that runs coffer when the PATH has none; a program with a slash is relative to the checkout. A script that needs a shell (gradlew.bat, npm) is written as a text.
A command that is started differently on Windows (./gradlew against .\gradlew.bat) is written as a mapping, each entry being a list or a text:
command:
default: ./gradlew --no-daemon dokkaGeneratePublicationHtml
windows: .\gradlew.bat --no-daemon dokkaGeneratePublicationHtml
default is required. Write .\gradlew.bat with the leading .\: cmd.exe does not look in the current folder when NoDefaultCurrentDirectoryInExePath is set.
The environment of the command is the one of coffer without the variables whose names look like secrets: names containing TOKEN, SECRET, KEY, PASSWORD, PASSWD, CREDENTIAL, AUTH, COOKIE or PRIVATE (in any case), and the ones that begin with CLOUDFLARE_, R2_ or AWS_. The command is code of another repository and never needs the keys the site is published with. It is killed, with everything it started, after 15 minutes. Running the command is running code of the repository (Gradle runs build scripts, npm runs scripts): configure a reference only for repositories you trust.
The Output
It has to exist after the command succeeded and to be inside the checkout or in {out}, links followed: a symbolic link in the repository cannot make the build publish a file from outside. A folder (html) must have an index.html, which is the address of the reference; it is copied up to 50 000 files and 512 MiB, and links inside it are not copied (a warning names them). A json file can be at most 8 MiB.
html. Every file of the folder is copied unchanged, except that every HTML page (.html, .htm) gets the bar right after the start of its <body> (at its start when it has no body; after the doctype when there is one). The pages are handled as bytes, so their encoding is not touched, and the bar is plain ASCII with its style in the element. coffer check follows the links of these pages like those of any page but does not ask them for preview metadata (the theme did not make them), and the reference is not in the sitemap.
json. The command writes a file in this format, which any generator can produce:
{
"title": "Kerfcalc commands",
"sections": [
{
"title": "Commands",
"items": [
{
"name": "waste",
"kind": "command",
"signature": "kerfcalc waste <kerf> <pieces>",
"description": "Prints the length of wood the saw cut removes.\n\nA second paragraph.",
"anchor": "cmd-waste",
"undocumented": false
}
]
}
]
}
| Field | Meaning |
|---|---|
title |
Optional. The heading of the page; the configured title when absent. |
sections |
Required. A list of {title, items}, at most 1000. The page begins with an index of the sections. |
items[].name |
Required. The name of the element. |
items[].kind |
Optional. Free text such as function, option or environment variable. |
items[].signature |
Optional. Shown as code, as written. |
items[].description |
Optional. Plain text; a blank line starts a paragraph. It is escaped, not read as Markdown or HTML. |
items[].anchor |
Optional. The id of the element on the page, so that links can point at it: letters, digits, -, _, . and :, starting with a letter or digit. It must be unique. Without one, an id is made from the name (Kerf.waste is kerf-waste; -2, -3 on a clash). |
items[].undocumented |
Optional. true for an element that has no documentation. |
Unknown fields are ignored, so a generator can carry more than coffer reads. Names and titles are at most 500 characters, a signature 5000, a description 50 000; there are at most 20 000 items. A file that does not fit the format fails the build, with the place of every problem (sections[0].items[2].name: is required). The page is rendered by reference.njk, a standalone template that does not extend base.njk; a theme can replace it, or extend the engine’s copy and replace its blocks reference_style and reference_body. The template receives lang, heading, project (name, url), bar, sections (id, title, items with id, name, kind, signature, paragraphs, undocumented), itemCount and undocumentedCount.
Linking Guides to the Reference
Guides and the reference are linked through a symbol index, made for each project from its reference. A symbol has a name, which may be qualified (com.example.Tool, Kerf.waste), and an address. Its simple name is the part after the last dot (Tool, waste). The index finds a symbol by either name, written exactly (case matters).
Where the symbols come from:
jsonreference: every item. Its name is the item’sname; its address is the reference page with the anchor of the item (/made/kerfcalc/docs/reference/#kerf-waste): theanchorof the file, else the one the page makes from the name.htmlreference: the file of an index adapter in the generated folder, named byindex.index: dokkareads Dokka’sscripts/pages.json;index: { adapter: dokka, file: other/pages.json }reads another file of the folder. Withoutindex, anhtmlreference has no symbols.
The dokka adapter reads a list of records {name, description, location, searchKeys}:
location, relative to the generated folder and with an anchor when the symbol has one, is the address;- the identifier in
name(Tool, orwasteforfun waste(...)) is the simple name; - a
searchKeysentry, or thedescription, that ends in a dot and the identifier (com.example.Tool) is a qualified name; so is thedescriptionfollowed by the identifier when the description is a dotted owner (com.example.Toolandspacinggivecom.example.Tool.spacing); - a record without a usable identifier is left out.
A file that is missing, is not valid JSON, or has a location that leaves the folder (an absolute address, a scheme, ..) fails the build, with the place of the problem (docs.reference.index: scripts/pages.json: [3].location: ...). More adapters can be added in src/docs/symbols.js (INDEX_ADAPTERS): a default file name and a function from the text of the file to a list of {name, url, keys}.
In guides:
[text](ref:Name), alsoref:com.example.Name, is replaced by the address of the symbol. A name that is unknown, or that finds more than one symbol (two classes with one simple name, overloads with a page each), fails the build, located at the link like every other link error:sample-tool:docs/usage.md:12:3 broken link 'ref:Kerf.gone' (the reference has no symbol "Kerf.gone"). A project with no symbols (noreference, or anhtmlone withoutindex) fails the same way.- Inline code that is exactly a simple or qualified name that finds one symbol is wrapped in a link to it. A name that finds several symbols is not linked, and nothing is reported; write the qualified name. Code blocks, code that is already inside a link, and code with markup inside it are never linked (a
<code>element written as raw HTML is treated like inline code).autoLink: falseturns the automatic links off;ref:links keep working.
Undocumented Elements
An element is undocumented when its item has undocumented: true, when its name is one that the undocumented pattern found in the output of the command, or both. The page shows such an element with its name, kind and signature only (its description is not shown) and a note, “Not documented”. Every one is a warning in the build report (.coffer/report.json and the output of the build), such as content/projects/kerfcalc/project.yaml: docs.reference: "Kerf.spacing" (Functions) has no documentation, and is listed in the manifest. Names found by the pattern that match no item (always so for html) are reported by name. Nothing about documentation ever fails the build.
Failures
A command that cannot be started, exits with a code other than 0, is stopped by a signal or runs out of time; an output that does not exist, is of the wrong kind or lies outside the allowed folders; and a json file that does not fit the format are errors of the project’s project.yaml: project.yaml docs.reference: the command `node scripts/reference.js ...` failed (exit code 3): <the last lines of its output>. The build fails; nothing is published for that reference and nothing is cached.
The Cache
The result is stored in .cache/reference/{slug}/{commit}-{hash}/, where commit is the commit of the source (the one coffer docs fetch prints) and hash covers command, format, output and undocumented (the title is not part of it), and the contents of the files and folders of the content repository that the command names through {site} ({site}/generators/reference.mjs, --init-script={site}/build-support/init.gradle.kts; a folder is read with everything in it). Editing such a script therefore gives a new entry. Files that a script itself reads or imports are not followed, and {site} alone (the whole repository) is not an input. A build whose commit and configuration have an entry does not run the command: the manifest says "cached": true, the pages are written from the stored result and the undocumented elements are reported as before. Only a source pinned to a commit is cached: a git source always is; a path source only when the folder is in a git repository and has no uncommitted changes (a folder outside a repository, or a changed one, runs the command every time). The result is expected to depend on the contents of the repository and the configuration only, not on {site} or on the machine. The five most recently used results of a project are kept. Like the repository cache, .cache/ must not be published, and two builds must not use the same cache folder at the same moment.
In the Manifest
docs.reference of a project is null without a reference, otherwise { url, file, format, title, files, items, undocumented, cached } (items is null for html). The reference pages are not in pages and not in the sitemap.