add option to skip rendering child when rendering ToC#439
add option to skip rendering child when rendering ToC#439jamescarr28 wants to merge 5 commits intomainfrom
Conversation
|
So the code looks good to me, @NathanD-GDS you raised the initial bug, you wanna give this a look too? |
Needs final approval from Huw and Nathan before merging
NathanD-GDS
left a comment
There was a problem hiding this comment.
Looks good - just a few small suggestions.
README.md
Outdated
|
|
||
| ## Use layouts to structure your Table of Contents | ||
|
|
||
| You can use layouts to group pages and customise your Table of Contents (ToC). To create a template create a new ruby file in the `source/layouts` directory, for example `source/layouts/live_support_layout.erb`. You can apply the template by including it in the frontmatter block of your required pages, for example: |
There was a problem hiding this comment.
| You can use layouts to group pages and customise your Table of Contents (ToC). To create a template create a new ruby file in the `source/layouts` directory, for example `source/layouts/live_support_layout.erb`. You can apply the template by including it in the frontmatter block of your required pages, for example: | |
| You can use layouts to group pages and customise your Table of Contents (ToC). To create a layout, create a new ruby file in the `source/layouts` directory, for example `source/layouts/live_support.erb`. | |
| Apply the template by including it in the frontmatter block of a pages. In this example, we're applying the `live_support` layout to the page: |
Just a few changes here. I think 'layout' is probably more appropriate than 'template'.
Removed 'layout' from the file name because it felt unnecessary, but happy for you to add it back in if you think it's needed.
Also added more of an explanation about what the example is.
README.md
Outdated
| ``` | ||
|
|
||
|
|
||
| This gem has helper functions to render your ToC. You should use: |
There was a problem hiding this comment.
| This gem has helper functions to render your ToC. You should use: | |
| This gem has helper functions to render your ToC. You can use: |
Is it 'should' or 'can'?
There was a problem hiding this comment.
Interesting question, it depends on how much leeway we want the gem to have I guess. I'd say that it's should as we're saying, 'if you want to [create a single page table of contents], you should use [the function] as we've tested it and approved it works in the style we expect'
README.md
Outdated
| ``` | ||
|
|
||
|
|
||
| This gem has helper functions to render your ToC. You should use: |
There was a problem hiding this comment.
Given this section is about layouts, is it possible to change this line to make it clearer how this relates to layouts? For example:
This gem has helper functions that you can use in custom layouts. You can use:
README.md
Outdated
|
|
||
| The `multi_page_table_of_contents` helper function takes [an optional `include_child_resources`](https://github.com/alphagov/tech-docs-gem/pull/439) parameter to help with your custom ToC. The default value of `include_child_resources` is `true`. | ||
|
|
||
| Below is an example of using the helper functions in a custom layout: |
There was a problem hiding this comment.
Would it be possible to add a bit more of an explainer about what's happening in this example? I've added a suggestion below of the kind of thing I mean, but it's probably wrong so you'll be able to explain it!
| Below is an example of using the helper functions in a custom layout: | |
| Below is an example of a custom layout that creates a ToC for a group of pages BLAH BLAH BLAH: |
What’s changed
We have added an optional flag for the
multi_page_table_of_contents/render_page_treehelper functions. The table of contents (ToC) currently has limitations when using layouts to group sections and create filtered ToC - e.g. when usingheader_linksand requiring a specific ToC .Example usage
Identifying a user need
This is particularly an issue when we have a directory with an index page, and then sub directories containing nested sections. When trying to organise this structure using
header_linksto create sections, we want each section to create it's own ToC eg:The expected result would be:
This bug has been previously raised here. We are currently unable to publish updated public facing documentation due to the navigation being too painful. This fix allows us to do this, while maintaining backwards compatibility
Existing options that don't generate the right result
Using resource.children
If we use the resource.children call then we loose the section index page altogether. This page can only be found by clicking the link in the navigation (top right). This is a confusing user journey and very unclear.
code example:
Including resource in tree builder
If we try to include the the extra resource then the full child tree is rendered below the main section. Result below is the same if we merge into a single array etc
code example:
result:
Using single page ToC
When using the single page ToC functions the ToC changes when you move to a different page, with the section index missing altogether