ElMassimo / iles

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

fix: prevent duplicated slugs for headings with the same title #155

Closed ouuan closed 2 years ago

ouuan commented 2 years ago

This resolves #154.

A counter is used to track the number of duplicated titles.

To pass the counter to the slug generator, the API of generateSlug is modified.

ids are taken into account when generating distinct slugs, but duplicated ids are not resolved and kept as-is, because it's the user's responsibility to not set duplicated ids.

An example (test suite):

title     id      slug
foo       none    foo
bar       none    bar-2
foo       none    foo-2
foo       bar     bar
foo-2     none    foo-2-2
foo-4     none    foo-4
foo       none    foo-3
foo       none    foo-5
bar       none    bar-3
foo-2     none    foo-2-3
foo-2-2   none    foo-2-2-2
foo       bar     bar

A consideration is that the type and initialization of counter limit the freedom of HeadingOptions.slug. Maybe we can change the parameter to a generic T and add HeadingOption.init: (ast: Parent) => T or use any.

nx-cloud[bot] commented 2 years ago

Nx Cloud Report

CI is running for commit df2baf20ae7dad8d524ea464db5f68a8e9f4431a.

📂 Click to track the progress, see the status, the terminal output, and the build insights.


Sent with 💌 from NxCloud.

ElMassimo commented 2 years ago

Thanks! I'll make a release later this week 😃

ouuan commented 1 year ago

Just a reminder that this is still not released.

ElMassimo commented 1 year ago

@ouuan Must have missed it last time, released in @islands/headings@0.8.1, thanks!