File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -101,11 +101,35 @@ def format_date(date)
101101 end
102102
103103 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?
104+ # if we are on the homepage e.g Documentation: /
105+ if page_path == "/" && current_page . url == "/"
106+ return true
107+ end
108+
109+ # if we are on a single page the header links point to e.g Expired page: /expired-page.html
110+ if "/#{ current_page . path } " == page_path
111+ return true
112+ end
113+
114+ # If the doc maintainer has set the parent data in the frontmatter for the current page,
115+ # and it matches the value in the config e.g
116+ # Expired page: /expired-page.html (config) and parent: /expired-page.html (child-of-expired-page.html)
117+ if !current_page . data . parent . nil? && current_page . data . parent . to_s == page_path
118+ return true
119+ end
120+
121+ # If we have a nested directory structure that matches a navigation link e.g Active pages: /active-pages/
122+ if current_page . url . start_with? ( page_path )
123+ # feels like a weird check, but stops fals positive where "/" for root is also the start of "/active-pages"
124+ if page_path == "/"
125+ return current_page . url == "/"
126+ end
127+
128+ # safe to return true, since we aren't in the situation above
129+ return true
130+ end
131+ # no other reason to believe we're active
132+ false
109133 end
110134 end
111135
You can’t perform that action at this time.
0 commit comments