Zine

Frequent Use Cases

About

This page collects common use cases that people will encounter while creating a Zine site.

As time passes new use cases will emerge as common enough to be listed here, so you might want to check back from time to time when wondering how to implement something in Zine.

Table of Contents

RSS feed

Zine doesn't have direct knowledge of RSS feeds but by combining a handful of its features you can add support for the most syndication formats commonly used.

In this example we'll assume that we want to generate an RSS feed for a blog.

1. Define an alternative for the post listing page

Your blog should have a page that lists all posts. We'll generate the RSS feed as an alternative version of it.

If you think about it, this is the semantically correct thing to do, since an RSS feed is an alternative version of a page that lists your posts.

posts.smd (in the frontmatter)

---
.alternatives = [{
  .layout = "rss.xml",
  .output = "index.xml",
}],
---

2. Create the XML layout

SuperHTML doesn't support XML officially yet, but there is enough support to generate correct feeds.

This is a RSS2.0 example but you can also do the same with Atom, if you prefer.

rss.xml

<rss version="2.0">
 <channel>
  <title>My blog</title>
  <link>https://site.com/</link>
  <description>Recent content</description>
  <generator>Zine -- https://zine-ssg.io</generator>
  <language>en-us</language>
  <lastBuildDate :text="$build.generated.formatHTTP()"></lastBuildDate>
  <ctx :loop="$page.subpages()">
   <item>
    <title :text="$loop.it.title"></title>
    <link :text="$site.host_url.addPath($loop.it.link())"></link>
    <pubDate :text="$loop.it.date.formatHTTP()"></pubDate>
    <guid :text="$site.host_url.addPath($loop.it.link())"></guid>
   </item>
  </ctx>
 </channel>
</rss>

3. Link to your RSS feed

<a href="/index.xml" rel="alternate" type="application/rss+xml">
  RSS feed
</a>