RSS Feed for Tiddlywiki SSG Website
Links
- https://techlifeweb.com/tiddlywiki/tw5tribalknowledge.html#RSS%20and%20Atom%20Feeds%20for%20your%20TiddlyWiki
- https://techlifeweb.com/tiddlywiki/tw5tribalknowledge.html#Atom%20Feed
- https://techlifeweb.com/tiddlywiki/tw5tribalknowledge.html#RSS%20Feed
- https://techlifeweb.com/tiddlywiki/tw5tribalknowledge.html#%24%3A%2Fdiscoverfeed
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
<?xml version="1.0" encoding="UTF-8" ?><br />
<rss version="2.0"><br />
<channel><br />
<title>
{{$:/SiteTitle}}
</title><br />
<link>{{$:/discoverfeed!!serverdomain}}</link><br /> <description>
{{$:/SiteSubtitle}}
</description><br />
<lastBuildDate><$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></lastBuildDate><br />
<$set name="MyTag" value=Feed>
<$set name="domain" value={{$:/discoverfeed!!serverdomain}}>
<$list filter=<<MyFilter>>>
<item><br /> <title>
<$view field="title"/>
</title><br />
<link><<domain>><$view field="title" format="doubleurlencoded"/>.html</link><br />
<pubDate><$view field="modified" format=date template="[UTC]ddd, 0DD mmm YYYY 0hh:0mm:0ss GMT"/></pubDate><br />
<description><![CDATA[<$view field="text" format=htmlwikified/>]]><br /> </description><br /></item><br />
</$list></$set></$set>
</channel><br /></rss><br />
Atom Feed tiddler contents
\define MyFilter(MyTag,domain)
[tag[$(MyTag)$]!sort[created]limit[100]]
\end
<?xml version="1.0" encoding="UTF-8"?><br />
<feed xmlns="http://www.w3.org/2005/Atom"><br />
<title>
{{$:/SiteTitle}}
</title><br />
<link href="{{$:/discoverfeed!!serverdomain}}" /><br />
<updated><$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></updated><br />
<author><br />
<name>
{{$:/status/UserName}}
</name><br />
</author><br />
<id>{{$:/discoverfeed!!serverdomain}}</id><br />
<link rel="self" type="application/atom+xml" href="{{$:/discoverfeed!!atomfile}}" /><br />
<$set name="MyTag" value=Feed>
<$set name="domain" value={{$:/discoverfeed!!serverdomain}}>
<$list filter=<<MyFilter>>>
<entry><br /> <title>
<$view field="title"/>
</title><br />
<link href="<<domain>>#<$view field="title" format="urlencoded"/>"/><br />
<id><<domain>>#<$view field="title" format="urlencoded"/></id><br />
<updated><$view field="modified" format=date template="[UTC]YYYY-0MM-0DDT0hh:0mm:0ssZ"/></updated><br />
<published><$view field="created" format=date template="[UTC]YYYY-0MM-0DDT0hh:0mm:0ssZ"/></published><br />
<content><![CDATA[<$view field="text" format=htmlwikified/>]]><br /> </content><br /></entry><br />
</$list></$set></$set>
</feed><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 14:42
Last update: 2021-11-15 14:16