diff options
Diffstat (limited to 'build/rss-hacks/index.html')
-rw-r--r-- | build/rss-hacks/index.html | 30 |
1 files changed, 2 insertions, 28 deletions
diff --git a/build/rss-hacks/index.html b/build/rss-hacks/index.html index d6d4ef5..ee6fdcd 100644 --- a/build/rss-hacks/index.html +++ b/build/rss-hacks/index.html @@ -3,11 +3,12 @@ <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> + <meta name="color-scheme" content="dark light"> <link rel="icon" href="data:,"> <title>RSS Hacks With XSLT</title> <link href="/atom.xml" type="application/atom+xml" rel="alternate" title="Atom feed for blog posts" /> <link href="/rss.xml" type="application/rss+xml" rel="alternate" title="RSS feed for blog posts" /> -<style>*{box-sizing:border-box;}body{font-family:sans-serif;line-height:1.33;margin:0 auto;max-width:650px;padding:1rem;}img{max-width:100%;}pre{border:1px solid;overflow:auto;padding:5px;}table{text-align:left;width:100%;}.footnotes{font-size:90%;}</style> +<style>*{box-sizing:border-box;}body{font-family:sans-serif;line-height:1.33;margin:0 auto;max-width:650px;padding:1rem;}blockquote{background:rgba(0,0,0,0.1);border-left:4px solid;padding-left:5px;}img{max-width:100%;}pre{border:1px solid;overflow:auto;padding:5px;}table{text-align:left;width:100%;}.footnotes{font-size:90%;}</style> </head> <nav> @@ -16,63 +17,36 @@ <main> <h1 id="rss-hacks-with-xslt">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 id="it-never-works-the-first-time-does-it">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 id="rss-hack-categories">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 id="patch-2-pending">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 id="shinobi-updates">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 id="refs">Refs</h2> - <ol> <li><a href="https://shinobi.website/">https://shinobi.website/</a></li> <li><a href="https://shinobi.website/posts/patch-1.txt">https://shinobi.website/posts/patch-1.txt</a></li> |