Skip to content

Commit 359430b

Browse files
authored
Fix output malformed on non-root base (#15)
1 parent 75a4d84 commit 359430b

File tree

5 files changed

+84
-67
lines changed

5 files changed

+84
-67
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Adds a trailing slash to all URLs like so:
9696

9797
Disabled by default; pass option `--slash` to enable.
9898

99-
**NOTE:** Cannot be used together with `-no-clean`. Also, trailing slashes are
99+
**NOTE:** Cannot be used together with `--no-clean`. Also, trailing slashes are
100100
[always added](https://github.com/zerodevx/static-sitemap-cli/tree/v1#to-slash-or-not-to-slash) to
101101
root domains.
102102

package-lock.json

Lines changed: 62 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "static-sitemap-cli",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "CLI to generate XML sitemaps for static sites from local filesystem",
55
"author": "Jason Lee <[email protected]>",
66
"type": "module",
@@ -12,7 +12,7 @@
1212
"scripts": {
1313
"format": "prettier --ignore-path .gitignore --write .",
1414
"lint": "eslint --ignore-path .gitignore .",
15-
"test": "ava"
15+
"test": "npm run format && npm run lint && ava"
1616
},
1717
"dependencies": {
1818
"commander": "^9.0.0",
@@ -25,9 +25,9 @@
2525
},
2626
"devDependencies": {
2727
"ava": "^4.0.1",
28-
"eslint": "^8.8.0",
28+
"eslint": "^8.9.0",
2929
"eslint-config-prettier": "^8.3.0",
30-
"execa": "^6.0.0",
30+
"execa": "^6.1.0",
3131
"prettier": "^2.5.1"
3232
},
3333
"engines": {

src/cli.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ try {
5050
} catch {
5151
program.error('Error: base is not a valid URL')
5252
}
53+
if (!opts.base.endsWith('/')) opts.base += '/'
5354

5455
if (opts.changefreq && opts.changefreq.length) {
5556
const frequencies = ['always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'never']

test/spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,19 @@ test('match media assets', (t) => {
8888
const { stdout } = run('fixtures', '-m', '**/*.{jpg,png}', '-o', '-f', 'txt')
8989
t.is(stdout, 'https://x.com/media/cats.jpg\nhttps://x.com/media/dogs.png')
9090
})
91+
92+
test('output not malformed if base is non-root', (t) => {
93+
const run2 = (root, ...args) =>
94+
execaSync('node', [
95+
path.join(__testdir, '..', 'src', 'cli.js'),
96+
'-b',
97+
'https://x.com/foo',
98+
'-r',
99+
path.join(__testdir, ...root.split('/')),
100+
...args
101+
])
102+
const { stdout } = run2('fixtures/about', '-o', '-f', 'txt')
103+
t.is(stdout, 'https://x.com/foo')
104+
const { stdout: stdout2 } = run2('fixtures/about', '-o', '-f', 'txt', '--slash')
105+
t.is(stdout2, 'https://x.com/foo/')
106+
})

0 commit comments

Comments
 (0)