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

InputPathToUrlTransformPlugin url IDs advanced handling #3601

Open
xplosionmind opened this issue Dec 24, 2024 · 1 comment
Open

InputPathToUrlTransformPlugin url IDs advanced handling #3601

xplosionmind opened this issue Dec 24, 2024 · 1 comment

Comments

@xplosionmind
Copy link

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

@Ryuno-Ki
Copy link
Contributor

Ryuno-Ki commented Jan 2, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants