-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.jl
66 lines (61 loc) · 1.83 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
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 `/posts` folder.
Souce: <https://github.com/abhishalya/abhishalya.github.io>.
"""
function hfun_blogposts()
today = Dates.today()
curyear = year(today)
curmonth = month(today)
curday = day(today)
list = readdir("posts")
filter!(endswith(".md"), list)
function sorter(p)
ps = splitext(p)[1]
url = "/posts/$ps/"
surl = strip(url, '/')
pubdate = pagevar(surl, :published)
if isnothing(pubdate)
return Date(Dates.unix2datetime(stat(surl * ".md").ctime))
end
return Date(pubdate, dateformat"yyyy-mm-dd")
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 = "/posts/$ps/"
surl = strip(url, '/')
title = pagevar(surl, :title)
pubdate = pagevar(surl, :published)
description = pagevar(surl, :rss_description)
if isnothing(pubdate)
date = "$curyear-$curmonth-$curday"
else
date = Date(pubdate, dateformat"yyyy-mm-dd")
end
write(io, """$date</i></span><b><a href="$url">$title</a></b>""")
write(io, """<li><i class="description">$description</i></li>""")
end
write(io, "</ul>")
return String(take!(io))
end