Build a documentation site

Build a small documentation site with a custom home page, Markdown pages, a sidebar, search, code highlighting, and generated sitemap and robots files. The same pieces are used by the Fission documentation site.

1. Create the project

fission init docs-site
cd docs-site
fission add-target static-site --project-dir .
Set the site fields in fission.toml:
targets = ["static-site"]

[app]
name = "docs-site"
app_id = "com.example.docs_site"

[site]
entry = "crate::site_app"
title = "Docs Site"
description = "Documentation for the product."
base_url = "https://docs.example.com"
out_dir = "dist/site"
asset_dirs = ["static"]
logo = "/img/logo.svg"
favicon = "/img/favicon.svg"
generate_sitemap = true
generate_robots = true

[site.code_highlighting]
enabled = true

[site.search]
enabled = true

[[site.routes]]
kind = "content"
path = "/docs"
source = "content/docs"
template = "fission::site::documentation"
sidebar = "site/docs-sidebar.toml"

2. Add content and sidebar

content/docs/intro.mdx
content/docs/learn/quickstart.mdx
site/docs-sidebar.toml
static/img/logo.svg
content/docs/intro.mdx:
---
title: Introduction
description: Learn what the product does.
---

# Introduction

Start here.
site/docs-sidebar.toml:
[[items]]
title = "Start"
href = "/docs/intro/"
level = 1
group = true

[[items]]
title = "Introduction"
href = "/docs/intro/"
level = 2

[[items]]
title = "Quickstart"
href = "/docs/learn/quickstart/"
level = 2

3. Add a custom home page

use anyhow::Result;
use fission::prelude::*;
use fission::site::{build_from_cli, FissionSite};

#[derive(Debug, Default)]
struct SiteState;
impl GlobalState for SiteState {}

fission_component! {
    pub HomePage<()> {}
    view(_page, _state, cx) {
        let tokens = &cx.view.env().theme.tokens;
    } =>
    Column(gap: tokens.spacing.l, children: [
        Text(TextContent::Key("docs.home.title".into()),
            font_size: tokens.typography.display_sm_size,
            font_weight: tokens.typography.font_weight_bold),
        Text(TextContent::Key("docs.home.introduction".into())),
        Link::to(cx.tr("docs.home.start"), "/docs/intro/"),
    ])
}

pub fn site_app() -> FissionSite {
    FissionSite::new().route_widget::<SiteState, _>(
        "/",
        "Docs Site",
        Some("A Fission static documentation site.".to_string()),
        HomePage,
    )
}

fn main() -> Result<()> {
    build_from_cli(site_app())
}
Define the three docs.home.* messages in the site's translation bundles and pass the prepared environment to FissionSite::with_env(...); use the shared setup from Theming and i18n. The homepage consumes that environment and links to a real content route, instead of being a heading with no next action. Add the listed quickstart page and image assets before checking: link validation should reject an unfinished navigation target.

4. Check and build

fission site check --project-dir .
fission site build --project-dir . --release
Review dist/site/index.html, dist/site/docs/intro/index.html, dist/site/site.css, dist/site/search/, dist/site/sitemap.xml, and dist/site/robots.txt.

5. Package and publish

fission package --project-dir . --target static-site --format static --release
fission publish --project-dir . --provider github-pages --artifact target/fission/release/static-site/static/artifact-manifest.json --site production
Open the generated pages under dist/site/ and check that the home page, docs routes, search index, sitemap, and robots file are present. The package manifest is the input to the publish command; it records the artifact that command will upload.