RSS Feed for Tiddlywiki SSG Website

radar23115th November 2021 at 9:16am

  • Contents
    • Links
    • Introduction
    • New Tiddlers
      • RSS Feed tiddler contents
      • Atom Feed tiddler contents
      • discoverfeed tiddler contents
    • Exporting RSS and Atom Feeds to Static Site

Links

Introduction

This post describes a feature extension to a Tiddlywiki generated static web site.

If your web site will have periodic posts (such as a blog or similar style of site), then an RSS feed would be a handy addition. This would allow readers to subscribe to the RSS feed using an RSS reader, and be notified when new posts are put up on the website, or existing posts are updated.

New Tiddlers

The following new tiddlers need to be created to support RSS and Atom feeds.

  • RSS Feed
  • Atom Feed
  • $:/discoverfeed

The RSS and Atom Feed tiddlers are dynamic pages, and handle creation of the RSS and Atom feeds. The discoverfeed tiddler allows addition of the RSS and Atom feed URLs to the site page headers. This allows RSS readers to auto-discover the correct URL to retrieve the RSS or Atom XML files. Unfortunately this content isn't currently making it through the static web page generation, so this information isn't showing up in the static web site pages. This isn't too big a deal though, as we can specify the correct RSS and Atom URLs somewhere on the website, such as an 'About' page, for example.

RSS Feed tiddler contents

\define MyFilter(MyTag,domain)
[tag[$(MyTag)$]!sort[created]limit[100]]
\end

&#60;?xml version="1.0" encoding="UTF-8" ?&#62;<br />
&#60;rss version="2.0"&#62;<br />
&#60;channel&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;title&#62;
{{$:/SiteTitle}}
&#60;/title&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;link&#62;{{$:/discoverfeed!!serverdomain}}&#60;/link&#62;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;description&#62;
{{$:/SiteSubtitle}}
&#60;/description&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;lastBuildDate&#62;<$list filter="[!is[system]get[modified]!prefix[NaN]!sort[]limit[1]]" variable=modified><$list filter="[!is[system]modified<modified>]"><$view field="modified" format=date template="[UTC]ddd, 0DD mmm YYYY 0hh:0mm:0ss GMT"/></$list></$list>&#60;/lastBuildDate&#62;<br />
<$set name="MyTag" value=Feed>
<$set name="domain" value={{$:/discoverfeed!!serverdomain}}>
<$list filter=<<MyFilter>>>
&#60;item&#62;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;title&#62;
<$view field="title"/>
&#60;/title&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;link&#62;<<domain>><$view field="title" format="doubleurlencoded"/>.html&#60;/link&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;pubDate&#62;<$view field="modified" format=date template="[UTC]ddd, 0DD mmm YYYY 0hh:0mm:0ss GMT"/>&#60;/pubDate&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;description&#62;&#60;![CDATA[<$view field="text" format=htmlwikified/>]]&#62;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;/description&#62;<br />&#60;/item&#62;<br />
</$list></$set></$set>
&#60;/channel&#62;<br />&#60;/rss&#62;<br />

Atom Feed tiddler contents

\define MyFilter(MyTag,domain)
[tag[$(MyTag)$]!sort[created]limit[100]]
\end

&#60;?xml version="1.0" encoding="UTF-8"?&#62;<br />
&#60;feed xmlns="http://www.w3.org/2005/Atom"&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;title&#62;
{{$:/SiteTitle}}
&#60;/title&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;link href="{{$:/discoverfeed!!serverdomain}}" /&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;updated&#62;<$list filter="[!is[system]get[modified]!prefix[NaN]!sort[]limit[1]]" variable=modified><$list filter="[!is[system]modified<modified>]"><$view field="modified" format=date template="[UTC]YYYY-0MM-0DDT0hh:0mm:0ssZ"/></$list></$list>&#60;/updated&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;author&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;name&#62;
{{$:/status/UserName}}
&#60;/name&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;/author&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;id&#62;{{$:/discoverfeed!!serverdomain}}&#60;/id&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;link rel="self" type="application/atom+xml" href="{{$:/discoverfeed!!atomfile}}" /&#62;<br />
<$set name="MyTag" value=Feed>
<$set name="domain" value={{$:/discoverfeed!!serverdomain}}>
<$list filter=<<MyFilter>>>
&#60;entry&#62;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;title&#62;
<$view field="title"/>
&#60;/title&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;link href="<<domain>>#<$view field="title" format="urlencoded"/>"/&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;id&#62;<<domain>>#<$view field="title" format="urlencoded"/>&#60;/id&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;updated&#62;<$view field="modified" format=date template="[UTC]YYYY-0MM-0DDT0hh:0mm:0ssZ"/>&#60;/updated&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;published&#62;<$view field="created" format=date template="[UTC]YYYY-0MM-0DDT0hh:0mm:0ssZ"/>&#60;/published&#62;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;content&#62;&#60;![CDATA[<$view field="text" format=htmlwikified/>]]&#62;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;/content&#62;<br />&#60;/entry&#62;<br />
</$list></$set></$set>
&#60;/feed&#62;<br />

discoverfeed tiddler contents

Exporting RSS and Atom Feeds to Static Site

The RSS and Atom Feed tiddlers are exported to the rss.xml and atom.xml files using the "–rendertiddler" tiddlywiki command. This will get run once for each file. This means our "build_static_website.sh" (as detailed in Tiddlywiki Static Site Generation) will now look like this;

$ cat build_static_website.sh 

#!/bin/bash

wikiPath='/mnt/k8s-storage/wikis/website-wiki/mywiki'
devWebsite='/mnt/k8s-storage/delfax/website'

cd ${wikiPath}
sudo tiddlywiki --rendertiddlers [!is[system]!tag[Draft]] $:/rdr231/templates/static.tiddler.html static text/plain --rendertiddler $:/rdr231/templates/static.template.css static/static.css text/plain
sudo tiddlywiki --rendertiddler "RSS Feed" static/rss.xml text/plain ""
sudo tiddlywiki --rendertiddler "Atom Feed" static/atom.xml text/plain ""
sudo rsync -avv --delete ${wikiPath}/output/static/ ${devWebsite}/
sudo chmod -R o+r ${devWebsite}/*

....................
(created: 2021-09-04, last modified: 2021-11-15 at 09:16:47)