File tree Expand file tree Collapse file tree 5 files changed +38
-9
lines changed Expand file tree Collapse file tree 5 files changed +38
-9
lines changed Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < title > Dev pages</ title >
7+ < script type ="module " src ="../common.js "> </ script >
8+ </ head >
9+ < body >
10+ < h1 > Charts development pages</ h1 >
11+
12+ < ul id ="listing "> </ ul >
13+ </ body >
14+ </ html >
Original file line number Diff line number Diff line change 22< html lang ="en ">
33 < head >
44 < meta charset ="UTF-8 " />
5- < meta http-equiv ="X-UA-Compatible " content ="IE=edge " />
65 < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
76 < title > Dev pages</ title >
87 < script type ="module " src ="./common.js "> </ script >
Original file line number Diff line number Diff line change @@ -12,7 +12,13 @@ export default {
1212 nodeResolve ( ) ,
1313 html ( {
1414 flattenOutput : false , // Preserve "charts" folder
15- transformHtml : [ ( html ) => appendStyles ( html ) , ( html ) => generateListing ( html ) ] ,
15+ transformHtml : [
16+ ( html ) => appendStyles ( html ) ,
17+ ( html , { htmlFileName } ) => {
18+ const folderPath = htmlFileName === 'charts/index.html' ? '/charts' : '' ;
19+ return generateListing ( html , `.${ folderPath } ` ) ;
20+ } ,
21+ ] ,
1622 transformAsset : [
1723 async ( content , filePath ) => {
1824 if ( filePath . endsWith ( '.css' ) ) {
Original file line number Diff line number Diff line change @@ -24,18 +24,23 @@ export function appendStyles(html) {
2424export function generateListing ( html , dir , path ) {
2525 if ( html . includes ( '<ul id="listing">' ) ) {
2626 // Add <base> to make index.html work when opening
27- // http://localhost:8000/dev without trailing slash
28- if ( path && path . endsWith ( '/dev' ) ) {
29- html = html . replace ( '<head>' , '<head>\n<base href="dev/">' ) ;
27+ // http://localhost:8000/dev or http://localhost:8000/dev/charts without trailing slash
28+ const match = / \/ (?< section > d e v | c h a r t s ) $ / u. exec ( path ) ;
29+ if ( match ) {
30+ html = html . replace ( '<head>' , `<head>\n<base href="${ match . groups . section } /">` ) ;
3031 }
3132
3233 const listing = `
3334 <ul id="listing">
3435 ${ fs
3536 . readdirSync ( dir || '.' )
3637 . filter ( ( file ) => file !== 'index.html' )
37- . filter ( ( file ) => file . endsWith ( '.html' ) )
38- . map ( ( file ) => `<li><a href="${ file } ">${ file } </a></li>` )
38+ . filter ( ( file ) => file . endsWith ( '.html' ) || file === 'charts' )
39+ . map (
40+ ( file ) => `<li>
41+ <a href="${ file } ${ file . endsWith ( '.html' ) ? '' : '/' } ">${ file } </a>
42+ </li>` ,
43+ )
3944 . join ( '' ) }
4045 </ul>` ;
4146
Original file line number Diff line number Diff line change @@ -76,8 +76,13 @@ export default {
7676 body = appendStyles ( body ) ;
7777
7878 // Index page listing
79- if ( [ '/dev/index.html' , '/dev' , '/dev/' ] . includes ( context . path ) ) {
80- body = generateListing ( body , './dev' , context . path ) ;
79+ const devPageMatch = / ^ \/ d e v (?: \/ (?< section > c h a r t s ) ) ? (?: \/ i n d e x \. h t m l | \/ ) ? $ / u. exec ( context . path ) ;
80+
81+ if ( devPageMatch ) {
82+ // If a group was captured, then it's in the /dev/charts path,
83+ // otherwise it should list the pages under the /dev folder
84+ const dir = devPageMatch . groups . section ? './dev/charts' : './dev' ;
85+ body = generateListing ( body , dir , context . path ) ;
8186 }
8287
8388 return { body } ;
You can’t perform that action at this time.
0 commit comments