Rewrite RSS post feed to be generated
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
index_template = File.read!("./templates/post_index_page.html")
|
||||
post_template = File.read!("./templates/post_single_page.html")
|
||||
|
||||
post_feed_item_template = File.read!("./templates/post_item.xml")
|
||||
post_feed_template = File.read!("./templates/posts.xml")
|
||||
|
||||
post_contents = File.ls!("./posts")
|
||||
|> Enum.reject(fn(x) -> String.starts_with?(x, ".") end)
|
||||
|> Enum.map(fn f -> File.read!("./posts/" <> f) end)
|
||||
@@ -47,3 +50,20 @@ post_contents
|
||||
end))
|
||||
|> File.close()
|
||||
end)
|
||||
|
||||
post_feed = post_contents
|
||||
|> Enum.sort_by(fn m -> Map.get(m, :date) end)
|
||||
|> Enum.reverse()
|
||||
|> Enum.map(fn post ->
|
||||
Regex.compile!("{{(.*)}}") |>
|
||||
Regex.replace(post_feed_item_template, fn _, key -> Map.get(post, String.to_atom(key))
|
||||
end)
|
||||
end)
|
||||
|> Enum.join("\n")
|
||||
|> (fn items -> (Regex.compile!("{{items}}") |>
|
||||
Regex.replace(post_feed_template, fn _, __ -> items end))
|
||||
end).()
|
||||
|
||||
File.open!("./gen/rss.xml", [:write])
|
||||
|> IO.binwrite(post_feed)
|
||||
|> File.close()
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<item>
|
||||
<title>{{title}}</title>
|
||||
<link>https://raymon.dev/posts/{{id}}.html</link>
|
||||
<guid>https://raymon.dev/posts/{{id}}.html</guid>
|
||||
<description>
|
||||
<![CDATA[
|
||||
{{content}}
|
||||
]]>
|
||||
</description>
|
||||
<content type="html">
|
||||
{{content}}
|
||||
</content>
|
||||
<pubDate>{{date}}</pubDate>
|
||||
</item>
|
||||
@@ -26,7 +26,7 @@
|
||||
<article>
|
||||
<header>
|
||||
<h1>{{title}}</h1>
|
||||
<h3>For those using a RSS reader, subscribe here: <a href="/api/posts/rss.xml">rss.xml</a></h3>
|
||||
<h3>For those using a RSS reader, subscribe here: <a href="/posts/rss.xml">rss.xml</a></h3>
|
||||
</header>
|
||||
<time datetime="{{date}}"></time>
|
||||
{{content}}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<channel>
|
||||
<atom:link href="https://raymon.dev/api/posts/rss.xml" rel="self" type="application/rss+xml" />
|
||||
<title>Posts</title>
|
||||
<link>https://raymon.dev</link>
|
||||
<description>Personal blog</description>
|
||||
<language>en-us</language>
|
||||
|
||||
{{items}}
|
||||
</channel>
|
||||
</rss>
|
||||
Reference in New Issue
Block a user