-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathutils.jl
87 lines (80 loc) · 2.79 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
87
using Dates
"""
{{news}}
Plug in the list of news contained in the `/news/` folder.
"""
function hfun_news()
author_badges = globvar("author_badges")
# Changing page width in "News" section
io = IOBuffer()
write(io, """<style>
@media (min-width: 1024px) {
.franklin-content {
width: 100%;
padding-left: 0%;
padding-right: 0%;
}
}
</style>""")
# Add news
curyear = year(Dates.today())
write(io, """<div class="news-container">""")
for year in curyear:-1:2022
ys = "$year"
year < curyear
for month in 12:-1:1
ms = "0"^(month < 10) * "$month"
base = joinpath("news", 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 = "/news/$ys/$ms/$ps/"
surl = strip(url, '/')
post_title = pagevar(surl, :post_title)
short_descr = pagevar(surl, :short_descr)
post_author = pagevar(surl, :post_author)
width = rand(250:290)
pubdate = pagevar(surl, :published)
if isnothing(pubdate)
date = "$ys-$ms-01"
days[i] = 1
else
date = Date(pubdate, dateformat"d U Y")
days[i] = day(date)
end
lines[i] = """"""
lines[i] *= """<div class="news-block" style="width:$(width)px;margin:-5px;">"""
lines[i] *= """<a href="$url">$post_title</a> $date<br>"""
lines[i] *= """<p>$short_descr</p>"""
lines[i] *= """$post_author"""
for b in author_badges[post_author]
lines[i] *= """<img src="/assets/$b.png"/>"""
end
lines[i] *= """</div>"""
end
# sort by day
foreach(line -> write(io, line), lines[sortperm(days, rev=false)])
end
end
write(io, """</div>""")
return String(take!(io))
end
"""
{{ addcomments }}
Add a comment widget, managed by utterances <https://utteranc.es>.
"""
function hfun_addcomments()
html_str = """
<script src="https://utteranc.es/client.js"
repo="JuliaParallel/juliaparallel.github.io"
issue-term="pathname"
theme="github-light"
crossorigin="anonymous"
async>
</script>
"""
return html_str
end