-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.jl
68 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
62
63
64
65
66
67
68
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
function hfun_recent_posts(m::Vector{String})
@assert length(m) == 1 "only one argument allowed for recent posts (the number of recent posts to pull)"
n = parse(Int64, m[1])
list = readdir("posts")
filter!(f -> endswith(f, ".md") && f != "index.md", list)
posts = []
df = DateFormat("mm/dd/yyyy")
for (k, post) in enumerate(list)
fi = "posts/" * splitext(post)[1]
title = pagevar(fi, :title)
datestr = pagevar(fi, :date)
date = Date(pagevar(fi, :date), df)
push!(posts, (title=title, link=fi, date=date))
end
markdown = "Dict{Date, String} with " *
string(n >= 0 ? n : length(posts)) *
" entrys:\n\n"
# pull all posts if n <= 0
n = n >= 0 ? n : length(posts) + 1
for ele in sort(posts, by=x -> x.date, rev=true)[1:min(length(posts), n)]
markdown *= "[$(ele.date) => \"$(ele.title)](../$(ele.link))\"\n\n"
end
return fd2html(markdown, internal=true)
end
function hfun_add_bsky_comments(post_url::Vector{String})
post = post_url[1]
html = "
<script src=\"../bsky-comments.js\"></script>
<bsky-comments post=\"$(post)\"></bsky-comments>
"
return html
end
@delay function hfun_all_posts()
return hfun_recent_posts(["-1"])
end
@delay function hfun_tag_landing_page()
PAGE_TAGS = Franklin.globvar("fd_page_tags")
TAG_COUNT = Franklin.invert_dict(PAGE_TAGS)
markdown = ""
for k in sort(collect(keys(TAG_COUNT)))
markdown *= "* [" * k * "](" * Franklin.joinpath("/tags/", k) * ") (" * string(length(TAG_COUNT[k])) * ")\n"
end
return fd2html(markdown, internal=true)
end