Charon
Docs menu

Template

The template is the HTML shell around each page. Pass your own with --template, "template" in charon.json, or the Vite plugin's template.

Each {{name}} is filled once; text in the page is never read as a placeholder. A placeholder charon does not know fails the build, so a typo never ships.

Placeholders #

Placeholder Value
{{lang}} lang, such as en
{{title}} the page title, escaped
{{description}} the page description, escaped
{{name}} the site name, escaped
{{url}} siteUrl plus the page route
{{home}} the route of the root page
{{base}} the base, such as /docs, or empty
{{markdown}} the route of the Markdown copy
{{image}} the URL of the page's social card; empty without og
{{updated}} a p.docs-updated with the last commit date
{{nav}} a details menu for phones and a sticky nav
{{content}} the rendered page; wrap it in .charon
{{contentsInline}} "On this page" for narrow screens, to put above the content
{{contents}} the "On this page" column
{{footer}} the previous and next links
{{meta}} Open Graph and Twitter tags, with the card if og is set
{{head}} extra head tags, such as the KaTeX stylesheet

The default #

This is charon's own template, a fine place to start:

<!doctype html>
<html lang="{{lang}}">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>{{title}} — {{name}}</title>
    <meta name="description" content="{{description}}" />
    <link rel="canonical" href="{{url}}" />
    <link rel="alternate" type="text/markdown" href="{{markdown}}" />
    <link rel="stylesheet" href="{{base}}/_charon/docs.css" />
    {{meta}} {{head}}
    <script type="module" src="{{base}}/_charon/docs.js"></script>
  </head>
  <body>
    <header class="docs-header"><a href="{{home}}">{{name}}</a></header>
    <main class="docs-layout">
      {{nav}}
      <div class="docs-main">
        <article class="charon">
          <h1>{{title}}</h1>
          {{contentsInline}} {{content}}
        </article>
        {{updated}} {{footer}}
      </div>
      {{contents}}
    </main>
  </body>
</html>

The package ships it as docs-template.html, with its layout in docs-layout.css.

Layout #

{{nav}}, the main column and {{contents}} are three siblings, so a three-column grid lays them out. docs-layout.css does that, and stacks them on narrow screens.

Keep {{head}} in the head: pages with math put KaTeX's stylesheet there. With the CLI, keep the _charon/docs.css and _charon/docs.js tags too, or add your own.

Turn off keys #

The CLI's script reads two switches from the html element: <html lang="{{lang}}" data-docs-arrow-keys="off" data-docs-search-key="off">.

data-docs-arrow-keys="off" stops ← and → from turning pages; data-docs-search-key="off" frees Ctrl K.

Last updated