@@ -8,14 +8,11 @@ module GovukTechDocs
88 module TableOfContents
99 module Helpers
1010 def single_page_table_of_contents ( html , url : "" , max_level : nil )
11- headings = HeadingsBuilder . new ( html , url ) . headings
12-
13- if headings . none? { |heading | heading . size == 1 }
14- raise "No H1 tag found. You have to at least add one H1 heading to the page: " + url
15- end
11+ output = "<ul>\n "
12+ output += list_items_from_headings ( html , url : url , max_level : max_level )
13+ output += "</ul>\n "
1614
17- tree = HeadingTreeBuilder . new ( headings ) . tree
18- HeadingTreeRenderer . new ( tree , max_level : max_level ) . html
15+ output
1916 end
2017
2118 def multi_page_table_of_contents ( resources , current_page , config , current_page_html = nil )
@@ -28,6 +25,17 @@ def multi_page_table_of_contents(resources, current_page, config, current_page_h
2825 render_page_tree ( resources , current_page , config , current_page_html )
2926 end
3027
28+ def list_items_from_headings ( html , url : "" , max_level : nil )
29+ headings = HeadingsBuilder . new ( html , url ) . headings
30+
31+ if headings . none? { |heading | heading . size == 1 }
32+ raise "No H1 tag found. You have to at least add one H1 heading to the page: " + url
33+ end
34+
35+ tree = HeadingTreeBuilder . new ( headings ) . tree
36+ HeadingTreeRenderer . new ( tree , max_level : max_level ) . html
37+ end
38+
3139 def render_page_tree ( resources , current_page , config , current_page_html )
3240 # Sort by weight frontmatter
3341 resources = resources
@@ -69,7 +77,7 @@ def render_page_tree(resources, current_page, config, current_page_html)
6977 output += "</li>\n "
7078 else
7179 output +=
72- single_page_table_of_contents (
80+ list_items_from_headings (
7381 content ,
7482 url : resource . url ,
7583 max_level : config [ :tech_docs ] [ :max_toc_heading_level ] ,
0 commit comments