Skip to content

Commit 3d424b7

Browse files
authored
allow empty sections when building a page (#100)
1 parent 7184608 commit 3d424b7

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/types/page.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,17 @@ function DemoPage(root::String)::DemoPage
130130
config = parse(Val(:Markdown), template_file)
131131
config = merge(json_config, config) # template has higher priority over config file
132132

133-
sections = map(DemoSection, section_paths)
133+
sections = filter(map(DemoSection, section_paths)) do sec
134+
empty_section = isempty(sec.cards) && isempty(sec.subsections)
135+
if empty_section
136+
@warn "Empty section detected, remove from the demo page tree." section=relpath(sec.root, root)
137+
return false
138+
else
139+
return true
140+
end
141+
end
142+
isempty(sections) && error("Empty demo page, you have to add something.")
143+
134144
page = DemoPage(root, sections, "", nothing, "", Dict{String, Any}())
135145
page.theme = load_config(page, "theme"; config=config)
136146

test/assets/section/empty/sec2/demo1.jl

Whitespace-only changes.

test/types/page.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ using DemoCards: infer_pagedir, is_demosection, is_democard
2828
# template has higher priority
2929
page = DemoPage(joinpath(root, "suppressed_title"))
3030
@test page.title == "Custom Title"
31+
32+
@testset "empty demo section" begin
33+
page_dir = joinpath("assets", "section", "empty")
34+
mkpath(joinpath(page_dir, "sec1")) # empty folder cannot be commited into git history
35+
36+
page = @suppress_err DemoPage(page_dir)
37+
@test length(page.sections) == 1
38+
warn_msg = @capture_err DemoPage(page_dir)
39+
@test occursin("Empty section detected", warn_msg)
40+
41+
@test_throws ErrorException("Empty demo page, you have to add something.") @suppress_err begin
42+
preview_demos(joinpath("assets", "section", "empty", "sec1"))
43+
end
44+
@test isempty(readdir(joinpath(page_dir, "sec1")))
45+
rm(joinpath(page_dir, "sec1"))
46+
end
3147
end
3248

3349
@testset "infer_pagedir" begin

0 commit comments

Comments
 (0)