Skip to content

Commit 7d48b09

Browse files
committed
fix: use nodejs_jll, use rootpath
1 parent eab6187 commit 7d48b09

File tree

6 files changed

+24
-31
lines changed

6 files changed

+24
-31
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Git = "d7ba0133-e1db-5d97-8f8c-041e4b3a1eb2"
99
Gumbo = "708ec375-b3d6-5a57-a7ce-8257bf98657a"
1010
HypertextLiteral = "ac1192a8-f4b3-4bfe-ba22-af5b92cd3ab2"
1111
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
12-
NodeJS = "2bd173c7-0d6d-553b-b6af-13a54713934c"
12+
NodeJS_22_jll = "8fca9ca2-e7a1-5ccf-8c05-43be5a78664f"
1313
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1414

1515
[compat]
@@ -18,7 +18,7 @@ Git = "1"
1818
Gumbo = "0.8.2"
1919
HypertextLiteral = "0.9"
2020
JSON = "0.20,0.21"
21-
NodeJS = "1, 2"
21+
NodeJS_22_jll = "22.15.0"
2222
julia = "1"
2323

2424
[extras]

assets/default/pagefind_integration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
let FOCUSABLE_ELEMENTS = []
55
let FOCUSED_ELEMENT_INDEX = 0
66

7-
const pagefind = await import("/pagefind/pagefind.js");
7+
const pagefind = await import(window.MULTIDOCUMENTER_ROOT_PATH + "pagefind/pagefind.js")
88

99
function initialize() {
1010
pagefind.init()

src/MultiDocumenter.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ end
1515
1616
`index_versions` is a vector of relative paths used for generating the search index. Only
1717
the first matching path is considered.
18-
`engine` may be `MultiDocumenter.PageFind`, `MultiDocumenter.FlexSearch`, `MultiDocumenter.Stork`,
18+
`engine` may be `MultiDocumenter.PageFind`, `MultiDocumenter.FlexSearch`, `MultiDocumenter.Stork`,
1919
or a module that conforms to the expected API (which is currently undocumented).
2020
`lowfi = true` will try to minimize search index size. Only relevant for flexsearch.
2121
"""
@@ -137,7 +137,7 @@ include("search/stork.jl")
137137
include("canonical.jl")
138138
include("sitemap.jl")
139139

140-
const DEFAULT_ENGINE = SearchConfig(index_versions = ["stable", "dev"], engine = PageFind)
140+
const DEFAULT_ENGINE = SearchConfig(; index_versions = ["stable", "dev"], engine = PageFind)
141141

142142
"""
143143
make(

src/search/flexsearch.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module FlexSearch
2-
import Gumbo, JSON, AbstractTrees, NodeJS
2+
import Gumbo, JSON, AbstractTrees
3+
using NodeJS_22_jll: node
34
using HypertextLiteral
45
import ..walk_outputs
56

@@ -151,7 +152,7 @@ function build_search_index(root, docs, config, rootpath)
151152
file = config.lowfi ? "gensearch-lowfi.js" : "gensearch.js"
152153
println("Writing $(config.lowfi ? "lowfi" : "") flexsearch index:")
153154
cd(root) do
154-
run(`$(NodeJS.nodejs_cmd()) $(joinpath(@__DIR__, "..", "..", "flexsearch", file))`)
155+
run(`$(node()) $(joinpath(@__DIR__, "..", "..", "flexsearch", file))`)
155156
end
156157
return nothing
157158
end

src/search/pagefind.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
module PageFind
2-
using NodeJS: NodeJS
3-
using HypertextLiteral
2+
using NodeJS_22_jll: npx, npm
3+
using HypertextLiteral: @htl
44

55
function inject_script!(custom_scripts, rootpath)
66
pushfirst!(custom_scripts, joinpath("assets", "default", "pagefind_integration.js"))
77
pushfirst!(custom_scripts, joinpath("pagefind", "pagefind.js"))
8+
pushfirst!(
9+
custom_scripts,
10+
Docs.HTML("window.MULTIDOCUMENTER_ROOT_PATH = '$(rootpath)'"),
11+
)
812
end
913

1014
function inject_styles!(custom_styles)
@@ -23,13 +27,16 @@ function render()
2327
end
2428

2529
function build_search_index(root, docs, config, rootpath)
26-
if !success(`npx pagefind -V`)
27-
error("pagefind search engine not found. Aborting. Try running `npm install pagefind --global`")
30+
if !success(Cmd(`$(npx) pagefind -V`; dir=root))
31+
@info "Installing pagefind into $root."
32+
if !success(Cmd(`$(npm) install pagefind`; dir=root))
33+
error("Could not install pagefind.")
34+
end
2835
end
2936

3037
pattern = "*/{$(join(config.index_versions, ","))}/**/*.{html}"
3138

32-
run(`npx pagefind --site $(root) --glob $(pattern) --root-selector article --exclude-selectors pre`)
39+
run(`$(npx) pagefind --site $(root) --glob $(pattern) --root-selector article`)
3340
end
3441

3542
end

test/runtests.jl

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ if Sys.iswindows() && !isinteractive()
9595
docs;
9696
search_engine = MultiDocumenter.SearchConfig(
9797
index_versions = ["stable", "dev"],
98-
engine = MultiDocumenter.FlexSearch,
98+
engine = MultiDocumenter.PageFind,
9999
),
100100
custom_scripts = [
101101
"foo/bar.js",
@@ -114,7 +114,7 @@ MultiDocumenter.make(
114114
docs;
115115
search_engine = MultiDocumenter.SearchConfig(
116116
index_versions = ["stable", "dev"],
117-
engine = MultiDocumenter.FlexSearch,
117+
engine = MultiDocumenter.PageFind,
118118
),
119119
custom_scripts = [
120120
"foo/bar.js",
@@ -210,23 +210,8 @@ MultiDocumenter.make(
210210
@test occursin(canonical_href, index)
211211
end
212212

213-
@testset "flexsearch" begin
214-
@test isdir(outpath, "search-data")
215-
store_content = read(joinpath(outpath, "search-data", "store.json"), String)
216-
@test !isempty(store_content)
217-
@test occursin("Infiltrator.jl", store_content)
218-
@test occursin("@infiltrate", store_content)
219-
# We can't traverse symlinks on Windows, so stable/ things do not get
220-
# written into the search index. Instead, it looks like we write dev/
221-
if Sys.iswindows()
222-
@test !occursin("$(rootpath)inf/stable/", store_content)
223-
@test !occursin("$(rootpath)inf/stable/", store_content)
224-
@test occursin("/inf/dev/", store_content)
225-
else
226-
@test occursin("$(rootpath)inf/stable/", store_content)
227-
@test occursin("$(rootpath)inf/stable/", store_content)
228-
@test !occursin("/inf/dev/", store_content)
229-
end
213+
@testset "pagefind" begin
214+
@test isdir(outpath, "pagefind")
230215
end
231216

232217
@testset "sitemap" begin

0 commit comments

Comments
 (0)