-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix missing <ul>
in single page navigation
#251
Conversation
Raised as a draft as I'm not super happy with this as a fix, mainly because it adds yet another level of indirection. I feel like there's probably a refactor here which simplifies things, but I just can't see it. |
I've had a reasonable look, and I think this is a good approach. I agree there are some concerns with the way it's factored - as I see it:
I also can't immediately see a way to refactor this that doesn't just make it even more complicated (e.g. you could hide the Maybe it's just worth thinking about the name of |
Since the changes made in 30471a9, there’s now no outer <ul> when `multipage_nav` is false – it jumps straight from the `<nav>` to the `<li>`. Because `multi_page_table_of_contents ` calls `single_page_table_of_contents` via `render_page_tree`, it's not as simple as adding the extra `<ul>` to the existing `single_page_table_of_contents` method, otherwise you end up with duplicate `<ul>` elements in some cases. Instead, rename the existing `single_page_table_of_contents` to create a new function `list_items_from_headings `. The `list_items_from_headings` method can be called by both `render_page_tree` and a new `single_page_table_of_contents` method which maintains the existing API. This new `single_page_table_of_contents` method can then add the wrapper without affecting the output of `multi_page_table_of_contents`.
c9367aa
to
4fd4a60
Compare
This is a good suggestion, thank you 👍🏻 I've changed it by amended the existing commit. |
Tested with the GDS Way repo and the navigation appears to be correctly formed: <nav id="toc" class="js-toc-list toc__list" aria-labelledby="toc-heading">
<ul>
<li>
<a href="#how-to-review-code"><span>How to review code</span></a>
<ul>
<li>
<a href="#good-review-practice" class="toc-link--in-view"><span>Good review practice</span></a>
</li>
<li>
<a href="#programming-style" class=""><span>Programming style</span></a>
</li>
<li>
<a href="#code-libraries" class=""><span>Code libraries</span></a>
</li>
<li>
<a href="#third-party-dependencies" class=""><span>Third-party dependencies</span></a>
</li>
<li>
<a href="#testing" class=""><span>Testing</span></a>
</li>
<li>
<a href="#deployment" class=""><span>Deployment</span></a>
</li>
<li>
<a href="#documentation" class=""><span>Documentation</span></a>
</li>
<li>
<a href="#further-reading"><span>Further reading</span></a>
</li>
</ul>
</li>
</ul>
</nav> |
Hi @timja - could you raise a separate issue with more details of where you're seeing this error? If your code is open source we can have a quick look, otherwise you'll need to say a bit more about what you're doing that you think causes the error. |
Since the changes made in 30471a9, there’s now no outer
<ul>
whenmultipage_nav
is false – it jumps straight from the<nav>
to the<li>
.Because
multi_page_table_of_contents
callssingle_page_table_of_contents
viarender_page_tree
, it's not as simple as adding the extra<ul>
to the existingsingle_page_table_of_contents
method, otherwise you end up with duplicate<ul>
elements in some cases.Instead, rename the existing
single_page_table_of_contents
to create a new function that can be called by bothrender_page_tree
and a newsingle_page_table_of_contents
method. The newsingle_page_table_of_contents
can then add the wrapper without affecting the output ofmulti_page_table_of_contents
.Fixes #250