@@ -8,73 +8,74 @@ import { fileURLToPath } from 'node:url'
88const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
99const packageJsonPath = path . resolve ( __dirname , '..' , '..' , 'package.json' )
1010const buildPagesScriptPath = path . resolve ( __dirname , '..' , 'scripts' , 'build-pages.mjs' )
11+ const configPath = path . resolve ( __dirname , '..' , 'config.ts' )
1112const docsRoot = path . resolve ( __dirname , '..' , '..' )
1213const distRoot = path . resolve ( docsRoot , '.vitepress' , 'dist' )
1314
14- let cachedLandingPages
15+ const cachedLandingPages = new Map ( )
1516
16- function readBuiltLandingPages ( ) {
17- if ( ! cachedLandingPages ) {
17+ function readBuiltLandingPages ( base = '/cpp-high-performance-guide/' ) {
18+ if ( ! cachedLandingPages . has ( base ) ) {
1819 const result = spawnSync ( process . execPath , [ buildPagesScriptPath ] , {
1920 cwd : docsRoot ,
2021 encoding : 'utf8' ,
22+ env : {
23+ ...process . env ,
24+ VITEPRESS_BASE : base ,
25+ } ,
2126 } )
2227
2328 assert . equal ( result . status , 0 , result . stderr || result . stdout || 'build:pages failed' )
2429
25- cachedLandingPages = {
30+ cachedLandingPages . set ( base , {
2631 en : fs . readFileSync ( path . join ( distRoot , 'en' , 'index.html' ) , 'utf8' ) ,
2732 zh : fs . readFileSync ( path . join ( distRoot , 'zh' , 'index.html' ) , 'utf8' ) ,
2833 exercisesIndexExists : fs . existsSync ( path . join ( distRoot , 'en' , 'exercises' , 'index.html' ) ) ,
2934 exercisesReadmeExists : fs . existsSync ( path . join ( distRoot , 'en' , 'exercises' , 'README.html' ) ) ,
30- }
35+ } )
3136 }
3237
33- return cachedLandingPages
38+ return cachedLandingPages . get ( base )
3439}
3540
36- test ( 'build:pages uses a cross-platform Node wrapper for the GitHub Pages base path' , ( ) => {
41+ test ( 'docs config keeps clean URLs disabled for static hosting' , ( ) => {
42+ const config = fs . readFileSync ( configPath , 'utf8' )
43+
44+ assert . match ( config , / c l e a n U r l s : \s * f a l s e / )
45+ assert . doesNotMatch ( config , / c l e a n U r l s : \s * t r u e / )
46+ } )
47+
48+ test ( 'build:pages uses a cross-platform Node wrapper while preserving external base paths' , ( ) => {
3749 const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf8' ) )
3850 const buildPagesScript = fs . readFileSync ( buildPagesScriptPath , 'utf8' )
3951
4052 assert . equal ( packageJson . scripts [ 'build:pages' ] , 'node .vitepress/scripts/build-pages.mjs' )
4153 assert . match ( buildPagesScript , / V I T E P R E S S _ B A S E / )
4254 assert . match ( buildPagesScript , / \/ c p p - h i g h - p e r f o r m a n c e - g u i d e \/ / )
4355 assert . match ( buildPagesScript , / v i t e p r e s s / )
56+ assert . match ( buildPagesScript , / p r o c e s s \. e n v \. V I T E P R E S S _ B A S E \s * \| \| / )
4457} )
4558
46- test ( 'build:pages prefixes homepage landing links with the GitHub Pages base' , ( ) => {
59+ test ( 'build:pages prefixes homepage landing links with the GitHub Pages base and .html leaf routes ' , ( ) => {
4760 const { en, zh } = readBuiltLandingPages ( )
4861
4962 for ( const href of [
5063 '/cpp-high-performance-guide/en/reference/' ,
51- '/cpp-high-performance-guide/en/getting-started/quickstart' ,
52- '/cpp-high-performance-guide/en/guides/learning-path' ,
53- '/cpp-high-performance-guide/en/exercises/module-02-memory' ,
54- '/cpp-high-performance-guide/en/exercises/module-04-simd' ,
55- '/cpp-high-performance-guide/en/exercises/module-05-concurrency' ,
56- '/cpp-high-performance-guide/en/getting-started/prerequisites' ,
57- '/cpp-high-performance-guide/en/guides/profiling-guide' ,
58- '/cpp-high-performance-guide/en/guides/optimization-decision-tree' ,
59- '/cpp-high-performance-guide/en/guides/validation' ,
60- '/cpp-high-performance-guide/en/guides/best-practices' ,
64+ '/cpp-high-performance-guide/en/getting-started/quickstart.html' ,
65+ '/cpp-high-performance-guide/en/guides/learning-path.html' ,
66+ '/cpp-high-performance-guide/en/guides/validation.html' ,
67+ '/cpp-high-performance-guide/en/contributing/ai-workflow.html' ,
6168 '/cpp-high-performance-guide/zh/' ,
6269 ] ) {
6370 assert . match ( en , new RegExp ( `href="${ href . replaceAll ( '/' , '\\/' ) } "` ) )
6471 }
6572
6673 for ( const href of [
6774 '/cpp-high-performance-guide/zh/reference/' ,
68- '/cpp-high-performance-guide/zh/getting-started/quickstart' ,
69- '/cpp-high-performance-guide/zh/guides/learning-path' ,
70- '/cpp-high-performance-guide/en/exercises/module-02-memory' ,
71- '/cpp-high-performance-guide/en/exercises/module-04-simd' ,
72- '/cpp-high-performance-guide/en/exercises/module-05-concurrency' ,
73- '/cpp-high-performance-guide/zh/getting-started/prerequisites' ,
74- '/cpp-high-performance-guide/zh/guides/profiling-guide' ,
75- '/cpp-high-performance-guide/zh/guides/optimization-decision-tree' ,
76- '/cpp-high-performance-guide/zh/guides/validation' ,
77- '/cpp-high-performance-guide/zh/guides/best-practices' ,
75+ '/cpp-high-performance-guide/zh/getting-started/quickstart.html' ,
76+ '/cpp-high-performance-guide/zh/guides/learning-path.html' ,
77+ '/cpp-high-performance-guide/zh/guides/validation.html' ,
78+ '/cpp-high-performance-guide/zh/contributing/ai-workflow.html' ,
7879 '/cpp-high-performance-guide/en/' ,
7980 ] ) {
8081 assert . match ( zh , new RegExp ( `href="${ href . replaceAll ( '/' , '\\/' ) } "` ) )
@@ -84,14 +85,8 @@ test('build:pages prefixes homepage landing links with the GitHub Pages base', (
8485 'href="/en/reference/"' ,
8586 'href="/en/getting-started/quickstart"' ,
8687 'href="/en/guides/learning-path"' ,
87- 'href="/en/exercises/module-02-memory"' ,
88- 'href="/en/exercises/module-04-simd"' ,
89- 'href="/en/exercises/module-05-concurrency"' ,
90- 'href="/en/getting-started/prerequisites"' ,
91- 'href="/en/guides/profiling-guide"' ,
92- 'href="/en/guides/optimization-decision-tree"' ,
9388 'href="/en/guides/validation"' ,
94- 'href="/en/guides/best-practices "' ,
89+ 'href="/en/contributing/ai-workflow "' ,
9590 'href="/zh/"' ,
9691 ] ) {
9792 assert . doesNotMatch ( en , new RegExp ( rawHref . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' ) ) )
@@ -101,20 +96,26 @@ test('build:pages prefixes homepage landing links with the GitHub Pages base', (
10196 'href="/zh/reference/"' ,
10297 'href="/zh/getting-started/quickstart"' ,
10398 'href="/zh/guides/learning-path"' ,
104- 'href="/zh/getting-started/prerequisites"' ,
105- 'href="/zh/guides/profiling-guide"' ,
106- 'href="/zh/guides/optimization-decision-tree"' ,
10799 'href="/zh/guides/validation"' ,
108- 'href="/zh/guides/best-practices "' ,
100+ 'href="/zh/contributing/ai-workflow "' ,
109101 'href="/en/"' ,
110- 'href="/en/exercises/module-02-memory"' ,
111- 'href="/en/exercises/module-04-simd"' ,
112- 'href="/en/exercises/module-05-concurrency"' ,
113102 ] ) {
114103 assert . doesNotMatch ( zh , new RegExp ( rawHref . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' ) ) )
115104 }
116105} )
117106
107+ test ( 'build:pages preserves an externally supplied base path' , ( ) => {
108+ const { en, zh } = readBuiltLandingPages ( '/custom-base/' )
109+
110+ assert . match ( en , / h r e f = " \/ c u s t o m - b a s e \/ e n \/ g e t t i n g - s t a r t e d \/ q u i c k s t a r t \. h t m l " / )
111+ assert . match ( en , / h r e f = " \/ c u s t o m - b a s e \/ z h \/ " / )
112+ assert . doesNotMatch ( en , / h r e f = " \/ c p p - h i g h - p e r f o r m a n c e - g u i d e \/ e n \/ g e t t i n g - s t a r t e d \/ q u i c k s t a r t \. h t m l " / )
113+
114+ assert . match ( zh , / h r e f = " \/ c u s t o m - b a s e \/ z h \/ g e t t i n g - s t a r t e d \/ q u i c k s t a r t \. h t m l " / )
115+ assert . match ( zh , / h r e f = " \/ c u s t o m - b a s e \/ e n \/ " / )
116+ assert . doesNotMatch ( zh , / h r e f = " \/ c p p - h i g h - p e r f o r m a n c e - g u i d e \/ z h \/ g e t t i n g - s t a r t e d \/ q u i c k s t a r t \. h t m l " / )
117+ } )
118+
118119test ( 'build:pages emits the exercises overview as a clean index route' , ( ) => {
119120 const { exercisesIndexExists, exercisesReadmeExists } = readBuiltLandingPages ( )
120121
0 commit comments