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
- If the path is one your site declares (a page, a file, an asset directory or a markdown section), the site answers it.
- Every other request goes to the app.
- If the app answers 404 to a request for an HTML page outside the app's own paths, the visitor gets your
notFoundpage. 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"
}
]
}
shellsets the header, stylesheets, navigation and footer that every markdown page shares.- Each entry in
sectionshas alayout(docsorblog), a URLprefix, and asourcedirectory of markdown files. - Markdown is GitHub-flavoured, so tables work. A code block that names its language (
```ts) is highlighted withhljs-*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.mdbecomes the section's index page.guides/install.mdbecomes/docs/guides/install.- The sidebar lists the index first, then the top-level files, then each group in
groups. orderlists the files that come first. Files not inorderfollow in alphabetical order. A section and each group can have its ownorder.
To publish several directories as one set of docs:
- Give each directory its own
docssection. - Put each prefix under the first one, for example
/docsand/docs/hosting. - 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 as001_launch/with anindex.md(or a locale file likeen.md) and the post's images. - The number at the start is not part of the URL.
- Each post's frontmatter has a
titleand apublisheddate in ISO format. The index lists posts newest first. - A post with
published: nullstill gets a page, but is not listed on the index.
Links in markdown
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
- Server spec §13.9 for how requests are resolved
- CLI spec §17.2.6 and §17.3.2 for sections and the full
site.jsonshape