require "govuk_tech_docs/table_of_contents/heading_tree_builder" require "govuk_tech_docs/table_of_contents/heading_tree_renderer" require "govuk_tech_docs/table_of_contents/heading_tree" require "govuk_tech_docs/table_of_contents/heading" require "govuk_tech_docs/table_of_contents/headings_builder" module GovukTechDocs module TableOfContents module Helpers def single_page_table_of_contents(html, url: "", max_level: nil) output = "\n" output end def multi_page_table_of_contents(resources, current_page, config, current_page_html = nil) # Only parse top level html files # Sorted by weight frontmatter resources = resources .select { |r| r.path.end_with?(".html") && (r.parent.nil? || r.parent.url == "/") } .sort_by { |r| [r.data.weight ? 0 : 1, r.data.weight || 0] } render_page_tree(resources, current_page, config, current_page_html) end def list_items_from_headings(html, url: "", max_level: nil) headings = HeadingsBuilder.new(html, url).headings if headings.none? { |heading| heading.size == 1 } raise "No H1 tag found. You have to at least add one H1 heading to the page: " + url end tree = HeadingTreeBuilder.new(headings).tree HeadingTreeRenderer.new(tree, max_level: max_level).html end def render_page_tree(resources, current_page, config, current_page_html) # Sort by weight frontmatter resources = resources .sort_by { |r| [r.data.weight ? 0 : 1, r.data.weight || 0] } output = "\n" output end end end end