Rista

Feeds, sitemaps and 404 pages

Files from routes

Not every file on a site is an HTML page. A +route.rb with a GET method is written to its route path, so src/routes/feed.xml/+route.rb becomes feed.xml. The return value is the content of the file.

def GET(_request)
  "User-agent: *\nAllow: /\n"
end

An Atom feed

Rista::Feed.render builds an Atom feed from a list of entries:

# src/routes/feed.xml/+route.rb
Site = import("/site")
Posts = import("/posts")

def GET(_request)
  Rista::Feed.render(
    title: Site.fetch(:title),
    url: Site.fetch(:url),
    author: Site.fetch(:author),
    entries: Posts.all.reverse.map do |post|
      {
        title: post::Frontmatter.fetch(:title),
        path: "/blog/#{post::Frontmatter.fetch(:slug)}",
        updated: post::Frontmatter.fetch(:date),
        summary: post::Frontmatter.fetch(:summary),
        content: Rista::Renderer.render(Rista::H[post])
      }
    end
  )
end

author is optional, and path defaults to /feed.xml. Link the feed from the document head:

%link{ rel: "alternate", type: "application/atom+xml", href: "/feed.xml", title: "My site" }

Site metadata

src/site.rb exports a hash. Pages import it like any module:

Default = {
  url: "https://example.com",
  title: "My site",
  author: "Someone"
}.freeze

Only :url means something to Rista. The other keys are for the site’s own pages.

Sitemap

When src/site.rb has a :url, the build writes sitemap.xml with every rendered page. Files from handlers and 404 pages are left out. Without a :url, no sitemap is written.

Point crawlers at it from public/robots.txt:

User-agent: *
Allow: /
Sitemap: https://example.com/sitemap.xml

Not-found pages

src/routes/+not-found.haml is written to 404.html. It is rendered inside the layouts, like a page.

A +not-found.haml in a subdirectory covers the paths below it: routes/docs/+not-found.haml is written to docs/404.html, and the generated nginx config answers a missing /docs/... path with it.

A +not-found under a param directory such as [slug] works in serve only. A build skips it, and the nearest one above answers.