Skip to content

Commit 24c4cd2

Browse files
authored
Merge pull request #65 from netlify-labs/bugs/fix-windows
Add Windows support
2 parents 5de2d55 + b7ef7e6 commit 24c4cd2

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ jobs:
1313
timeout-minutes: 30
1414
strategy:
1515
matrix:
16-
os: [ubuntu-latest, macOS-latest]
16+
os: [ubuntu-latest, macOS-latest, windows-latest]
1717
node-version: [8.12.0, 15.x]
1818
exclude:
1919
- os: macOS-latest
2020
node-version: 8.12.0
21+
- os: windows-latest
22+
node-version: 8.12.0
2123
fail-fast: false
2224
steps:
2325
- uses: actions/checkout@v2

make_sitemap.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,25 @@ const { createSitemap } = require('sitemap')
88

99
const 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

3328
const prettifyUrl = ({ url, trailingSlash }) => {
34-
const prettyUrl = url.replace(/\/index\.html$/, '').replace(/\.html$/, '')
29+
const prettyUrl = url.replace(/\/?index\.html$/, '').replace(/\.html$/, '')
3530

3631
if (!trailingSlash) {
3732
return prettyUrl
@@ -41,7 +36,7 @@ const prettifyUrl = ({ url, trailingSlash }) => {
4136
}
4237

4338
const 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

Comments
 (0)