Skip to content

x/website: show anchor links for article headings #68596

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
hyangah opened this issue Jul 25, 2024 · 9 comments
Closed

x/website: show anchor links for article headings #68596

hyangah opened this issue Jul 25, 2024 · 9 comments
Assignees
Labels
NeedsFix The path to resolution is known, but the work has not been done. website
Milestone

Comments

@hyangah
Copy link
Contributor

hyangah commented Jul 25, 2024

Reveal anchor links to headings, so users can copy the link to the specific part of the doc easily.

Before
Screenshot 2024-07-26 at 5 40 31 AM

After - the "¶" symbol appears when hover. On Chrome, right click on it will show the context menu so users can operate on the anchor link.
Screenshot 2024-07-26 at 5 43 04 AM

@gopherbot gopherbot added this to the Unreleased milestone Jul 25, 2024
@hyangah hyangah self-assigned this Jul 25, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/601055 mentions this issue: _content: add anchor links to article headers

@dmitshur dmitshur added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 25, 2024
@matttproud
Copy link
Contributor

@hyangah, thank you so much for doing this! The lack of this has bothered me for years and caused me to open up the inspector for each heading's ID to deep link to blog article sections! I am elated I no longer have to do this.

@gopherbot
Copy link
Contributor

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

@mvdan
Copy link
Member

mvdan commented Oct 9, 2024

I'm just here to echo what @matttproud said, this is amazing! I just created the anchor link https://go.dev/doc/comment#doclinks manually because I've been doing this for years and it didn't even occur to me that this got fixed 🙇

@mvdan
Copy link
Member

mvdan commented Oct 9, 2024

@hyangah just one request - when I hover over "Doc Links", nothing happens - which is why I didn't even realise this got fixed earlier today. I have to move my cursor to the right of the heading - where the "reverse P" anchor symbol would be - for it to appear, as if I had to know ahead of time it would be there.

Can we make the anchor link show up whenever I hover over any of the heading area too? I think this is how anchor link hovers usually work on other websites, or at least that's how I intuitively think they work.

@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 9, 2024
setAnchors in site.js was used to add anchor links to article headers.
Move that functionality to the related addPermalinks in godocs.js, so
it executes after generateTOC instead of before. That way generateTOC
can go back to using the full heading text as it did before CL 601055
and not need to deal with ignoring the '¶' symbol that is newly added.

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

Change-Id: I39334bd5635cd7af5ee0baeaf1ca06734eb4cb3f
Reviewed-on: https://go-review.googlesource.com/c/website/+/618635
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
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>
@mvdan
Copy link
Member

mvdan commented Nov 27, 2024

Hi again @hyangah @dmitshur - did you see my comment above? This is a closed issue so I'm worried the comment will be forgotten. If you must track this in an open issue, we could either reopen this one as "not fully implemented" or I can open a new one. Ideally it's an easy fix that doesn't require tracking.

@cespare
Copy link
Contributor

cespare commented Nov 27, 2024

Can we make the anchor link show up whenever I hover over any of the heading area too? I think this is how anchor link hovers usually work on other websites, or at least that's how I intuitively think they work.

In particular, it's how the anchor links work on pkgsite (example).

@mvdan I think you should just file a separate bug so it doesn't get dropped.

@mvdan
Copy link
Member

mvdan commented Dec 13, 2024

Yep, this is still not on anyone's radar, so I've filed #70827.

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

6 participants