blog Home | Posts | RSS

Adding an RSS feed to a static site, 2022 edition

When I tried to add this blog to Feedly, it asked me to enter the RSS Feed URL. Automatically generating the RSS feed required a paid subscription of Feedly. So I decided to write some code of generating the RSS Feed by myself. I had to write some snippets of Elixir code for Lambdapad, and it worked OK in the end. It's another good way to learn Elixir!

Here's some excerpts from lambdapad.exs:

config do
    set transform: fn(config) ->
      currentdatetime = 
          DateTime.utc_now() |> 
              Map.replace(:microsecond, {0, 0}) |>
      Map.put(config, "builddatetime", currentdatetime)
         |> Map.put("site_root", config["blog"]["url"])
pages "rss" do
    set from: :posts
    set template: "rss.xml"
    set uri: "/rss.xml"
    set index: true
    set var_name: "posts"
    set uri_type: :file
    set priority: :low

And here's the template of rss.xml:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <title>{{ blog.title }}</title>
  <description>{{ blog.description }}</description>
  <link>{{ site_root }}index.html</link>
  <lastBuildDate>{{ builddatetime }}</lastBuildDate>

{% for post in posts %}
    <title>{{ post.title }}</title>
    <description>{{ post.summary }}</description>
    <link>{{ site_root }}posts/{{}}</link>
    <guid>{{ site_root }}posts/{{}}</guid>
    <pubDate>{{ }}</pubDate>
{% endfor %}


These snippets are applicable for the Lambdapad blog example.