Skip to content
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

blog: Add anchor links to headings #1091

Merged
merged 4 commits into from
Dec 12, 2024
Merged

Conversation

victorlin
Copy link
Member

@victorlin victorlin commented Dec 12, 2024

preview

Description of proposed changes

This PR adds GitHub-style anchor links to heading elements. I also added a '#' on hover. See commits for details.

Related issue(s)

N/A, thought of this while working on #1089

Checklist

"See the variable/function definition" should implicitly be the thing to
do if one wants to inspect further.
@victorlin victorlin self-assigned this Dec 12, 2024
@nextstrain-bot nextstrain-bot temporarily deployed to nextstrain-s-victorlin--jdol3m December 12, 2024 00:13 Inactive
@victorlin victorlin mentioned this pull request Dec 12, 2024
6 tasks
Copy link
Contributor

@joverlee521 joverlee521 left a comment

Choose a reason for hiding this comment

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

Flagging that right now with the split between the Page and App routers, we also have static-site/src/util/parseMarkdown.js. I think we want to keep the two in-sync?

static-site/app/styles/globals.css Outdated Show resolved Hide resolved
@victorlin victorlin temporarily deployed to nextstrain-s-victorlin--jdol3m December 12, 2024 00:57 Inactive
@victorlin
Copy link
Member Author

Flagging that right now with the split between the Page and App routers, we also have static-site/src/util/parseMarkdown.js. I think we want to keep the two in-sync?

Hmm, I think it's reasonable to have different Markdown parsing based on each of the 3 usages:

  • Rendering blog posts (using app router version)
  • Rendering the blog feeds (using pages router version)
  • Rendering community/group descriptions (using pages router version)

Anchor links are only relevant for blog posts and I don't see the other two benefitting from this functionality. I can rewrite parseMarkdown to only add anchor links with an option (e.g. parseMarkdown({mdString, addHeadingAnchors: true}) so that this function is still unchanged for when we convert the other two to use app router. I can also revert allowing "style" tags and put all the styles in globals.css.

@joverlee521
Copy link
Contributor

I can rewrite parseMarkdown to only add anchor links with an option (e.g. parseMarkdown({mdString, addHeadingAnchors: true}) so that this function is still unchanged for when we convert the other two to use app router. I can also revert allowing "style" tags and put all the styles in globals.css.

+1 for both of these

These are meant to stay on the same page.
Add a reference and mention globals.css as an alternative. This is not
ideal since it adds unnecessary/unused styles for other pages, but this
is the easiest thing to do in absence of a more specific static CSS
file.

CSS modules cannot be easily used since the class names are dynamically
generated and meant for React/Next.js components.
This commit adds GitHub-style anchor links¹ to heading elements. I also
added a '#' on hover.

¹ https://github.com/markedjs/marked/blob/10020d018d4448b1d2d4612baf650c4e3a5949bf/docs/USING_PRO.md#the-renderer--renderer
@victorlin victorlin force-pushed the victorlin/blog-heading-links branch from 5548769 to ea6f00f Compare December 12, 2024 21:00
@victorlin victorlin merged commit 64f29d3 into master Dec 12, 2024
4 of 5 checks passed
@victorlin victorlin deleted the victorlin/blog-heading-links branch December 12, 2024 21:01
@victorlin victorlin temporarily deployed to nextstrain-s-victorlin--jdol3m December 12, 2024 21:01 Inactive
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