-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.jl
86 lines (79 loc) · 2.33 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using Dates
"""
{{blogposts}}
Plug in the list of blog posts contained in the `/blog/` folder.
"""
@delay function hfun_blogposts()
today = Dates.today()
curyear = year(today)
curmonth = month(today)
curday = day(today)
list = readdir("blog")
filter!(f -> endswith(f, ".md"), list)
sorter(p) = begin
ps = splitext(p)[1]
url = "/blog/$ps/"
surl = strip(url, '/')
pubdate = pagevar(surl, :published)
if isnothing(pubdate)
return Date(Dates.unix2datetime(stat(surl * ".md").ctime))
end
return Date(pubdate, dateformat"d U Y")
end
sort!(list, by=sorter, rev=true)
io = IOBuffer()
write(io, """<ul class="blog-posts">""")
for (i, post) in enumerate(list)
if post == "index.md"
continue
end
ps = splitext(post)[1]
write(io, "<li><span><i>")
url = "/blog/$ps/"
surl = strip(url, '/')
title = pagevar(surl, :title)
pubdate = pagevar(surl, :published)
if isnothing(pubdate)
date = "$curyear-$curmonth-$curday"
else
date = Date(pubdate, dateformat"d U Y")
end
write(io, """$date</i></span><a href="$url">$title</a>""")
end
write(io, "</ul>")
return String(take!(io))
end
"""
{{custom_taglist}}
Plug in the list of blog posts with the given tag
"""
function hfun_custom_taglist()::String
tag = locvar(:fd_tag)
rpaths = globvar("fd_tag_pages")[tag]
sorter(p) = begin
pubdate = pagevar(p, :published)
if isnothing(pubdate)
return Date(Dates.unix2datetime(stat(p * ".md").ctime))
end
return Date(pubdate, dateformat"d U Y")
end
sort!(rpaths, by=sorter, rev=true)
io = IOBuffer()
write(io, """<ul class="blog-posts">""")
# go over all paths
for rpath in rpaths
write(io, "<li><span><i>")
url = get_url(rpath)
title = pagevar(rpath, :title)
pubdate = pagevar(rpath, :published)
if isnothing(pubdate)
date = "$curyear-$curmonth-$curday"
else
date = Date(pubdate, dateformat"d U Y")
end
# write some appropriate HTML
write(io, """$date</i></span><a href="$url">$title</a>""")
end
write(io, "</ul>")
return String(take!(io))
end