diff options
author | Bradley Taunt <bt@btxx.org> | 2024-06-06 08:05:12 -0400 |
---|---|---|
committer | Bradley Taunt <bt@btxx.org> | 2024-06-06 08:05:12 -0400 |
commit | 6b742c459266b18e2b375b35205ce8a6c02f0452 (patch) | |
tree | b16fbb9a045e33dd6c97eb5ab72e6ff4d9237ea3 /build/rss-hacks |
Initial commit
Diffstat (limited to 'build/rss-hacks')
-rw-r--r-- | build/rss-hacks/index.html | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/build/rss-hacks/index.html b/build/rss-hacks/index.html new file mode 100644 index 0000000..232de44 --- /dev/null +++ b/build/rss-hacks/index.html @@ -0,0 +1,75 @@ +<!doctype html> +<html lang="en" id="top"> +<head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <link rel="icon" href="data:,"> + <title>RSS Hacks With XSLT</title> + <link href="https://bt.ht/atom.xml" type="application/atom+xml" rel="alternate" title="Atom feed for blog posts" /> + <style>*{box-sizing:border-box;}body{font-family:sans-serif;margin:0 auto;max-width:650px;padding:1rem;}img{max-width:100%;}pre{overflow:auto;}table{text-align:left;width:100%;}</style> +</head> + +<nav> + <a href="#menu">Menu ↓</a> +</nav> + +<main> +<h1>RSS Hacks With XSLT</h1> +<p>2022-05-23</p> +<p>In my spare time I've been further tinkering (hopefully for the better) with my humble Shinobi Website[^0] script. The most recent update in <code>patch-1</code> came with a solid amount of QoL improvements. If you're interested, I wrote about it on the official Shinobi blog[^1].</p> +<p>The next feature I wanted to tackle was designing a custom layout for the XML files directly in the browser. I was greatly inspired to create something similar to Len Falken's main directory listing[^2], since that blog was one of the original inspirations for Shinobi. I'm not able to copy what's there though, since our feed builds are quite a bit different.</p> +<p>I then proceeded to fall down the XSLT rabbit hole.</p> +<h2>It Never Works the First Time, Does It?</h2> +<p>Since the shinobi script generates valid RSS code by default, I didn't want to mess around <em>too</em> much via XSLT and risk breaking validation. I also wanted to keep the "plain text" look-and-feel for consistency with the rest of the site, even though the XSLT template would render into standard HTML. Minor CSS styling and placing the content directly inside <code>pre</code> tags solved these issues.</p> +<p>My first attempt was to use the available <code>sort</code> parameter (in XSL version 1.1+) targeting the <code>dc:date</code> type linked to the <code>pubDate</code> element:</p> +<pre><code><xsl:sort select="pubDate" data-type="dc:date" order="descending"/> +<!-- each individual post's content here --> +</code></pre> +<p>This did not work as intended. RSS 2.0 requires that the <code>pubDate</code> content is set to comply with the RFC-822 date-time[^3], which shinobi handles perfectly fine. The issue came from the XSL <code>sort</code> parameter not honoring this setting across all dates. My best guess is that it struggles to properly organize posts from their "month" parameter, so it sets the posts in order of date in what I refer to as "monthly sections".</p> +<p>If anyone knows why this failed to consistently order the posts via <code>pubDate</code>, please let me know using the comment link below. I'm far from an XSLT expert and might have overlooked something painfully obvious!</p> +<h2>RSS Hack: Categories</h2> +<p>After spending far too much time reading over documentation, official manual pages and Stack Overflow comments I gave up on the <code>dc:date</code> sort. I realized I could sort the posts much easier if they were converted into a format similar to ISO 8601. But <code>pubDate</code> is required to be in RFC-822, so I couldn't alter that in the final XML file.</p> +<p>Then I remembered the <code>category</code> tag which shinobi does not utilize by default.</p> +<p>First I needed to convert the RFC-822 formatted date (found on the first line of all blog post text files) and render it inside a <code>category</code> tag. This was simple enough:</p> +<pre><code>$(date -j -f "%a, %d %b %Y" "$(head -n 1 $file)" +"%Y/%m/%d/%u") +</code></pre> +<p>In a nutshell, this converts the RFC-822 date into the format "2022/05/24/2". Simple numbers that can be sorted much easier by XSL. Now all that was needed was setting to <code>sort</code> parameter properly:</p> +<pre><code><xsl:sort select="category" order="descending"/> +</code></pre> +<p>Everything worked perfectly and the RSS was still valid!</p> +<h3>Patch-2 Pending</h3> +<p>I've ported these changes over to this blog to perform some "in the wild" testing. You can see the custom feed list in your supported browser by visiting:</p> +<p><a href="https://pblog.bt.ht/feed.xml">https://pblog.bt.ht/feed.xml</a></p> +<p>As for the shinobi project itself, I have not merged these updates into the main master branch (at the time of publishing this article). They can be found sitting on patch-2[^4]. My plan is to get this merged ASAP once a little more real-world testing is finished and I can include a better "setup/install" section for newcomers.</p> +<h2>Shinobi Updates</h2> +<p>If you're interested in more updates and details about the shinobi project itself, feel free to sub to that specific feed below. This post was more focused on hacking RSS parameters that happened to involve shinobi, but in the future all updates specific to the project will be posted there:</p> +<p><a href="https://shinobi.bt.ht/feed.xml">https://shinobi.bt.ht/feed.xml</a></p> +<h2>Refs</h2> +<ol> +<li>https://shinobi.website/</li> +<li>https://shinobi.website/posts/patch-1.txt</li> +<li>http://len.falken.directory/</li> +<li>https://validator.w3.org/feed/docs/error/InvalidRFC2822Date.html</li> +<li>https://git.sr.ht/~tdarb/shinobi-script/tree/patch-2</li> +</ol> +<footer role="contentinfo"> + <h2>Menu Navigation</h2> + <ul id="menu"> + <li><a href="/">Home</a></li> + <li><a href="/projects">Projects</a></li> + <li><a href="/uses">Uses</a></li> + <li><a href="/wiki">Wiki</a></li> + <li><a href="/resume">Resume</a></li> + <li><a href="/colophon">Colophon</a></li> + <li><a href="/now">Now</a></li> + <li><a href="/donate">Donate</a></li> + <li><a href="/atom.xml">RSS</a></li> + <li><a href="#top">↑ Top of the page</a></li> + </ul> + <small> + Built with <a href="https://git.sr.ht/~bt/barf">barf</a>. <br> + Maintained with ♥ for the web. <br> + Proud supporter of <a href="https://usefathom.com/ref/DKHJVX">Fathom</a> & <a href="https://nextdns.io/?from=74d3p3h8">NextDNS</a>. <br> + The content for this site is <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>.<br> The <a href="https://git.sr.ht/~bt/bt.ht">code for this site</a> is <a href="https://git.sr.ht/~bt/bt.ht/tree/master/item/LICENSE">MIT</a>. + </small> +</footer>
\ No newline at end of file |