@@ -6,13 +6,20 @@ exports.genRoutesFile = async function ({
66 sourceDir,
77 pageFiles
88} ) {
9- function genRoute ( { path : pagePath , key : componentName } , index ) {
9+ const rssItems = [ ]
10+
11+ function genRoute ( { path : pagePath , key : componentName , frontmatter } , index ) {
1012 const file = pageFiles [ index ]
1113 const filePath = path . resolve ( sourceDir , file )
14+
15+ let cleanPagePath = pagePath . replace ( / .h t m l / g, '' )
16+ if ( cleanPagePath !== '/' && cleanPagePath . endsWith ( '/' ) ) {
17+ cleanPagePath = cleanPagePath . slice ( 0 , - 1 )
18+ }
1219 let code = `
1320 {
1421 name: ${ JSON . stringify ( componentName ) } ,
15- path: ${ JSON . stringify ( pagePath ) } ,
22+ path: ${ JSON . stringify ( cleanPagePath ) } ,
1623 component: ThemeLayout,
1724 beforeEnter: (to, from, next) => {
1825 import(${ JSON . stringify ( filePath ) } ).then(comp => {
@@ -22,20 +29,28 @@ exports.genRoutesFile = async function ({
2229 }
2330 }`
2431
32+ if ( ! frontmatter . top_page ) {
33+ rssItems . push ( {
34+ title : frontmatter . title ,
35+ path : cleanPagePath ,
36+ date : frontmatter . date
37+ } )
38+ }
39+
2540 const dncodedPath = decodeURIComponent ( pagePath )
2641 if ( dncodedPath !== pagePath ) {
2742 code += `,
2843 {
2944 path: ${ JSON . stringify ( dncodedPath ) } ,
30- redirect: ${ JSON . stringify ( pagePath ) }
45+ redirect: ${ JSON . stringify ( cleanPagePath ) }
3146 }`
3247 }
3348
3449 if ( / \/ $ / . test ( pagePath ) ) {
3550 code += `,
3651 {
3752 path: ${ JSON . stringify ( pagePath + 'index.html' ) } ,
38- redirect: ${ JSON . stringify ( pagePath ) }
53+ redirect: ${ JSON . stringify ( cleanPagePath ) }
3954 }`
4055 }
4156
@@ -48,15 +63,22 @@ exports.genRoutesFile = async function ({
4863 component: ThemeNotFound
4964 }`
5065
51- return (
66+ const generatedRoutes = pages . map ( genRoute )
67+
68+ const routesCode = (
5269 `import ThemeLayout from '@themeLayout'\n` +
5370 `import ThemeNotFound from '@themeNotFound'\n` +
5471 `import { injectMixins } from '@app/util'\n` +
5572 `import rootMixins from '@app/root-mixins'\n\n` +
5673 `injectMixins(ThemeLayout, rootMixins)\n` +
5774 `injectMixins(ThemeNotFound, rootMixins)\n\n` +
58- `export const routes = [${ pages . map ( genRoute ) . join ( ',' ) } ${ notFoundRoute } \n]`
75+ `export const routes = [${ generatedRoutes . join ( ',' ) } ${ notFoundRoute } \n]`
5976 )
77+
78+ return {
79+ routesCode,
80+ rssItems
81+ }
6082}
6183
6284exports . genComponentRegistrationFile = async function ( { sourceDir } ) {
0 commit comments