Title: RSS feed for OpenBSD stable packages repository (made with XSLT) | |
Author: Solène | |
Date: 05 June 2019 | |
Tags: openbsd automation | |
Description: | |
I am happy to announce there is now a RSS feed for getting news in case | |
of new | |
packages available on my repository | |
[https://stable.perso.pw/](https://stable.perso.pw/) | |
The file is available at | |
[https://stable.perso.pw/rss.xml](https://stable.perso.pw/rss.xml). | |
I take the occasion of this blog post to explain how the file is | |
generated as I | |
did not find easy tool for this task, so I ended up doing it myself. | |
I choosed to use **XSLT**, which is not quite common. Briefly, **XSLT** | |
allows | |
to use some kind of XML template on a XML data file, this allow loops, | |
filtering etc... It requires only two parts: the template and the data. | |
**Simple RSS template** | |
The following file is a template for my RSS file, we can see a few tags | |
starting by `xsl` like `xsl:for-each` or `xsl:value-of`. | |
It's interesting to note that the `xsl-for-each` can use a condition | |
like | |
`position < 10` in order to limit the loop to the 10 first items. | |
<?xml version="1.0" encoding="UTF-8"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> | |
<channel> | |
<description></description> | |
<title>OpenBSD unofficial stable packages | |
repository</title> | |
<link>https://stable.perso.pw/</link> | |
<atom:link href="https://stable.perso.pw/rss.xml" | |
rel="self" type="application/rss+xml" /> | |
<!-- END CONFIGURATION --> | |
<xsl:for-each select="feed/news[position()<10]"> | |
<item> | |
<title> | |
<xsl:value-of select="title"/> | |
</title> | |
<description> | |
<xsl:value-of select="description"/> | |
</description> | |
<pubDate> | |
<xsl:value-of select="date"/> | |
</pubDate> | |
</item> | |
</xsl:for-each> | |
</rss> | |
</xsl:template> | |
</xsl:stylesheet> | |
**Simple data file** | |
Now, we need some data to use with the template. | |
I've added a comment block so I can copy / paste it to add a new entry | |
into the | |
RSS easily. As the date is in a painful format to write for a human, I | |
added to | |
my Makefile starting the commands a call to a script replacing the | |
string DATE | |
by the current date with the correct format. | |
<feed> | |
<news> | |
<title>www/mozilla-firefox</title> | |
<description>Firefox 67.0.1</description> | |
<date>Wed, 05 Jun 2019 06:00:00 GMT</date> | |
</news> | |
<news> | |
<title></title> | |
<description></description> | |
<date></date> | |
</news> | |
--> | |
</feed> | |
**Makefile** | |
I love makefiles, so I share it even if this one is really short. | |
all: | |
sh replace_date.sh | |
xsltproc template.xml news.xml | xmllint -format - | tee | |
rss.xml | |
scp rss.xml perso.pw:/home/stable/ | |
rm rss.xml | |
When I want to add an entry, I copy / paste the comment block in | |
news.xml, add | |
DATE, run `make` and it's uploaded :) | |
The command **xsltproc** is available from the package **libxslt** on | |
OpenBSD. | |
And then, after writing this, I realise that manually editing the | |
result file | |
rss.xml is as much work as editing the news.xml file and then process | |
it with | |
xslt... But I keep that blog post as this can be useful for more | |
complicated | |
cases. :) |