ElMassimo / iles

🏝 The joyful site generator
https://iles.pages.dev
MIT License
1.07k stars 31 forks source link

Rename the slugs of duplicated headings #154

Closed ouuan closed 2 years ago

ouuan commented 2 years ago

Is your feature request related to a problem? Please describe.

When using @islands/headings, if multiple headings have the same name, now they will share the same slug, and then the anchor will only work for the first heading with the shared name.

Describe the solution you'd like

Rename the slug when multiple headings have the same name. For example, if the slug foo is already used, we can give foo-2 to the next heading whose name is foo, and then give foo-3 to the next one whose name is foo, and then maybe give foo-3-2 to a heading whose name is foo-3.

Describe alternatives you've considered

Avoid duplicated headings when writing Markdown.

ElMassimo commented 2 years ago

Hi Yufan!

Would you provide an example where you would use the same heading in several sections in a Markdown doc?

PRs are welcome to create an Object counter, that keeps track of how many times a given heading has appeared, suffixing it with numbers if it already exists (counter + 1).