-
Notifications
You must be signed in to change notification settings - Fork 19
/
deploy.jl
71 lines (52 loc) · 2.56 KB
/
deploy.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
# this runs in your environment and assumes that all your scripts are up to date etc.
# do not run this if you have not previously run `serve()` and checked everything was fine.
Pkg.activate()
using Franklin, Pkg, Logging, Literate
##################################################################
## PART 1: generate all scripts and notebooks and push everything
# on the gh-pages branch (yes we're abusing the system)
##################################################################
Logging.disable_logging(Logging.LogLevel(1500))
scripts = readdir("_literate")
filter!(e -> endswith(e, ".jl"), scripts)
ifiles = joinpath.("_literate", scripts)
nbpath = joinpath("__site", "generated", "notebooks")
scpath = joinpath("__site", "generated", "scripts")
isdir(nbpath) || mkpath(nbpath)
isdir(scpath) || mkpath(scpath)
ACTIVATE = """
# Before running this, please make sure to activate and instantiate the environment
# corresponding to [this `Project.toml`](https://raw.githubusercontent.com/alan-turing-institute/MLJTutorials/master/Project.toml) and [this `Manifest.toml`](https://raw.githubusercontent.com/alan-turing-institute/MLJTutorials/master/Manifest.toml)
# so that you get an environment which matches the one used to generate the tutorials:
#
# ```julia
# cd("MLJTutorials") # cd to folder with the *.toml
# using Pkg; Pkg.activate("."); Pkg.instantiate()
# ```
"""
preproc(s) = ACTIVATE * s
# Remove lines that end with `# hide`
postproc(s) = replace(s, r"(^|\n).*?#(\s)*?(?i)hide(?:all)?"=>s"\1")
# =============================================================================
get_fn(fp) = splitext(splitdir(fp)[2])[1]
for file in ifiles
# Generate annotated notebooks
Literate.notebook(file, nbpath,
preprocess=preproc, postprocess=postproc,
execute=false, documenter=false)
# Generate annotated scripts
Literate.script(file, scpath,
postprocess=preproc ∘ postproc,
keep_comments=true, documenter=false)
# Generate stripped scripts (no comments)
Literate.script(file, scpath, name=get_fn(file)*"-raw",
postprocess=preproc ∘ postproc,
keep_comments=false, documenter=false)
end
##################################################################
## PART 2
# optimize (compress and pre-render) the website and publish it
# to the master branch this time.
##################################################################
commit = (@isdefined commit) ? commit : "fd-update"
publish(message=commit, final=lunr)