-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.jl
62 lines (58 loc) · 1.98 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function hfun_bar(vname)
val = Meta.parse(vname[1])
return round(sqrt(val), digits=2)
end
function hfun_m1fill(vname)
var = vname[1]
return pagevar("index", var)
end
function lx_baz(com, _)
# keep this first line
brace_content = Franklin.content(com.braces[1]) # input string
# do whatever you want here
return uppercase(brace_content)
end
"""
{{blogposts}}
Plug in the list of blog posts contained in the `/blog/` folder.
Taken from the JuliaLang site utils.jl
"""
function hfun_blogposts()
curyear = year(Dates.today())
io = IOBuffer()
for year in curyear:-1:2023
ys = "$year"
year < curyear && write(io, "\n**$year**\n")
for month in 12:-1:1
ms = "0"^(month < 10) * "$month"
base = joinpath("requietis", ys, ms)
isdir(base) || continue
posts = filter!(p -> endswith(p, ".md"), readdir(base))
days = zeros(Int, length(posts))
lines = Vector{String}(undef, length(posts))
for (i, post) in enumerate(posts)
ps = splitext(post)[1]
url = "/requietis/$ys/$ms/$ps/"
surl = strip(url, '/')
title = pagevar(surl, :title)
desc = pagevar(surl, :rss_description)
title === nothing && (title = "Untitled")
pubdate = pagevar(surl, :published)
if isnothing(pubdate)
date = "($ms/$ys)"
days[i] = 1
else
date = Date(pubdate, dateformat"d U Y")
days[i] = day(date)
end
lines[i] = "\n$date [$title]($url) : $desc\n"
end
# sort by day
foreach(line -> write(io, line), lines[sortperm(days, rev=true)])
end
end
# markdown conversion adds `<p>` beginning and end but
# we want to avoid this to avoid an empty separator
r = Franklin.fd2html(String(take!(io)), internal=true)
return r
end