Description
Feature request
What problem does this feature solve?
Generating correct links when the clean-urls plugin is used.
Let's assume the plugin is used with the options { normalSuffix: '/', indexSuffix: '/' }
and a page guide.md
.
The plugin modifies the path of the resulting page, so that it gets exported as guide/index.html
instead of the standard guide.html
.
This solves only one part of the problem though, as the links generated by Vuepress are still guide.html
. As the warning in the plugin README mentions, this isn't a problem as long as JavaScript is used because the router handles both cases. But following those links without JavaScript or opening them in a separate window/tab leads to the 404 page, because there is no guide.html
but guide/index.html
. We noticed this when adding a broken link checker to our project.
As a solution to that, the proposed change gives the option to configure the links that get generated by Vuepress, so that users and plugins can hook into that. In parts, this request relates to #2420 and #2424.
What does the proposed API look like?
Extending the markdown link plugin with an option for the suffix, which is currently hardcoded to be .html
.
How should this be implemented in your opinion?
- Accept the suffix option in the exported plugin function, defaulting to the current
.html
- Modifying the
toRouterLink
of the markdown link plugin to make use of the new option:
- .replace(/\.md$/, '.html')
+ .replace(/\.md$/, suffix)
- .replace(/\.md(#.*)$/, '.html$1')
+ .replace(/\.md(#.*)$/, `${suffix}$1`)
Are you willing to work on this yourself?
Yes, if this is a wanted change I could take it on.
I verified that this works at least for the described case by monkey-patching the link.js
file.
There might be edge cases involved though, but the cases described in #2420 and #2424 seem like other good real-world examples.