Vuepress: Make page suffix configurable (currently fixed to .html)

Created on 18 Jun 2020  路  5Comments  路  Source: vuejs/vuepress

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?

  1. Accept the suffix option in the exported plugin function, defaulting to the current .html
  2. 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.

core team review feature request

Most helpful comment

@billyyyyy3320 Thanks for the feedback, I provided the PR #2674.

All 5 comments

Inviting feedback from @bencodezen @billyyyyy3320 @kefranabg :)

I am keen to see a solution for this and @dennisreimann's suggestion seems simple and elegant, would this change be accepted if a PR is made?

I could provide a pull request 鈥撀燼nyone from core interested in this?
Inviting feedback from @bencodezen @billyyyyy3320 @kefranabg :)

@dennisreimann Sorry for the very late reply. It sounds great to me.

Also, IMO, the config should be a property of Markdown config.

cc @Shigma @meteorlxy (Plugin authors)

@billyyyyy3320 Thanks for the feedback, I provided the PR #2674.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gaomd picture gaomd  路  3Comments

alinnert picture alinnert  路  3Comments

sankincn picture sankincn  路  3Comments

higuoxing picture higuoxing  路  3Comments

genedronek picture genedronek  路  3Comments