-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathbuild.jl
96 lines (87 loc) · 2.98 KB
/
build.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
88
89
90
91
92
93
94
95
96
function PY()
if "PYTHON3" ∈ keys(ENV)
ENV["PYTHON3"]
else
if Sys.iswindows()
if "PYENV" ∈ keys(ENV)
return "python"
end
"py -3"
else
"python3"
end
end
end
function PIP()
if "PIP3" ∈ keys(ENV)
ENV["PIP3"]
else
if Sys.iswindows()
"py -3 -m pip"
else
"pip3"
end
end
end
function NODE()
if "NODE" ∈ keys(ENV)
ENV["NODE"]
else
NodeJS.nodejs_cmd()
end
end
# highligh.js library; can be overridden from the outside which is useful for testing
const HIGHLIGHTJS = Ref{String}("highlight.js")
shell_try(com)::Bool = try success(com); catch; false; end
#=
Pre-rendering
- In order to prerender KaTeX, the only thing that is required is `node` and then we can just
require `katex.min.js`
- For highlights, we need `node` and also to have the `highlight.js` installed via `npm`.
=#
function FD_CAN_PRERENDER()
r = shell_try(`$(NODE()) -v`)
if !r
@warn """Couldn't find node.js: `$(NODE()) -v` failed. Setting `prerender=false`.
Note: node is required for pre-rendering KaTeX and highlight.js, but it is not necessary to run Franklin (cf docs)."""
end
return r
end
let r = nothing # Hack to only run the checks once per call to Franklin.optimize since this is called multiple times
global function FD_CAN_HIGHLIGHT(; force::Bool=false)
if force || r === nothing
r = FD_CAN_PRERENDER() && shell_try(`$(NODE()) -e "require('$(HIGHLIGHTJS[])')"`)
if !r
@warn """Couldn't find highlight.js: `$(NODE()) -e "require('$(HIGHLIGHTJS[])')"` failed. Will not prerender code blocks.
Note: highlight.js is required for pre-rendering highlight.js, but is not necessary to run Franklin (cf docs)."""
end
end
return r
end
end
#=
Minification
- We use `css_html_js_minify`. To use it, you need python3 and to install it.
- Here we check there is python3, and pip3, and then if we fail to import, we try to
use pip3 to install it.
=#
function FD_HAS_PY3()
r = shell_try(`$([e for e in split(PY())]) -V`)
if !r
@warn """Couldn't find python3 (`$([e for e in split(PY())]) -V` failed). Will not minify.
Note: python3 is required for minification, but not necessary to run Franklin (cf docs)."""
end
return r
end
FD_HAS_PIP3() = shell_try(`$([e for e in split(PIP())]) -V`)
function FD_CAN_MINIFY()
r = FD_HAS_PY3() && FD_HAS_PIP3()
r || return r
r = (success(`$([e for e in split(PY())]) -c "import css_html_js_minify"`) ||
success(`$([e for e in split(PIP())]) install css_html_js_minify`))
if !r
@warn """Couldn't find css_html_js_minify (`$([e for e in split(PY())]) -m "import css_html_js_minify"` failed). Will not minify.
Note: css_html_js_minify is required for minification, but is not necessary to run Franklin (cf docs)."""
end
return r
end