Skip to content

Commit eaab6fc

Browse files
authored
Merge pull request #11 from JuliaComputing/sp/release-ready
Get this ready for release
2 parents f404ebf + 10770c9 commit eaab6fc

File tree

9 files changed

+184
-74
lines changed

9 files changed

+184
-74
lines changed

.github/workflows/CI.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: CI
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
tags: '*'
8+
jobs:
9+
test:
10+
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
version:
16+
- '1.6'
17+
- '1.8'
18+
os:
19+
- ubuntu-latest
20+
arch:
21+
- x64
22+
env:
23+
PYTHON: ""
24+
steps:
25+
- uses: actions/checkout@v2
26+
- uses: julia-actions/setup-julia@v1
27+
with:
28+
version: ${{ matrix.version }}
29+
arch: ${{ matrix.arch }}
30+
- uses: actions/cache@v1
31+
env:
32+
cache-name: cache-artifacts
33+
with:
34+
path: ~/.julia/artifacts
35+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
36+
restore-keys: |
37+
${{ runner.os }}-test-${{ env.cache-name }}-
38+
${{ runner.os }}-test-
39+
${{ runner.os }}-
40+
- uses: julia-actions/julia-buildpkg@v1
41+
- uses: julia-actions/julia-runtest@v1

Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ version = "0.1.0"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
8-
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
98
Gumbo = "708ec375-b3d6-5a57-a7ce-8257bf98657a"
109
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
1110
NodeJS = "2bd173c7-0d6d-553b-b6af-13a54713934c"
1211
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1312

1413
[compat]
1514
AbstractTrees = "0.4"
16-
Documenter = "0.27"
1715
Gumbo = "0.8"
1816
JSON = "0.20,0.21"
1917
NodeJS = "1"

README.md

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,34 @@ Example usage:
44
```julia
55
using MultiDocumenter
66

7+
clonedir = mktempdir()
8+
79
docs = [
8-
MultiDocumenter.MultiDocRef(
9-
upstream = "/home/pfitzseb/.julia/dev/Documenter/docs/build",
10-
path = "documenter",
11-
name = "Home"
10+
("JuliaDocs/Documenter.jl.git", "gh-pages") => MultiDocumenter.MultiDocRef(
11+
upstream = joinpath(clonedir, "Documenter"),
12+
path = "doc",
13+
name = "Documenter"
1214
),
13-
MultiDocumenter.MultiDocRef(
14-
upstream = "/home/pfitzseb/.julia/dev/Infiltrator/docs/build",
15-
path = "infil",
15+
("JuliaDebug/Infiltrator.jl.git", "gh-pages") => MultiDocumenter.MultiDocRef(
16+
upstream = joinpath(clonedir, "Infiltrator"),
17+
path = "inf",
1618
name = "Infiltrator"
17-
)
19+
),
1820
]
1921

22+
for ((remote, branch), docref) in docs
23+
run(`git clone --depth 1 [email protected]:$remote --branch $branch --single-branch $(docref.upstream)`)
24+
end
25+
26+
outpath = joinpath(@__DIR__, "out")
27+
2028
MultiDocumenter.make(
21-
joinpath(@__DIR__, "out"),
22-
docs;
23-
assets_dir = joinpath(@__DIR__, "assets"),
24-
brand_image = MultiDocumenter.BrandImage(
25-
"documenter/index.html",
26-
"assets/brandimg.svg"
27-
),
28-
custom_stylesheets = [
29-
"assets/custom.css",
30-
"assets/fonts/fonts.css",
31-
]
29+
outpath,
30+
collect(last.(docs));
31+
search_engine = MultiDocumenter.SearchConfig(
32+
index_versions = ["stable"],
33+
engine = MultiDocumenter.FlexSearch
34+
)
3235
)
3336
```
3437

sample.png

19.6 KB
Loading

src/MultiDocumenter.jl

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module MultiDocumenter
22

3-
import Documenter, Gumbo, AbstractTrees
4-
5-
include("search/flexsearch.jl")
6-
include("search/stork.jl")
3+
import Gumbo, AbstractTrees
74

85
"""
96
SearchConfig(index_versions = ["stable"], engine = MultiDocumenter.FlexSearch)
107
8+
`index_versions` is a vector of relative paths used for generating the search index.
9+
`engine` may be `MultiDocumenter.FlexSearch`, `MultiDocumenter.Stork`, or a module that conforms
10+
to the expected API.
1111
"""
1212
Base.@kwdef mutable struct SearchConfig
1313
index_versions = ["stable"]
@@ -30,6 +30,28 @@ function MultiDocRef(; upstream, name, path)
3030
MultiDocRef(upstream, path, name)
3131
end
3232

33+
function walk_outputs(f, root, docs::Vector{MultiDocRef}, dirs::Vector{String})
34+
for ref in docs
35+
p = joinpath(root, ref.path)
36+
for dir in dirs
37+
dirpath = joinpath(p, dir)
38+
isdir(dirpath) || continue
39+
for (r, _, files) in walkdir(dirpath)
40+
for file in files
41+
file == "index.html" || continue
42+
43+
f(chop(r, head = length(root), tail = 0), joinpath(r, file))
44+
end
45+
end
46+
end
47+
end
48+
end
49+
50+
include("search/flexsearch.jl")
51+
include("search/stork.jl")
52+
53+
const DEFAULT_ENGINE = SearchConfig(index_versions = ["stable"], engine = FlexSearch)
54+
3355
"""
3456
make(
3557
outdir,
@@ -49,7 +71,7 @@ Aggregates multiple Documenter.jl-based documentation pages `docs` into `outdir`
4971
item in the global navigation
5072
- `custom_stylesheets` is a `Vector{String}` of stylesheets injected into each page.
5173
- `custom_scripts` is a `Vector{String}` of scripts injected into each page.
52-
- `search_engine` inserts a global search bar. See [`SearchConfig`](@ref) for more details.
74+
- `search_engine` inserts a global search bar if not `false`. See [`SearchConfig`](@ref) for more details.
5375
- `prettyurls` removes all `index.html` suffixes from links in the global navigation.
5476
"""
5577
function make(
@@ -59,7 +81,7 @@ function make(
5981
brand_image::Union{Nothing,BrandImage} = nothing,
6082
custom_stylesheets = [],
6183
custom_scripts = [],
62-
search_engine = SearchConfig(index_versions = ["stable"], engine = FlexSearch),
84+
search_engine = DEFAULT_ENGINE,
6385
prettyurls = true
6486
)
6587

@@ -71,6 +93,13 @@ function make(
7193
isdir(out_assets) || mkpath(out_assets)
7294
cp(joinpath(@__DIR__, "..", "assets", "__default"), joinpath(out_assets, "__default"))
7395

96+
if search_engine != false
97+
if search_engine.engine == Stork && !Stork.has_stork()
98+
@warn "stork binary not found. Falling back to flexsearch as search_engine."
99+
search_engine = DEFAULT_ENGINE
100+
end
101+
end
102+
74103
inject_styles_and_global_navigation(
75104
dir,
76105
docs,
@@ -82,7 +111,7 @@ function make(
82111
)
83112

84113
if search_engine != false
85-
search_engine.engine.build_search_index(dir, search_engine)
114+
search_engine.engine.build_search_index(dir, docs, search_engine)
86115
end
87116

88117
cp(dir, outdir; force = true)
@@ -215,10 +244,11 @@ function js_injector()
215244
return read(joinpath(@__DIR__, "..", "assets", "multidoc_injector.js"), String)
216245
end
217246

247+
218248
function inject_styles_and_global_navigation(
219249
dir,
220250
docs::Vector{MultiDocRef},
221-
brand_image::BrandImage,
251+
brand_image,
222252
custom_stylesheets,
223253
custom_scripts,
224254
search_engine,
@@ -240,8 +270,6 @@ function inject_styles_and_global_navigation(
240270
end
241271
continue
242272
end
243-
# no need to do anything about /index.html
244-
path == joinpath(dir, "index.html") && continue
245273

246274
endswith(file, ".html") || continue
247275

@@ -251,7 +279,11 @@ function inject_styles_and_global_navigation(
251279
stylesheets = make_global_stylesheet(custom_stylesheets, relpath(dir, root))
252280
scripts = make_global_scripts(custom_scripts, relpath(dir, root))
253281

282+
254283
page = read(path, String)
284+
if startswith(page, "<!--This file is automatically generated by Documenter.jl-->")
285+
continue
286+
end
255287
doc = Gumbo.parsehtml(page)
256288
injected = 0
257289

@@ -273,16 +305,15 @@ function inject_styles_and_global_navigation(
273305
documenter_div = first(el.children)
274306
if documenter_div isa Gumbo.HTMLElement &&
275307
Gumbo.getattr(documenter_div, "id", "") == "documenter"
276-
# inject global navigation as first element in body
277-
278-
global_nav =
279-
make_global_nav(dir, docs, root, brand_image, search_engine, prettyurls)
280-
global_nav.parent = el
281-
pushfirst!(el.children, global_nav)
282-
injected += 1
283-
else
284-
@warn "Could not inject global nav into $path."
308+
@debug "Could not detect Documenter page layout in $path. This may be due to an old version of Documenter."
285309
end
310+
# inject global navigation as first element in body
311+
312+
global_nav =
313+
make_global_nav(dir, docs, root, brand_image, search_engine, prettyurls)
314+
global_nav.parent = el
315+
pushfirst!(el.children, global_nav)
316+
injected += 1
286317
end
287318
end
288319
end

src/search/flexsearch.jl

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module FlexSearch
22
import Gumbo, JSON, AbstractTrees, NodeJS
3+
import ..walk_outputs
34

45
const ID = Ref(0)
56

@@ -61,7 +62,7 @@ function add_fragment(doc, el)
6162
end
6263
end
6364

64-
function add_to_index(index, ref, file)
65+
function add_to_index!(index, ref, file)
6566
content = read(file, String)
6667
html = Gumbo.parsehtml(content)
6768

@@ -82,22 +83,12 @@ function add_to_index(index, ref, file)
8283
push!(index.documents, doc)
8384
end
8485

85-
function generate_index(root, config)
86+
function generate_index(root, docs, config)
8687
search_index = SearchIndex()
87-
for (r, _, files) in walkdir(root)
88-
pathparts = splitpath(relpath(r, root))
89-
if length(pathparts) >= 2 && pathparts[2] in config.index_versions
90-
for file in files
91-
if file == "index.html"
92-
add_to_index(
93-
search_index,
94-
chop(r, head = length(root), tail = 0),
95-
joinpath(r, file),
96-
)
97-
end
98-
end
99-
end
88+
walk_outputs(root, docs, config.index_versions) do path, file
89+
add_to_index!(search_index, path, file)
10090
end
91+
10192
return search_index
10293
end
10394

@@ -160,9 +151,9 @@ function to_json_index(index::SearchIndex, file)
160151
end
161152
end
162153

163-
function build_search_index(root, config)
154+
function build_search_index(root, docs, config)
164155
ID[] = 0
165-
idx = generate_index(root, config)
156+
idx = generate_index(root, docs, config)
166157
to_json_index(idx, joinpath(root, "index.json"))
167158
println("Writing flexsearch index:")
168159
cd(root) do

src/search/stork.jl

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
module Stork
22
import Pkg.TOML
33
import Gumbo, AbstractTrees
4+
import ..walk_outputs
45

5-
function build_search_index(root, config)
6-
config = make_stork_config(root, config)
6+
function has_stork()
7+
has_stork = false
8+
try
9+
has_stork = success(`stork -V`)
10+
catch
11+
has_stork = false
12+
end
13+
return has_stork
14+
end
15+
16+
function build_search_index(root, docs, config)
17+
config = make_stork_config(root, docs, config)
718
config_path = joinpath(root, "stork.config.toml")
819
index_path = joinpath(root, "stork.st")
920
open(config_path, "w") do io
@@ -13,7 +24,7 @@ function build_search_index(root, config)
1324
return index_path
1425
end
1526

16-
function make_stork_config(root, config)
27+
function make_stork_config(root, docs, config)
1728
files = []
1829
stork_config = Dict(
1930
"input" => Dict(
@@ -23,19 +34,9 @@ function make_stork_config(root, config)
2334
),
2435
"output" => Dict("save_nearest_html_id" => true),
2536
)
26-
for (r, _, fs) in walkdir(root)
27-
pathparts = splitpath(relpath(r, root))
28-
if length(pathparts) >= 2 && pathparts[2] in config.index_versions
29-
for file in fs
30-
if file == "index.html"
31-
add_to_index!(
32-
files,
33-
chop(r, head = length(root), tail = 0),
34-
joinpath(r, file),
35-
)
36-
end
37-
end
38-
end
37+
38+
walk_outputs(root, docs, config.index_versions) do path, file
39+
add_to_index!(files, path, file)
3940
end
4041

4142
return stork_config

test/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
out
2+
clones

0 commit comments

Comments
 (0)