Skip to content

Commit 4fabee6

Browse files
committed
fix: generate multipage TOC with http_prefix
1 parent c1d0a62 commit 4fabee6

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/govuk_tech_docs/table_of_contents/helpers.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@ def single_page_table_of_contents(html, url: '', max_level: nil)
1919
end
2020

2121
def multi_page_table_of_contents(resources, current_page, config, current_page_html = nil)
22+
# Determine
23+
home_url =
24+
if config[:http_prefix].end_with?("/")
25+
config[:http_prefix]
26+
else
27+
config[:http_prefix] + "/"
28+
end
29+
2230
# Only parse top level html files
2331
# Sorted by weight frontmatter
2432
resources = resources
25-
.select { |r| r.path.end_with?(".html") && (r.parent.nil? || r.parent.url == "/") }
33+
.select { |r| r.path.end_with?(".html") && (r.parent.nil? || r.parent.url == home_url) }
2634
.sort_by { |r| [r.data.weight ? 0 : 1, r.data.weight || 0] }
2735

2836
render_page_tree(resources, current_page, config, current_page_html)

spec/table_of_contents/helpers_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def add_children(children)
174174
expect(subject.multi_page_table_of_contents(resources, current_page, config, current_page_html).strip).to eq(expected_multi_page_table_of_contents.strip)
175175
end
176176

177-
it 'builds a table of contents from several page resources with a custom http prefix ocnfigured' do
177+
it 'builds a table of contents from several page resources with a custom http prefix configured' do
178178
resources = []
179179
resources[0] = FakeResource.new('/prefix/index.html', '<h1 id="heading-one">Heading one</h1><h2 id="heading-two">Heading two</h2>', 10, 'Index');
180180
resources[1] = FakeResource.new('/prefix/a.html', '<h1 id="heading-one">Heading one</h1><h2 id="heading-two">Heading two</h2>', 10, 'Sub page A', resources[0]);

0 commit comments

Comments
 (0)