core icon indicating copy to clipboard operation
core copied to clipboard

feat: add route option (close #1505)

Open Mister-Hope opened this issue 1 year ago • 6 comments

[!warning] This PR is now based on https://github.com/vuepress/core/pull/1562, so it's expected #1562 to be merged first.

[!tip] For a file like /a/b.md, the full format is /a/b.html and clean format is /a/b

Features

This pr adds route option for vuepress config file.

  • New route.cleanUrl option to support the "clean format"
  • pagePatterns and permalinkPatten is moved to route.pagePatterns and route.permalinkPatten

Bug Fixes

Previously, when use manually set a permalink or page path to a clean format like /a, they will always get 404 when trying to visit the page (in any link format). Now, this is correctly handled. Page path will be normalized to a "full" or "clean" version based on cleanUrl, no matter user use "clean", "full" format or mixing them.

Performance Improvements

Now, the key in routes is always the clean format, which avoid outputting uncessary .html suffix for most pages.

Potential Breaking Changes

  • Now inferRoutePath and normalizeRoutePath return the "clean" format instead of "full" format.

Tweaks

Now a new field called routeKey is on the Page object.

Mister-Hope avatar Apr 11 '24 16:04 Mister-Hope

Pull Request Test Coverage Report for Build 13690296414

Details

  • 17 of 18 (94.44%) changed or added relevant lines in 8 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 71.873%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/cli/src/commands/dev/watchPageFiles.ts 0 1 0.0%
<!-- Total: 17 18
Totals Coverage Status
Change from base Build 13616164910: 0.2%
Covered Lines: 654
Relevant Lines: 912

💛 - Coveralls

coveralls avatar May 16 '24 02:05 coveralls

now e2e test is added in this PR

Mister-Hope avatar May 24 '24 05:05 Mister-Hope

image

A little weird to me, I can not reproduce the CI result locally

Mister-Hope avatar May 24 '24 06:05 Mister-Hope

@Mister-Hope

In the e2e/docs/components/route-link.md file, the title is Query and hash, but in the e2e/tests/components/route-link.spec.ts file, the locator is:

- .e2e-theme-content #hash-and-query + ul > li a
                      ^^^^^^^^^^^^^^
+ .e2e-theme-content #query-and-hash + ul > li a

which causes the e2e test to fail due to the inability to find the element.

pengzhanbo avatar Feb 20 '25 17:02 pengzhanbo

I would really love to see this in VuePress, this is the one thing preventing me from using it.

wilsncc avatar May 25 '25 09:05 wilsncc

If @meteorlxy is happy to review it, then I am totally fine to refine this asap.

Mister-Hope avatar May 25 '25 14:05 Mister-Hope