@@ -8,30 +8,25 @@ const { createSitemap } = require('sitemap')
88
99const ensureTrailingSlash = ( url ) => ( url . endsWith ( '/' ) ? url : `${ url } /` )
1010
11- const getPaths = async ( { distPath, exclude, cwd } ) => {
12- const htmlFiles = `${ distPath } /**/**.html`
13- const excludeFiles = ( exclude || [ ] ) . map ( ( filePath ) => `!${ filePath . replace ( / ^ ! / , '' ) } ` )
11+ const getPaths = async ( { distPath, exclude = [ ] , cwd = '.' } ) => {
12+ const htmlFiles = `${ getRelPath ( distPath , cwd ) } /**/**.html`
13+ const excludeFiles = exclude . map ( ( excludedPath ) => `!${ getRelPath ( excludedPath , cwd ) . replace ( / ^ ! / , '' ) } ` )
1414
15- const lookup = [ htmlFiles ] . concat ( excludeFiles )
15+ const lookup = [ htmlFiles , ... excludeFiles ]
1616 const paths = await globby ( lookup , { cwd } )
1717 return paths
1818}
1919
20- const normalizeFile = ( { file, distPath } ) => {
21- // handle root distPath
22- if ( distPath === '.' ) {
23- return `/${ file } `
24- }
25-
26- if ( file . startsWith ( distPath ) ) {
27- return file . replace ( distPath , '' )
28- }
29-
30- return distPath
20+ // Globbing patterns cannot use backslashes, but Windows use some. It cannot use
21+ // Windows drives.
22+ // Note: this does not apply to `globby` `cwd` option.
23+ const getRelPath = function ( filePath , cwd ) {
24+ const relPath = path . isAbsolute ( filePath ) ? path . relative ( cwd , filePath ) : filePath
25+ return relPath . replace ( / \\ / g, '/' )
3126}
3227
3328const prettifyUrl = ( { url, trailingSlash } ) => {
34- const prettyUrl = url . replace ( / \/ i n d e x \. h t m l $ / , '' ) . replace ( / \. h t m l $ / , '' )
29+ const prettyUrl = url . replace ( / \/ ? i n d e x \. h t m l $ / , '' ) . replace ( / \. h t m l $ / , '' )
3530
3631 if ( ! trailingSlash ) {
3732 return prettyUrl
@@ -41,7 +36,7 @@ const prettifyUrl = ({ url, trailingSlash }) => {
4136}
4237
4338const getUrlFromFile = ( { file, distPath, prettyURLs, trailingSlash } ) => {
44- const url = normalizeFile ( { file , distPath } )
39+ const url = path . relative ( distPath , file )
4540
4641 if ( ! prettyURLs ) {
4742 return url
0 commit comments