Skip to content

blog: Add ToC to the right sidebar #3484

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

ZJvandeWeg
Copy link
Member

Description

Adds a ToC to the right sidebar for Blog posts.

Related Issue(s)

Checklist

  • I have read the contribution guidelines
  • I have considered the performance impact of these changes
  • Suitable unit/system level tests have been added and they pass
  • Documentation has been updated

.eleventy.js Outdated

const markdownItOptions = {
html: true,
}

const markdownItAnchorOptions = {
permalink: markdownItAnchor.permalink.linkInsideHeader({
symbol: `# `,
symbol: ``,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got to verify if this didn't break a lot of other things?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change removes the visual indicator for header permalinks in our docs and the NR docs too. It also removes the ability to copy the link address for sharing a specific section. Was this the intended outcome?

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds a Table of Contents to the right sidebar of blog posts using the eleventy-plugin-toc.

  • Introduces CSS styles for rendering and interacting with the ToC
  • Updates the post layout to conditionally render the ToC in the sidebar
  • Installs and configures the eleventy-plugin-toc in the build config

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

File Description
src/css/style.components.css Styles for the new ToC component
src/_includes/layouts/post.njk Conditional rendering of the ToC
package.json Adds eleventy-plugin-toc dependency
.eleventy.js Registers and configures the ToC plugin
Comments suppressed due to low confidence (3)

src/_includes/layouts/post.njk:65

  • Consider adding a test to verify that the ToC filter renders correctly and only appears when heading elements are present.
                    {% if content | toc %}

.eleventy.js:671

  • [nitpick] Update the project README or developer documentation to include setup and usage instructions for the new ToC plugin configuration.
    eleventyConfig.addPlugin(pluginTOC, {

src/css/style.components.css:126

  • The theme() function is not valid in plain CSS; consider using a CSS variable, a utility class, or ensuring your build step processes theme() correctly.
    color: theme(colors.gray.700);

Copy link
Collaborator

@sumitshinde-84 sumitshinde-84 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToC Looks great, thanks for the PR, @ZJvandeWeg

@Yndira-E
Copy link
Contributor

We already had a solution in place for creating ToCs; check our docs, handbook, and nr-docs for reference. Why should we use a different one for the blog posts?

@ZJvandeWeg
Copy link
Member Author

@Yndira-E Less maintainance on our part, was planning on moving those parts over too

Comment on lines +67 to +74
<script>
document.addEventListener('DOMContentLoaded', function() {
const tocLinks = document.querySelectorAll('.toc a');
tocLinks.forEach(link => {
link.textContent = link.textContent.replace(/^#\s*/, '');
});
});
</script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just ran a small test, because the blog articles were still showing the symbol on the ToC items. We can add the # through css, and there will be no need for this script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants