-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.jl
49 lines (42 loc) · 1.17 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
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
"""
lx_pluto(com, _)
Embed a Pluto notebook via:
https://github.com/rikhuijzer/PlutoStaticHTML.jl
"""
function lx_pluto(com, _)
file = string(Franklin.content(com.braces[1]))::String
notebook_path = joinpath("posts", "notebooks", "$file.jl")
log_path = joinpath("posts", "notebooks", "$file.log")
return """
```julia:pluto
# hideall
using PlutoStaticHTML: notebook2html
path = "$notebook_path"
log_path = "$log_path"
@assert isfile(path)
@info "→ evaluating Pluto notebook at (\$path)"
html = open(log_path, "w") do io
redirect_stdout(io) do
html = notebook2html(path)
return html
end
end
println("~~~\n\$html\n~~~\n")
```
\\textoutput{pluto}
"""
end