docsy icon indicating copy to clipboard operation
docsy copied to clipboard

Build the right-side table of contents from javascript

Open fekete-robert opened this issue 2 years ago • 15 comments

By default, Docsy shows the table of contents for the current page in the right sidebar using the built-in function of Hugo. You can replace that with a JavaScript-based ToC that uses the [https://tscanlin.github.io/tocbot/](Tocbot library) by setting the following in your config.toml file:

[params.jstoc]
enable = true

Compared to the default sidebar ToC, this solution:

  • has a marker that shows the current location of the screen (useful for long pages)
  • shows the correct title even if the title contains a shortcode
  • shows the title in the toc even if it was included from another file

For a working example, see https://kube-logging.dev/docs/

fekete-robert avatar Jun 15 '22 12:06 fekete-robert

Exciting! Can't wait for this!

jmichelgarcia avatar Sep 12 '22 21:09 jmichelgarcia

Thanks @jmichelgarcia, glad you like it! Rebased and resolved conflicts. @chalin , might you have some time to review this PR?

fekete-robert avatar Sep 13 '22 08:09 fekete-robert

@fekete-robert would you be willing to rebase this against main?

If you're not sure what that means, reply here and someone who does know how may be able to make time to guide you through that.

sftim avatar Oct 18 '22 10:10 sftim

:confused: @fekete-robert did you mean to close this PR?

sftim avatar Oct 18 '22 11:10 sftim

Hi @sftim, sorry I didn't intend to close it, just messed something up during the rebase.

fekete-robert avatar Oct 18 '22 12:10 fekete-robert

Should be ok now

fekete-robert avatar Oct 18 '22 12:10 fekete-robert

@sftim : It seems that the tocbot release archive (https://github.com/tscanlin/tocbot/releases/tag/v4.12.0) contain only the minified version (that is, the same minified file under the tocbot.min.js and tocbot.js name), so I don't think it makes any difference.

The highlighting is not very visible on the screenshot, because not the entire title is highlighted, just the section of the vertical splitbar next to the title. It's more apparent when you are actually scrolling on the page.

fekete-robert avatar Oct 18 '22 13:10 fekete-robert

How are we honoring the tocbot LICENSE?

sftim avatar Oct 18 '22 14:10 sftim

Tocbot is MIT-licensed which AFAIK permits free use - is there anything we should do?

On Tue, Oct 18, 2022 at 4:33 PM Tim Bannister @.***> wrote:

How are we honoring the tocbot LICENSE?

— Reply to this email directly, view it on GitHub https://github.com/google/docsy/pull/1049#issuecomment-1282495128, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA6AU3PZ3AC7ZMCEUZ6JZN3WD2YLDANCNFSM5Y3GHUZQ . You are receiving this because you modified the open/close state.Message ID: @.***>

fekete-robert avatar Oct 18 '22 14:10 fekete-robert

BTW, many thanks for the thorough review!

On Tue, Oct 18, 2022 at 4:38 PM Robert Fekete @.***> wrote:

Tocbot is MIT-licensed which AFAIK permits free use - is there anything we should do?

On Tue, Oct 18, 2022 at 4:33 PM Tim Bannister @.***> wrote:

How are we honoring the tocbot LICENSE?

— Reply to this email directly, view it on GitHub https://github.com/google/docsy/pull/1049#issuecomment-1282495128, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA6AU3PZ3AC7ZMCEUZ6JZN3WD2YLDANCNFSM5Y3GHUZQ . You are receiving this because you modified the open/close state.Message ID: @.***>

fekete-robert avatar Oct 18 '22 14:10 fekete-robert

Hi, @fekete-robert. Thank you for your work and the update! This is a better and complete solution for the ToC feature.🙂

Although using the original tocbot code itself is allowed by MIT License, it also requires including the original MIT License in the copied code (please refer to the original LICENSE here: tocbot/LICENSE at master · tscanlin/tocbot · GitHub - https://github.com/tscanlin/tocbot/blob/master/LICENSE#L12-L13). So I think one option could be to include the entire MIT License text as a code comment in static/js/tocbot.min.js and static/scss/tocbot.css.

Also, I'd recommend including the original URL and tocbot version so that we can easily track the version and refer to it during a future update.

shuuji3 avatar Jul 09 '23 07:07 shuuji3

@shuuji3 Many thanks for spotting that, I've added the licenses and updated the js/css to use a newer version (4.21.0)

fekete-robert avatar Jul 10 '23 10:07 fekete-robert

I still have hope that this will get merged one day. 🥇

jmichelgarcia avatar Mar 14 '24 20:03 jmichelgarcia

I still have hope that this will get merged one day. 🥇

Me too. I realize that this PR pulls in tocbot.min.js from static folder. Since tocbot is actively maintained —latest version is 4.25.0, while this PR still uses 4.21.0— it might be useful to pull in the latest version of the script from CDN at build time via hugo's resources.GetRemote function. @chalin: any timeline for this PR? I'm surprised to see that this PR is not assigned to any of the existing milestones yet :worried:.

deining avatar Mar 14 '24 21:03 deining

@deining: If I have some time this weekend I'll update the PR to use the CDN, and resolve the conflicts as well. (Originally I didn't use the CDN because I prefer to use local copies, and was also hoping that https://github.com/google/docsy/pull/1204 gets merged, and wanted to use that approach )

fekete-robert avatar Mar 21 '24 10:03 fekete-robert