-
-
Notifications
You must be signed in to change notification settings - Fork 127
Generate ToC with Hugo rather than JavaScript #1851
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
Conversation
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
| applications, they are not intended to be fully-fledged communication | ||
| systems. | ||
|
|
||
| {{< cs-module name="instant_messaging" >}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hrm. We switched to {{< deliberately (#1205). Switching back seems like it will break things?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this is ok because the cs-module shortcode is switching to .RenderShortcodes instead of .Content? But why is it necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hugo is lazy and uses the markdown renderer to detect headings and construct the headings tree.
.Content returns a page rendered as HTML, and {{< means "don't process the data returned by this shortcode with the renderer", so the renderer in the main page just replaces the shortcode with the module page rendered as HTML without processing anything, and Hugo is only aware of the headings in the main page.
.RenderShortcodes returns the raw markdown, with the shortcodes of the page already replaced, and {{% means "process the data returned by this shortcode with the renderer", so the renderer processes the full mardown of the main page and the module pages as a single document, and Hugo is aware of all the headings in the final page.
| IgnoreDirectoryMissingTrailingSlash: true | ||
| DirectoryPath: spec | ||
| CheckExternal: false | ||
| IgnoreInternalEmptyHash: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the record: this stops htmltest complaining about links with href="#"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Though, as far as I can tell, we've had such links in the ToC for ever, so I don't know why we suddenly need this now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
htmltest only tests the HTML source, the ToC was generated with JavaScript, so htmltest didn't check it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh of course
| IgnoreDirectoryMissingTrailingSlash: true | ||
| DirectoryPath: spec | ||
| CheckExternal: false | ||
| IgnoreInternalEmptyHash: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Though, as far as I can tell, we've had such links in the ToC for ever, so I don't know why we suddenly need this now)
|
Writing it here for want of somewhere better: I wondered if we could avoid cloning the whole of baseof.html: - {{ partial "sidebar.html" . }}
+ <div class="sidebar-div td-sidebar-nav">
+ {{ partial "sidebar.html" . }}
+ {{ partial "toc.html" . }}
+ </div>Custom CSS: .sidebar-div {
overflow-y: auto;
position: sticky;
top: 4rem;
height: calc(100vh - 5rem);
}
.td-sidebar__inner {
height: auto !important;
position: static !important;
}(In other words, we have to move the |
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
richvdh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Thanks to the
.RenderShortcodesfunction added in Hugo 0.117.0, we can include the CS modules and all the headings are included in the generated ToC, with unique IDs. This avoids to do it with JavaScript in the browser.This should fix the issue in #1841.
This might however leave some duplicate IDs in the code generated from OpenAPI definitions.
Pull Request Checklist
Preview: https://pr1851--matrix-spec-previews.netlify.app