File tree Expand file tree Collapse file tree 4 files changed +49
-9
lines changed
theme/components/Overview Expand file tree Collapse file tree 4 files changed +49
-9
lines changed Original file line number Diff line number Diff line change @@ -37,5 +37,6 @@ export {
3737 normalizeImagePath ,
3838 removeBase ,
3939 removeTrailingSlash ,
40+ routePathToMdPath ,
4041 withBase ,
4142} from './utils' ;
Original file line number Diff line number Diff line change 1+ import { describe , expect , it , rs } from '@rstest/core' ;
2+ import { routePathToMdPath } from './utils' ;
3+
4+ rs . mock ( 'virtual-site-data' , ( ) => {
5+ return {
6+ default : {
7+ base : '/' ,
8+ } ,
9+ } ;
10+ } ) ;
11+
12+ describe ( 'routePathToMdPath' , ( ) => {
13+ it ( 'should match snapshot for various paths' , ( ) => {
14+ const cases = [
15+ '/foo/bar.html' ,
16+ '/foo/bar.html#hash' ,
17+ '/foo/bar.html?q=1' ,
18+ '/foo/bar.html?q=1#hash' ,
19+ '/foo.html' ,
20+ '/simple.html#my-heading' ,
21+ '/query.html?foo=bar&baz=qux' ,
22+ '/complex.html?id=123#section-2' ,
23+ ] ;
24+
25+ const results = cases . map ( path => routePathToMdPath ( path ) ) ;
26+ expect ( results ) . toMatchInlineSnapshot ( `
27+ [
28+ "/foo/bar.md",
29+ "/foo/bar.md#hash",
30+ "/foo/bar.md?q=1",
31+ "/foo/bar.md?q=1#hash",
32+ "/foo.md",
33+ "/simple.md#my-heading",
34+ "/query.md?foo=bar&baz=qux",
35+ "/complex.md?id=123#section-2",
36+ ]
37+ ` ) ;
38+ } ) ;
39+ } ) ;
Original file line number Diff line number Diff line change @@ -53,6 +53,13 @@ function normalizeImagePath(imagePath: string) {
5353 return withBase ( imagePath ) ;
5454}
5555
56+ function routePathToMdPath ( routePath : string ) : string {
57+ let url : string = routePath ;
58+ url = normalizeHref ( url , false ) ;
59+ url = url . replace ( / \. h t m l (? = # | \? | $ ) / , '.md' ) ;
60+ return withBase ( url ) ;
61+ }
62+
5663function isAbsoluteUrl ( path : string ) {
5764 return isExternalUrl ( path ) || isDataUrl ( path ) || path . startsWith ( '//' ) ;
5865}
@@ -67,4 +74,5 @@ export {
6774 withBase ,
6875 isEqualPath ,
6976 normalizeHrefInRuntime ,
77+ routePathToMdPath ,
7078} ;
Original file line number Diff line number Diff line change @@ -6,11 +6,10 @@ import type {
66} from '@rspress/core' ;
77import {
88 isEqualPath ,
9- normalizeHref ,
9+ routePathToMdPath ,
1010 useI18n ,
1111 usePageData ,
1212 useSidebar ,
13- withBase ,
1413} from '@rspress/core/runtime' ;
1514import {
1615 FallbackHeading ,
@@ -27,13 +26,6 @@ import {
2726import './index.scss' ;
2827import { findItemByRoutePath } from './utils' ;
2928
30- function routePathToMdPath ( routePath : string ) : string {
31- let url : string = routePath ;
32- url = normalizeHref ( url , false ) ;
33- url = url . replace ( / \. h t m l $ / , '.md' ) ;
34- return withBase ( url ) ;
35- }
36-
3729function OverviewMarkdown ( {
3830 title,
3931 groups,
You can’t perform that action at this time.
0 commit comments