4 ms·
Simple script to generate RSS feeds
- Fred34 3y agoThis is one of the first bash scripts I've written. What do you guys think?
- rvense 3y agoIt's cool, nice work! And thank you for sharing it. This is just spitballing, you've already solved problem you set out to and get full marks. There are always many different ways to do things with bash/shell. Here, you could probably do the entire thing in AWK, which you seem to already be aware of. This might be more readable or it might not. If this were a script someone wrote for more general usage, I'd recommend to use the unofficial "bash strict mode"[0], and make sure to check that the awk/sed calls succeed. Shell has a nasty habit of limping along as far as it can if something goes wrong along the way and it's very easy to just end up with bad output and not notice until it's too late. Another thing I only recently discovered is envsubst, a tool that's commonly available and tailor-made for substituting variables. You could pipe a template string or pile into that instead of the repetitive calls to echo. What you have here is fine and instantly readable, but if it were three times as long it might not be so nice. Here you could use awk to extract the variables and envsubst to put them into your template. Honestly I don't think shell is a good language for writing perfect, robust things anyway. But it's good for exactly what you're doing, though, writing something for yourself that solves a problem without spending too much time on it (although it's fine to spend a lot of time on it if you're learning and/or just enjoying yourself). [0] http://redsymbol.net/articles/unofficial-bash-strict-mode/ http://redsymbol.net/articles/unofficial-bash-strict-mode/
- Fred34 3y agoThanks for the feedback. I haven't heard of "bash strict mode" before. Haven't heard of envsubst either. I'll make a better rss script as I learn more about scripting.
- EmilStenstrom 3y agoSome feedback: Did you consider what happens if the blog post contains the string "]]>"? I think that probably needs to be escaped to avoid problems?
- LorenDB 3y agoFor anybody using Hugo, you also may be interested in https://lorendb.dev/posts/fixing-hugos-rss-feed/ https://lorendb.dev/posts/fixing-hugos-rss-feed/ in which I fix Hugo's feed template to have the entire article as well as a few other niceties.
- Fred34 3y agoLearning hugo is on my bucket list. Has things like tagging which would be a pain to do with a hand coded website. I got a parsing error when trying to add the rss feed on your website to Thunderbird. Line Number 19, Column 7.
- LorenDB 3y agoHm, maybe it's the `<dc:creator>` tag causing the issue. Can you check to see if https://web.archive.org/web/20231225135859/https://lorendb.dev/index.xml https://web.archive.org/web/20231225135859/https://lorendb.d... has the same problem? (this is an archive from before I added the `<dc:creator>` tag) Edit: that doesn't seem to be importable. Give me a minute and I'll check manually. Edit 2: I am unable to figure out a fix to the problem, sorry! My feed works fine for me in Tiny Tiny RSS, so I am tempted to say that it's caused by a very strict feed parser.
- Fred34 3y agohttps://validator.w3.org/feed/check.cgi?url=https%3A%2F%2Florendb.dev%2Findex.xml https://validator.w3.org/feed/check.cgi?url=https%3A%2F%2Flo... My rss feeder that I use on my phone works with your site. Maybe it's only Thunderbird that refuses to parse it.
- LorenDB 3y agoOK, I found the problem. I hadn't imported the proper RSS namespace thingy to provide the `<dc:creator>` tag. I've fixed that now, so you should be able to read my feed in Thunderbird!
- surprisetalk 3y agoRelated: I recently wrote an SQL query to generate podcast RSS: https://taylor.town/xml-sql https://taylor.town/xml-sql Postgres XML functions are ugly, but make this kind of stuff very easy
- deleted 3y ago[deleted]
- politelemon 3y agoIf you're using eleventy, you should be able to just add the RSS plugin: https://www.11ty.dev/docs/plugins/rss/ https://www.11ty.dev/docs/plugins/rss/ and easily configure it. If you're using a theme then check to see if it already bundles this.
- Fred34 3y agoI'm not using a static-site generator yet. I probably should however.