diff --git a/docs/frontmatter.md b/docs/frontmatter.md index 9ddaf0a0..0fa4b144 100644 --- a/docs/frontmatter.md +++ b/docs/frontmatter.md @@ -110,4 +110,14 @@ title: My beautiful page --- ``` +## `parent` + +The page that should be highlighted as ‘active’ in the navigation. + +```yaml +--- +parent: shaving-yaks.html +--- +``` + [mm]: https://middlemanapp.com/basics/frontmatter diff --git a/example/source/child-of-expired-page.html.md b/example/source/child-of-expired-page.html.md new file mode 100644 index 00000000..769dd1aa --- /dev/null +++ b/example/source/child-of-expired-page.html.md @@ -0,0 +1,8 @@ +--- +title: This is a child of expired page +parent: expired-page.html +--- + +# This is a child of expired page + +Expired page should highlight in the navigation. diff --git a/lib/govuk_tech_docs.rb b/lib/govuk_tech_docs.rb index e4ca6f4f..95c77735 100644 --- a/lib/govuk_tech_docs.rb +++ b/lib/govuk_tech_docs.rb @@ -70,6 +70,14 @@ def current_page_review def format_date(date) date.strftime('%-e %B %Y') end + + def active_page(page_path) + [ + page_path == "/" && current_page.path == "index.html", + ("/" + current_page.path) == page_path, + current_page.data.parent != nil && ("/" + current_page.data.parent.to_s) == page_path, + ].any? + end end context.page '/*.xml', layout: false diff --git a/lib/source/layouts/_header.erb b/lib/source/layouts/_header.erb index 32d2b46a..f20d8548 100644 --- a/lib/source/layouts/_header.erb +++ b/lib/source/layouts/_header.erb @@ -31,9 +31,9 @@