Skip to content

Conversation

@kfranqueiro
Copy link
Collaborator

@kfranqueiro kfranqueiro commented Jun 23, 2025

This adds middleware to automatically add IDs to any headings that don't possess one, effective both during builds and when running the dev server. This operates across all generated HTML files, regardless of whether they were generated through Markdown content or directly from an Astro template.

This PR adds new explicit dependencies but does not actually add any new packages:

  • IDs are generated based on the heading's text content using the github-slugger library. This library is already used by Astro internally.
  • cheerio is used for headless DOM manipulation as its API mimics jQuery, which tends to be more concise and understandable than AST manipulation APIs; version 1.0.0 is already relied upon indirectly by astro-icon, so I reuse the same version to avoid adding new dependencies.

Unrelated, this PR also removes an unused import I missed in #92.

@kfranqueiro kfranqueiro merged commit f1a7920 into main Jun 30, 2025
1 check passed
@kfranqueiro kfranqueiro deleted the kgf-heading-ids branch June 30, 2025 18:35
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