-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
utils.jl
27 lines (26 loc) · 1.02 KB
/
utils.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using Dates
@delay function hfun_recentposts(params)
postdir = only(params)
list = readdir(postdir)
filter!(f -> endswith(f, ".md"), list)
dates = Vector{Date}(undef, length(list))
titles = Vector{String}(undef, length(list))
links = Vector{String}(undef, length(list))
for (i, file) in enumerate(list)
postname = splitext(basename(file))[1]
url = postdir * "/" * postname
pubdate = pagevar(url, :published)
dates[i] = isnothing(pubdate) ? Date(1999) : Date(pubdate, dateformat"d U Y")
titles[i] = something(pagevar(url, :title), "Post $i")
externallink = pagevar(url, :external)
links[i] = isnothing(externallink) ? ("../" * url * "/") : externallink
end
perm = sortperm(dates, rev=true)
io = IOBuffer()
for i in perm
write(io, """<p><a href="$(links[i])">$(titles[i])</a>""")
!isnothing(dates[i]) && write(io, " ($(monthname(dates[i])) $(year(dates[i])))")
write(io, "</p>\n")
end
return String(take!(io))
end