Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
Monkey patch contents builder to support titles in frontmatter
Browse files Browse the repository at this point in the history
This is a bit horrible, but it means we can keep going. Effectively the
govuk_tech_docs panics when there's not H1 on the page. We use this
override to (at the last minute) inject one.
  • Loading branch information
duncanjbrown committed May 26, 2022
1 parent 6a6b2da commit a660f97
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tech-docs/config.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# frozen_string_literal: true

require 'govuk_tech_docs'

GovukTechDocs::TableOfContents::Helpers.module_eval do
def list_items_from_headings(html, url: '', max_level: nil)
headings = GovukTechDocs::TableOfContents::HeadingsBuilder.new(html, url).headings

if headings.none? { |heading| heading.size == 1 }
resource = sitemap.find_resource_by_path("#{url[1..]}index.html")
html = "<h1>#{resource.data.title}</h1>"
headings = GovukTechDocs::TableOfContents::HeadingsBuilder.new(html, url).headings
end

tree = GovukTechDocs::TableOfContents::HeadingTreeBuilder.new(headings).tree
GovukTechDocs::TableOfContents::HeadingTreeRenderer.new(tree, max_level: max_level).html
end
end

GovukTechDocs.configure(self)

configure :build do
Expand Down

0 comments on commit a660f97

Please sign in to comment.