Skip to content

Use AnchorJS to automatically generate heading anchors - #700

Merged
nchammas merged 7 commits into
apache:asf-sitefrom
nchammas:heading-anchors
Oct 26, 2026
Merged

nchammas merged 7 commits into
apache:asf-sitefrom
nchammas:heading-anchors

Conversation

@nchammas

@nchammas nchammas commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Right now if you look at a page on the main website like Useful Developer Tools, you'll notice that you cannot easily click on a heading and get an HTML anchor that will let you link directly to that section. On the other hand, if you look at the programming docs, you'll see that you can get anchor links by mousing over a heading.

This discrepancy is because the programming docs include AnchorJS, whereas the main website does not.

This PR adds AnchorJS to the main docs so readers can easily link to headings there like they can on the programming docs:

This adds the latest release of AnchorJS, which is 5.0.0. The programming docs are on AnchorJS 1.1.1, which is more than 11 years old. In a matching PR, I will update the programming docs to also use AnchorJS 5.0.0 so they are consistent.

I built the docs locally and confirmed that the anchors work as expected.

Matching AnchorJS upgrade on the docs site: apache/spark#59547

@nchammas

Copy link
Copy Markdown
Contributor Author

Because this touches global.html, the diff on the generated HTML is going to be massive. For this reason I'm going to wait until #699 is merged before asking for this to be formally reviewed and merged in.

@nchammas

Copy link
Copy Markdown
Contributor Author

cc @yaooqinn. As an example, this work here combined with the {:toc} kramdown directive would eliminate the need to manually add section ids or a table of contents as you had to do in #535.

@nchammas
nchammas marked this pull request as ready for review October 14, 2026 11:07
nchammas added a commit to apache/spark that referenced this pull request Oct 26, 2026
### What changes were proposed in this pull request?

Upgrade AnchorJS to v5.0.0, and update its config accordingly to maintain roughly the current production behavior.

Additionally:
- Move the AnchorJS config to `global.html`, which matches where we include and configure other vendored libraries.
- Remove the `anchors` global from `main.js`, which is no longer needed now that the config is handled outside of there.
- Fix the included licenses for AnchorJS so it includes the copyright holder's name and year.

### Why are the changes needed?

The current version of AnchorJS we are using is [more than 11 years old][old]. The releases since then have added more accessible heading links and more reliable fragment generation.

[old]: https://github.com/bryanbraun/anchorjs/releases/tag/1.1.1

This upgrade will also keep the versions in sync with the main website's version of AnchorJS: apache/spark-website#700

Any browser released since early 2021 should support this new version without issue.

### Does this PR introduce _any_ user-facing change?

No, documentation behavior tweaks only.

### How was this patch tested?

I built and reviewed the site locally with `SKIP_API=1 bundle exec jekyll serve`. Confirmed that anchors work as expected, including for `h1` headings.

### Was this patch authored or co-authored using generative AI tooling?

Co-authored-by: GitHub Copilot

Closes #59547 from nchammas/anchorjs-bump.

Authored-by: Nicholas Chammas <nicholas.chammas@gmail.com>
Signed-off-by: Nicholas Chammas <nicholas.chammas@gmail.com>
nchammas added a commit to apache/spark that referenced this pull request Oct 26, 2026
### What changes were proposed in this pull request?

Upgrade AnchorJS to v5.0.0, and update its config accordingly to maintain roughly the current production behavior.

Additionally:
- Move the AnchorJS config to `global.html`, which matches where we include and configure other vendored libraries.
- Remove the `anchors` global from `main.js`, which is no longer needed now that the config is handled outside of there.
- Fix the included licenses for AnchorJS so it includes the copyright holder's name and year.

### Why are the changes needed?

The current version of AnchorJS we are using is [more than 11 years old][old]. The releases since then have added more accessible heading links and more reliable fragment generation.

[old]: https://github.com/bryanbraun/anchorjs/releases/tag/1.1.1

This upgrade will also keep the versions in sync with the main website's version of AnchorJS: apache/spark-website#700

Any browser released since early 2021 should support this new version without issue.

### Does this PR introduce _any_ user-facing change?

No, documentation behavior tweaks only.

### How was this patch tested?

I built and reviewed the site locally with `SKIP_API=1 bundle exec jekyll serve`. Confirmed that anchors work as expected, including for `h1` headings.

### Was this patch authored or co-authored using generative AI tooling?

Co-authored-by: GitHub Copilot

Closes #59547 from nchammas/anchorjs-bump.

Authored-by: Nicholas Chammas <nicholas.chammas@gmail.com>
Signed-off-by: Nicholas Chammas <nicholas.chammas@gmail.com>
(cherry picked from commit 5b71434)
Signed-off-by: Nicholas Chammas <nicholas.chammas@gmail.com>
@nchammas
nchammas merged commit 0f373e7 into apache:asf-site Oct 26, 2026
1 check passed
@nchammas
nchammas deleted the heading-anchors branch October 26, 2026 15:24
@nchammas

Copy link
Copy Markdown
Contributor Author

Confirmed post merge that the anchor links are working as expected: https://spark.apache.org/developer-tools.html#reducing-build-times

(Note also the link that now appears when you hover over the heading!)

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.

2 participants