eleventy
eleventy copied to clipboard
`InputPathToUrlTransformPlugin` url IDs advanced handling
Is your feature request related to a problem? Please describe.
By default, the InputPathToUrl tansform plugin leaves the portion of the link to a file after the # unchanged. It would be useful if IDs in links could have some optional logic and/or functions assigned.
Describe the solution you'd like
Let’s suppose there is a [link to a file section](path/to/file.md#Example%20ID%20Heading). The transformed outcome of that link will be <a href='/file-permalink/#Example%20ID%20Heading'>link to a file section</a>.
It would be great to add an option in the plugin config, allowing us to specify a preferred logic or set a custom function to handle links to IDs. For example, I would like to have that ID slugified, because in the linked page the heading ID is generated by Eleventy’s built-in Id Attribute plugin. Hence, the desired result would be <a href='/file-permalink/#example-id-heading'>link to a file section</a>
Describe alternatives you've considered
The example link is how Obsidian generates heading IDs by default. Potential alternatives would be to manually slugify the anchor IDs in the URLs, but this would break Obsidian’s default. For this reason, it would be optimal to give users the possibility to choose the best logic/function to accommodate their use case.
Additional context
No response
Studying the source code I notice that it uses the slugify option:
https://github.com/11ty/eleventy/blob/v3.0.1-alpha.1/src/Plugins/IdAttributePlugin.js#L84
Reading the docs I see that you can configure that option:
https://www.11ty.dev/docs/plugins/id-attribute/#with-options
In other words: You can define a function that treats the IDs like you need.
The default is https://github.com/11ty/eleventy/blob/v3.0.1-alpha.1/src/Filters/Slugify.js in combination with https://www.npmjs.com/package/@sindresorhus/slugify