feat: add RSS feed
This commit is contained in:
parent
6c9a87584e
commit
f1ecac288f
2 changed files with 73 additions and 0 deletions
72
src/feed.rss.cgt
Normal file
72
src/feed.rss.cgt
Normal file
|
@ -0,0 +1,72 @@
|
|||
<!
|
||||
local months = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
|
||||
}
|
||||
|
||||
-- Implementation of John Conway's Doomsday algorithm due to retarded date specs used in RSS
|
||||
-- Written in collaboration with stack overflow. Don't ask me WTF is going on here
|
||||
function dayOfWeek(gd, gm, gy)
|
||||
local d
|
||||
local by, a = 20, 0
|
||||
local y = { 6, 4, 2, 0 }
|
||||
local m = { 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 }
|
||||
local wd = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }
|
||||
|
||||
local ym = gy % 100
|
||||
local yp = math.floor(ym / 4)
|
||||
local ay = math.floor(gy / 100)
|
||||
|
||||
while ay ~= by do
|
||||
by = by + 1
|
||||
a = a + 1
|
||||
|
||||
if a == 4 then
|
||||
a = 0
|
||||
end
|
||||
end
|
||||
|
||||
if ym % 4 == 0 and gm == 2 then
|
||||
d = (gd + m[gm] + ym + yp + y[a + 1] - 1) % 7
|
||||
else
|
||||
d = (gd + m[gm] + ym + yp + y[a + 1]) % 7
|
||||
end
|
||||
|
||||
return wd[d + 1]
|
||||
end
|
||||
|
||||
function xmlEscape(s)
|
||||
local map = {
|
||||
["<"] = "<",
|
||||
[">"] = ">",
|
||||
["&"] = "&",
|
||||
}
|
||||
|
||||
return string.gsub(s, "(.)", function(c)
|
||||
return map[c] or c
|
||||
end)
|
||||
end
|
||||
!><?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>LordMZTE's Blog</title>
|
||||
<description>A Repository of a nerd's thoughts and oppinions</description>
|
||||
<link>https://mzte.de</link>
|
||||
<copyright>no lol</copyright>
|
||||
<generator>Confgen</generator>
|
||||
|
||||
<! for i = #opt.articles, 1, -1 do
|
||||
local a = opt.articles[i]
|
||||
local year_s, month_s, day_s = string.match(a.date, "(%d+)-(%d+)-(%d+)")
|
||||
local year, month, day = tonumber(year_s), tonumber(month_s), tonumber(day_s)
|
||||
!>
|
||||
<item>
|
||||
<title><% xmlEscape(a.title) %></title>
|
||||
<description><% xmlEscape(a.summary) %></description>
|
||||
<link>https://mzte.de/a/<% a.id %>/</link>
|
||||
<pubDate><% dayOfWeek(day, month, year) %>, <% day %> <% months[month] %> <% year %> 00:00:00 +0000</pubDate>
|
||||
<! -- TODO: set `category` field with tags !>
|
||||
</item>
|
||||
<! end !>
|
||||
</channel>
|
||||
</rss>
|
|
@ -48,6 +48,7 @@ If you want to chat, you can also reach me on matrix (`@lordmzte:mzte.de`).
|
|||
</div>
|
||||
|
||||
<h1>Articles</h1>
|
||||
<a href="/feed.rss">[RSS Feed]</a>
|
||||
<hr />
|
||||
<div id="articles">
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue