-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.jl
More file actions
79 lines (62 loc) · 1.72 KB
/
utils.jl
File metadata and controls
79 lines (62 loc) · 1.72 KB
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
using BibTeX
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_include(vname)
fname = vname[1]
try
return join(readlines(joinpath(@__DIR__, fname)), "\n")
catch e
return string(e)
end
end
function ref_item(ref, infos)
io = IOBuffer()
author = infos["author"]
author_list = split(author, " and ")
write(io, "<li id=\"#$ref\">")
for entry in author_list
splitted = split(entry, ",")
if length(splitted) == 1
write(io, "$(splitted[1]), ")
else
last, first = strip.(splitted)
write(io, "$first $last, ")
end
end
if haskey(infos, "date")
date = infos["date"]
elseif haskey(infos, "year")
date = infos["year"]
else
error("Date for key for $author not defined")
end
title = infos["title"]
title = replace(title, "{"=>"", "}"=>"")
write(io, """<span style="font-style:italic;">$title</span>, $date.""")
write(io, "</li>")
return String(take!(io))
end
function hfun_cite(refs)
_, allrefs = parse_bibtex(read(joinpath("_assets", "peacefounder.bib"), String))
out = IOBuffer()
write(out, "<ul style=\"margin-left:1rem;\">")
for ref in refs
infos = get(allrefs, ref, nothing)
isnothing(infos) && continue
write(out, ref_item(ref, infos))
end
write(out, "</ul>")
return String(take!(out))
end