SEO & feeds

Canonical URLs, social sharing cards, syndication feeds, and sitemaps all require a public absolute origin. Set origin under [site] in tola.toml:

toml
[site]
title = "My Site"
origin = "https://example.com"
base-path = "/"

When site.origin is unset (such as early local drafts), skip canonical, feeds, and sitemap.xml rather than emitting invalid relative URLs.

Head tags

All four helpers in @tola/head:0.0.0 return arrays of HTML elements that concatenate straight into html.head:

typst
#import "@tola/address:0.0.0": output-url
#import "@tola/document:0.0.0": plain-text
#import "@tola/head:0.0.0": canonical, head-metadata, open-graph, twitter-card
#import "@tola/site:0.0.0": site

#let render-head(page, cover-url: none) = {
  let page-title = plain-text(page.meta.title)
  let browser-title = if page.kind == "home" {
    plain-text(site.title)
  } else {
    page-title + " | " + plain-text(site.title)
  }

  let tags = head-metadata(
    site,
    title: browser-title,
    description: page.meta.description,
  )

  if site.origin != none {
    let url = output-url(page.output, origin: site.origin)
    let images = if cover-url != none { (cover-url,) } else { () }
    tags += canonical(url)
    tags += open-graph(
      title: page-title,
      kind: if page.kind == "post" { "article" } else { "website" },
      url: url,
      images: images,
      description: page.meta.description,
      site-name: plain-text(site.title),
      locale: page.locale.tag,
    )
    tags += twitter-card(
      card: if cover-url != none { "summary_large_image" } else { "summary" },
      title: page-title,
      image: cover-url,
      description: page.meta.description,
    )
  }

  tags
}

When titles or descriptions contain rich Typst content (inline code or math), convert with plain-text(...) from @tola/document before placing them into <title> and <meta>. Social cover URLs in open-graph and twitter-card must be absolute URLs with origin and actually emitted via [assets], @tola/image, or a hook.

Feeds

Reuse your sorted, draft-filtered posts list at the end of site.typ to call @tola/feed:0.0.0:

typst
#import "@tola/document:0.0.0": plain-text
#import "@tola/feed:0.0.0": feed
#import "@tola/site:0.0.0": site

#if site.origin != none and posts.len() > 0 {
  feed(
    output: "feed.xml",
    format: "rss", // Supports "rss", "atom", "json"
    language: site.language.tag,
    title: plain-text(site.title),
    description: "Site updates",
    entries: posts.map(post => (
      id: post.meta.at("feed-id", default: "urn:example:" + post.id),
      target: post.output,
      title: plain-text(post.meta.title),
      published: post.meta.published.rfc3339,
      updated: if post.meta.updated != none { post.meta.updated.rfc3339 } else { none },
      summary: post.meta.description,
      content: (document: post.output, id: "article"),
    )),
  )
}

Add an autodiscovery <link> inside <head>:

typst
#html.link(
  rel: "alternate",
  type: "application/rss+xml",
  title: plain-text(site.title),
  href: output-url("feed.xml"),
)

Decouple each entry’s id from its URL (store a fixed feed-id in metadata or derive one from a stable identifier with v5 from @tola/uuid) so moving routes never triggers duplicate items in feed readers. Omitting content emits summaries only; (document: post.output, id: "article") extracts the HTML subtree with id="article" without site chrome. To link into a section of a page, set target to (output: "changelog/index.html", fragment: "v0-8-2").

Sitemap

@tola/sitemap:0.0.0 writes sitemap.xml for indexable pages (excluding 404.html, paginated archives, or pages with sitemap: false):

typst
#import "@tola/sitemap:0.0.0": sitemap
#import "@tola/site:0.0.0": site

#if site.origin != none {
  let indexable = pages.filter(p => p.meta.at("sitemap", default: true))
  sitemap(
    output: "sitemap.xml",
    targets: indexable.map(p => (
      target: p.output,
      lastmod: if p.meta.at("updated", default: none) != none {
        let u = p.meta.updated
        if type(u) == dictionary { u.rfc3339 } else { u }
      } else { none },
    )),
  )
}

Search this site

Use the arrow keys to move through results.

Type to search.