clone url: git://


1 <!DOCTYPE html>
2 <html xmlns="" lang="en" xml:lang="en">
3 <head>
4 <meta charset="utf-8" />
5 <meta name="generator" content="pandoc" />
6 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
7 <title>Adding date support to my awful RSS feed generator</title>
8 <style>
9 code{white-space: pre-wrap;}
10 span.smallcaps{font-variant: small-caps;}
11 span.underline{text-decoration: underline;}
12 div.column{display: inline-block; vertical-align: top; width: 50%;}
13 div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
14 ul.task-list{list-style: none;}
15 </style>
16 <link rel="stylesheet" href="/assets/archive.css">
17 </head>
18 <body>
19 <main>
20 <h2 id="adding-date-support-to-my-awful-rss-feed-generator">Adding date support to my awful RSS feed generator</h2>
21 <p>2020-10-27 00:00</p>
22 <p>So, someone asked “when are you going to add dates to your RSS feed?”, and I replied “I’m not actually sure!”. I wasn’t sure, because my original goal was to create a bare-minimum, valid RSS feed, which <a href="">doesn’t actually require dates</a>.</p>
23 <p>This went well and all, but it kind of messes with people’s RSS feed readers because it doesn’t know how to order them, so it adds dates in for them, which are all just the same date.</p>
24 <p>I created this generator so friends could keep up with my blog posts, so it kind of made sense to me that they should be able to view them in chronological order in their RSS feed reader haha.</p>
25 <p>Tonight I set out to do that, and, since my RSS-feed generator was already a mess, I had a lot of fun with this, because I didn’t need to worry about ruining nicely organized code.</p>
26 <p>I wasn’t sure how I was going to do it, because I was basically generating links and titles in the RSS feed based off the <code></code> file, which consisted of a bunch of <code>* [I'm a title](</code>s, and just parsed those into RSS-style XML for the <code>&lt;title&gt;</code>, <code>&lt;link&gt;</code>, and <code>&lt;guid&gt;</code>. The problem was that there was no date for me to pull from there!</p>
27 <p>I realized I was keeping dates in all of my posts, and that I could just take the link my crappy parser found, remove the initial <code>/</code> from it, and it could open the file, split it into lines, grab the third line, which was the date, and plop it into the RSS!</p>
28 <p>It took a few tries, some referencing of <a href="https://%7B%7Bgit-domain%7D%7D/ruth">an IRC bot I made</a> to get the output of a shell command from racket, but in the end, I managed to do it!</p>
29 <p>I ended up using an awful nested list of functions, because, why not? The code is already awful, why not have more fun and keep it that way?</p>
30 <p>The result? This super awful function, and I love it!:</p>
31 <pre><code>(define (listof-rss-items-&gt;rss-items-string listof-rss-items)
32 (format &quot;~a&quot; (string-join listof-rss-items)))
34 (define (create-item l)
35 (let* ([post-title (car l)]
36 [link-fragment (car (cdr l))] ;; /posts/some-name.html
37 [date (car
38 (cdr
39 (cdr
40 (file-&gt;lines
41 (string-replace (string-replace link-fragment &quot;.html&quot; &quot;.md&quot;)
42 &quot;/posts/&quot;
43 &quot;posts/&quot;)))))] ;; creates &quot;yyyy-mm-dd&quot;
44 [date-converted (string-trim
45 (with-output-to-string
46 (lambda () (system (format &quot;date -Rd&#39;~a&#39;&quot; date)))))] ;; creates &quot;Day, Mon 31 00:00:00 EDT 2020&quot;
47 [link-full (string-append homepage-url link-fragment)])
48 (format
49 #&lt;&lt;string-block
51 &lt;item&gt;
52 &lt;title&gt;~a&lt;/title&gt;
53 &lt;link&gt;~a&lt;/link&gt;
54 &lt;guid&gt;~a&lt;/guid&gt;
55 &lt;pubDate&gt;~a&lt;/pubDate&gt;
56 &lt;/item&gt;
58 string-block
59 post-title
60 link-full
61 link-full
62 date-converted)))</code></pre>
63 <p>P.S. If you are following my RSS feed, to get it to regenerate with dates, you might need to delete my feed and reload it. I know I had to do this with Thunderbird while I was testing my feed.</p>
64 </main>
65 </body>
66 </html>