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

Make page suffix configurable (currently fixed to .html) #2452

Closed
dennisreimann opened this issue Jun 18, 2020 · 5 comments · Fixed by #2674
Closed

Make page suffix configurable (currently fixed to .html) #2452

dennisreimann opened this issue Jun 18, 2020 · 5 comments · Fixed by #2674
Labels
status: core team review Priority issues for the core team to review type: feature request Request to add a new feature

Comments

@dennisreimann
Copy link
Contributor

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.

@dennisreimann
Copy link
Contributor Author

Inviting feedback from @bencodezen @billyyyyy3320 @kefranabg :)

@cwaring
Copy link

cwaring commented Sep 21, 2020

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?

@dennisreimann
Copy link
Contributor Author

dennisreimann commented Oct 19, 2020

I could provide a pull request – anyone from core interested in this?
Inviting feedback from @bencodezen @billyyyyy3320 @kefranabg :)

@billyyyyy3320 billyyyyy3320 added status: core team review Priority issues for the core team to review type: feature request Request to add a new feature labels Oct 19, 2020
@billyyyyy3320
Copy link
Collaborator

@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)

@dennisreimann
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: core team review Priority issues for the core team to review type: feature request Request to add a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants