Hosting · Your own pages

Your own pages

By default the server shows its own landing page at /. You can serve your own pages from the same server: a home page, a pricing page, docs, or a blog. This page covers the site.json file that describes them.

Start the server with a site

Pass the path to a site.json file, or to a directory that holds one:

civ api start --site ./site

Your pages and the app share one address, for example example.com/pricing and example.com/settings. No CORS setup is needed.

site.json

Put site.json next to the pages it describes. Every path in it is relative to the file.

{
  "pages": {
    "/": "routes/index.html",
    "/pricing": "routes/pricing.html",
    "/terms": "routes/terms.html"
  },
  "files": { "/config.js": "config.js" },
  "assets": [{ "urlRoot": "static", "dir": "static" }],
  "notFound": "routes/404.html"
}
Key What it does
pages Maps a URL path to an HTML file.
files Maps a URL path to a single file of any type.
assets Serves a whole directory (dir) under a URL prefix (urlRoot).
notFound The HTML file shown for a page that does not exist.
shell The header and footer for pages made from markdown. See below.
sections Docs and blog sections made from markdown. See below.

Which requests your site answers

  1. If the path is one your site declares (a page, a file, an asset directory or a markdown section), the site answers it.
  2. Every other request goes to the app.
  3. If the app answers 404 to a request for an HTML page outside the app's own paths, the visitor gets your notFound page. 404s from the API and from blobs stay as JSON.

There is one exception to step 1: a signed-in visitor who opens / gets their account home, not your home page.

Reserved paths

The app owns these paths. A pages entry that uses one stops the server from starting.

/api                 /blobs             /assets            /styles.css
/settings            /admin             /apps              /u
/authorize           /logout
/login               /signup            /forgot-password   /reset-password
/mfa-challenge       /mfa-recovery        /magic-link        /verify-email
/.well-known/types   /.well-known/civility-user

Link to the app's own /login and /signup from your pages.

Pages from markdown

To publish docs or a blog, add a section. The server turns the markdown into pages when it starts. There is no build step.

{
  "shell": {
    "brand": { "label": "Acme", "href": "/", "icon": "/static/icon.svg" },
    "stylesheets": ["/static/site.css"],
    "nav": [{ "href": "/docs", "label": "Docs" }],
    "footer": {
      "note": "© Acme",
      "links": [{ "href": "/terms", "label": "Terms" }]
    }
  },
  "sections": [
    {
      "layout": "docs",
      "prefix": "/docs",
      "source": "./content/docs",
      "titleSuffix": " — Acme docs",
      "groups": [{ "dir": "guides", "heading": "Guides", "order": ["install"] }]
    },
    {
      "layout": "blog",
      "prefix": "/blog",
      "source": "./content/blog",
      "title": "Blog"
    }
  ]
}
  • shell sets the header, stylesheets, navigation and footer that every markdown page shares.
  • Each entry in sections has a layout (docs or blog), a URL prefix, and a source directory of markdown files.
  • Markdown is GitHub-flavoured, so tables work. A code block that names its language (```ts) is highlighted with hljs-* classes; your stylesheet sets the colours.
  • The markdown is read when the server starts. Restart the server to pick up edits. In a container, copy the markdown into the image.

Docs sections

A docs section makes one page per markdown file, with a sidebar.

  • README.md becomes the section's index page. guides/install.md becomes /docs/guides/install.
  • The sidebar lists the index first, then the top-level files, then each group in groups.
  • order lists the files that come first. Files not in order follow in alphabetical order. A section and each group can have its own order.

To publish several directories as one set of docs:

  1. Give each directory its own docs section.
  2. Put each prefix under the first one, for example /docs and /docs/hosting.
  3. Give each section a heading.

The sections then share one sidebar, in the order they appear in site.json. The section being read lists its pages. Each other section is a single link.

The sidebar is written into the page twice: as nav.docs-sidebar, and inside details.docs-picker, whose summary shows the name of the open page. Show one or the other in your stylesheet, so narrow screens get the picker.

Blog sections

A blog section makes one page per post, plus an index page at the prefix.

  • A post is a file such as 001_launch.md, or a directory such as 001_launch/ with an index.md (or a locale file like en.md) and the post's images.
  • The number at the start is not part of the URL.
  • Each post's frontmatter has a title and a published date in ISO format. The index lists posts newest first.
  • A post with published: null still gets a page, but is not listed on the index.

Relative links between markdown files are rewritten to the URLs of the pages. For links that point outside the sections, for example to source code, set linkFallback to send them to a repository browser:

{
  "linkFallback": {
    "root": "./content",
    "baseUrl": "https://git.example.com/acme/site/blob/main"
  }
}

See also