|
24 | 24 | require "govuk_tech_docs/unique_identifier_generator" |
25 | 25 | require "govuk_tech_docs/warning_text_extension" |
26 | 26 | require "govuk_tech_docs/api_reference/api_reference_extension" |
| 27 | +require "govuk_tech_docs/custom_method_missing_handler" |
| 28 | +require "govuk_tech_docs/govuk_nunjuck_componenet_renderer" |
27 | 29 |
|
28 | 30 | module SassWarningSupressor |
29 | 31 | def warn(message) |
@@ -101,11 +103,35 @@ def format_date(date) |
101 | 103 | end |
102 | 104 |
|
103 | 105 | def active_page(page_path) |
104 | | - [ |
105 | | - page_path == "/" && current_page.path == "index.html", |
106 | | - "/#{current_page.path}" == page_path, |
107 | | - !current_page.data.parent.nil? && current_page.data.parent.to_s == page_path, |
108 | | - ].any? |
| 106 | + # if we are on the homepage e.g Documentation: / |
| 107 | + if page_path == "/" && current_page.url == "/" |
| 108 | + return true |
| 109 | + end |
| 110 | + |
| 111 | + # if we are on a single page the header links point to e.g Expired page: /expired-page.html |
| 112 | + if "/#{current_page.path}" == page_path |
| 113 | + return true |
| 114 | + end |
| 115 | + |
| 116 | + # If the doc maintainer has set the parent data in the frontmatter for the current page, |
| 117 | + # and it matches the value in the config e.g |
| 118 | + # Expired page: /expired-page.html (config) and parent: /expired-page.html (child-of-expired-page.html) |
| 119 | + if !current_page.data.parent.nil? && current_page.data.parent.to_s == page_path |
| 120 | + return true |
| 121 | + end |
| 122 | + |
| 123 | + # If we have a nested directory structure that matches a navigation link e.g Active pages: /active-pages/ |
| 124 | + if current_page.url.start_with?(page_path) |
| 125 | + # feels like a weird check, but stops false positive where "/" for root is also the start of "/active-pages" |
| 126 | + if page_path == "/" |
| 127 | + return current_page.url == "/" |
| 128 | + end |
| 129 | + |
| 130 | + # safe to return true, since we aren't in the situation above |
| 131 | + return true |
| 132 | + end |
| 133 | + # no other reason to believe we're active |
| 134 | + false |
109 | 135 | end |
110 | 136 | end |
111 | 137 |
|
@@ -138,5 +164,9 @@ def active_page(page_path) |
138 | 164 | else |
139 | 165 | context.ignore "search/*" |
140 | 166 | end |
| 167 | + |
| 168 | + if context.config[:tech_docs][:enable_govuk_components] |
| 169 | + context.activate :custom_method_missing_handler |
| 170 | + end |
141 | 171 | end |
142 | 172 | end |
0 commit comments