Skip to content

Commit 189b79a

Browse files
committed
pass dir information during walkpage
1 parent e56c258 commit 189b79a

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/generate.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,11 @@ function makedemos(source::String, templates::Union{Dict, Nothing} = nothing;
143143

144144
# we can directly pass it to Documenter.makedocs
145145
if isnothing(templates)
146-
out_path = walkpage(page; flatten=false) do item
147-
splitext(joinpath(relative_root, relpath(item.path, page_root)))[1] * ".md"
146+
out_path = walkpage(page; flatten=false) do dir, item
147+
joinpath(
148+
relpath(dir, root),
149+
splitext(basename(item))[1] * ".md"
150+
)
148151
end
149152
else
150153
out_path = joinpath(relative_root, "index.md")

src/utils.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ This is particulaly useful to generate information for the page structure. For e
5050
```julia
5151
julia> page = DemoPage("docs/quickstart/");
5252
53-
julia> walkpage(page; flatten=true) do item
53+
julia> walkpage(page; flatten=true) do dir, item
5454
basename(item.path)
5555
end
5656
@@ -85,7 +85,7 @@ If `flatten=false`, then it gives you something like this:
8585
]
8686
```
8787
"""
88-
walkpage(page::DemoPage; kwargs...) = walkpage(identity, page; kwargs...)
88+
walkpage(page::DemoPage; kwargs...) = walkpage((dir, item)->item, page; kwargs...)
8989
function walkpage(f, page::DemoPage; flatten=true, kwargs...)
9090
nodes = _walkpage.(f, page.sections, 1; flatten=flatten, kwargs...)
9191
if flatten
@@ -97,9 +97,9 @@ function walkpage(f, page::DemoPage; flatten=true, kwargs...)
9797
end
9898

9999
function _walkpage(f, sec::DemoSection, depth; max_depth=Inf, flatten=true)
100-
depth+1 > max_depth && return flatten ? f(sec) : [f(sec), ]
100+
depth+1 > max_depth && return flatten ? f(src.root, sec) : [f(sec.root, sec), ]
101101
if !isempty(sec.cards)
102-
return flatten ? mapreduce(f, vcat, sec.cards) : sec.title => f.(sec.cards)
102+
return flatten ? mapreduce(x->f(sec.root, x), vcat, sec.cards) : sec.title => f.(sec.root, sec.cards)
103103
else
104104
map_fun(section) = _walkpage(f, section, depth+1; max_depth=max_depth, flatten=flatten)
105105
return flatten ? mapreduce(map_fun, vcat, sec.subsections) : sec.title => map_fun.(sec.subsections)

test/utils.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,21 @@ end
9393
@testset "walkpage" begin
9494
page = DemoPage(joinpath("assets", "page", "hidden"))
9595
reference = "Hidden" => ["hidden1.jl", "hidden2.md", "normal.md"]
96-
@test reference == walkpage(page) do item
96+
@test reference == walkpage(page) do dir, item
9797
basename(item.path)
9898
end
9999
reference = "Hidden" => ["Sec" => ["hidden1.jl", "hidden2.md", "normal.md"]]
100-
@test reference == walkpage(page; flatten=false) do item
100+
@test reference == walkpage(page; flatten=false) do dir, item
101101
basename(item.path)
102102
end
103103

104104
page = DemoPage(joinpath("assets", "page", "one_card"))
105105
reference = "One card" => ["card.md"]
106-
@test reference == walkpage(page) do item
106+
@test reference == walkpage(page) do dir, item
107107
basename(item.path)
108108
end
109109
reference = "One card" => ["Section" => ["Subsection" => ["card.md"]]]
110-
@test reference == walkpage(page; flatten=false) do item
110+
@test reference == walkpage(page; flatten=false) do dir, item
111111
basename(item.path)
112112
end
113113
end

0 commit comments

Comments
 (0)