Skip to content

Commit

Permalink
Fix ul structure
Browse files Browse the repository at this point in the history
The current structure has an individual `ul` for each list item. There
should only be one `<ul></ul>` at each level, with the items defined in
`li` elements.
  • Loading branch information
colinbm committed Jun 21, 2021
1 parent 5b51590 commit a462b92
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ def render_tree(tree, indentation: DEFAULT_INDENTATION, level: nil)
end

if tree.children.any? && level < @max_level
output += indentation + "<ul>\n"

tree.children.each do |child|
output += indentation + INDENTATION_INCREMENT + "<li>\n"
output += render_tree(
Expand All @@ -35,8 +33,6 @@ def render_tree(tree, indentation: DEFAULT_INDENTATION, level: nil)
)
output += indentation + INDENTATION_INCREMENT + "</li>\n"
end

output += indentation + "</ul>\n"
end

output
Expand Down
14 changes: 10 additions & 4 deletions lib/govuk_tech_docs/table_of_contents/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ def multi_page_table_of_contents(resources, current_page, config, current_page_h
.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)
output = "<ul>"
output += render_page_tree(resources, current_page, config, current_page_html)
output += "</ul>"

output
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 = "";
output = ""
resources.each do |resource|
# Skip from page tree if hide_in_navigation:true frontmatter
next if resource.data.hide_in_navigation
Expand Down Expand Up @@ -63,9 +67,11 @@ def render_page_tree(resources, current_page, config, current_page_html)
end

if resource.children.any? && resource.url != home_url
output += %{<ul><li><a href="#{resource.url}"><span>#{resource.data.title}</span></a>\n}
output += %{<li><a href="#{resource.url}"><span>#{resource.data.title}</span></a>\n}
output += "<ul>"
output += render_page_tree(resource.children, current_page, config, current_page_html)
output += "</li></ul>"
output += "</ul>"
output += "</li>"
else
output +=
single_page_table_of_contents(
Expand Down

0 comments on commit a462b92

Please sign in to comment.