Skip to content

x/website: code and other elements no longer display in TOC #69816

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

Closed
ianlancetaylor opened this issue Oct 8, 2024 · 4 comments
Closed

x/website: code and other elements no longer display in TOC #69816

ianlancetaylor opened this issue Oct 8, 2024 · 4 comments
Assignees
Labels
NeedsFix The path to resolution is known, but the work has not been done. website
Milestone

Comments

@ianlancetaylor
Copy link
Contributor

ianlancetaylor commented Oct 8, 2024

Go version

tip

Output of go env in your module/workspace:

N/A

What did you do?

Looked at https://go.dev/doc/faq.

What did you see happen?

See, for example, https://go.dev/doc/faq. The TOC has several incomplete entries, such as "Why is" and "Why does Go not have the". These are because the headers in _content/doc/faq.md uses header lines like

### Why is `len` a function and not a method? {#methods_on_basics}

and

### Why does Go not have the `?:` operator? {#Does_Go_have_a_ternary_form}

In https://go.dev/cl/601055 for #68596 the TOC code was changed to only display the first element. That is causing the truncation we see here.

CC @hyangah @dmitshur

What did you expect to see?

Untruncated TOC lines.

@gopherbot gopherbot added this to the Unreleased milestone Oct 8, 2024
@dmitshur
Copy link
Member

dmitshur commented Oct 8, 2024

CL 601055 made the change to start using node.firstChild.textContent as the TOC item text, instead of $(node).text(). It looks like it was trying not to include the '¶' symbol that the new setAnchors adds.

One of the ways to fix this is to go back to using text, but arrange for setAnchors to run after generateTOC, not the other way around as it currently happens:

setAnchors is being scheduled
generateTOC is being scheduled
setAnchors is starting
generateTOC is starting

Another approach might be to leave their current running order as is, but modify generateTOC to take into account it ran after setAnchors and not include the '¶' symbol in a different way, one that doesn't cut off text content beyond the first child element.

@cherrymui cherrymui added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 8, 2024
@cherrymui cherrymui changed the title x/website: code and other elements no longer display in TOC. x/website: code and other elements no longer display in TOC Oct 8, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/618635 mentions this issue: _content/js: generate TOC items before adding anchor links

@dmitshur
Copy link
Member

dmitshur commented Oct 8, 2024

CL 618635 changes the order to be:

setAnchors is being scheduled
generateTOC is being scheduled
generateTOC is starting
setAnchors is starting
image

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 8, 2024
@dmitshur dmitshur self-assigned this Oct 8, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/619015 mentions this issue: _content/blog: don't load godocs.js (and other scripts) more than once

gopherbot pushed a commit to golang/website that referenced this issue Oct 17, 2024
By now, the /js/godocs.js and /js/playground.js scripts are already
loaded on all go.dev pages because they're included at the bottom of
the root site.tmpl template. The layout template for blog pages also
loads those scripts.

That means /js/godocs.js runs twice, and that causes duplicate anchor
links to be added to article headings.

Remove the duplicate scripts, keeping only play.js which isn't already
present in site.html. Update it to reuse the existing window.initFuncs
mechanism.

For golang/go#68596.
For golang/go#69816.

Change-Id: I709f4b8df30500bddbbf16f4ddd95f266f290472
Reviewed-on: https://go-review.googlesource.com/c/website/+/619015
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done. website
Projects
None yet
Development

No branches or pull requests

4 participants