@@ -10,8 +10,8 @@ function log(msg) {
1010 console . warn ( '\x1b[36m%s\x1b[0m' , `[sscli] ${ msg } ` )
1111}
1212
13- async function getFiles ( { root, ignore, verbose } ) {
14- const files = await fastglob ( '**/*.html' , { cwd : root , stats : true , ignore } )
13+ async function getFiles ( { root, match , ignore, verbose } ) {
14+ const files = await fastglob ( match , { cwd : root , stats : true , ignore } )
1515 if ( ! files . length ) {
1616 throw new Error ( 'NO_MATCHES' )
1717 }
@@ -43,16 +43,18 @@ function detectNoindex(path) {
4343}
4444
4545async function transformUrl (
46- file ,
46+ { path , stats : { mtime } } ,
4747 { root, base, changefreq, priority, robots, clean, slash, verbose }
4848) {
49- if ( robots ) {
50- if ( await detectNoindex ( nodepath . join ( root , file . path ) ) ) {
51- if ( verbose ) log ( `noindex: ${ file . path } ` )
52- return
53- }
49+ if (
50+ robots &&
51+ nodepath . extname ( path ) === '.html' &&
52+ ( await detectNoindex ( nodepath . join ( root , path ) ) )
53+ ) {
54+ if ( verbose ) log ( `noindex: ${ path } ` )
55+ return
5456 }
55- let url = base + file . path . split ( nodepath . sep ) . join ( '/' )
57+ let url = base + path . split ( nodepath . sep ) . join ( '/' )
5658 if ( clean ) {
5759 if ( url . slice ( - 11 ) === '/index.html' ) url = url . slice ( 0 , - 11 )
5860 else if ( url . slice ( - 5 ) === '.html' ) url = url . slice ( 0 , - 5 )
@@ -61,12 +63,12 @@ async function transformUrl(
6163 const check = ( pairs , tagname ) => {
6264 for ( let a = pairs . length - 1 ; a >= 0 ; a -- ) {
6365 const p = pairs [ a ] . split ( ',' )
64- if ( micromatch . isMatch ( file . path , p [ 0 ] ) ) return { [ tagname ] : p [ 1 ] }
66+ if ( micromatch . isMatch ( path , p [ 0 ] ) ) return { [ tagname ] : p [ 1 ] }
6567 }
6668 }
6769 return {
6870 loc : url ,
69- lastmod : file . stats . mtime . toISOString ( ) ,
71+ lastmod : mtime . toISOString ( ) ,
7072 ...( changefreq && changefreq . length && check ( changefreq , 'changefreq' ) ) ,
7173 ...( priority && priority . length && check ( priority , 'priority' ) )
7274 }
0 commit comments