Skip to content

Commit

Permalink
Fix output malformed on non-root base (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
zerodevx authored Feb 14, 2022
1 parent 75a4d84 commit 359430b
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 67 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Adds a trailing slash to all URLs like so:

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

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

Expand Down
124 changes: 62 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "static-sitemap-cli",
"version": "2.1.0",
"version": "2.1.1",
"description": "CLI to generate XML sitemaps for static sites from local filesystem",
"author": "Jason Lee <[email protected]>",
"type": "module",
Expand All @@ -12,7 +12,7 @@
"scripts": {
"format": "prettier --ignore-path .gitignore --write .",
"lint": "eslint --ignore-path .gitignore .",
"test": "ava"
"test": "npm run format && npm run lint && ava"
},
"dependencies": {
"commander": "^9.0.0",
Expand All @@ -25,9 +25,9 @@
},
"devDependencies": {
"ava": "^4.0.1",
"eslint": "^8.8.0",
"eslint": "^8.9.0",
"eslint-config-prettier": "^8.3.0",
"execa": "^6.0.0",
"execa": "^6.1.0",
"prettier": "^2.5.1"
},
"engines": {
Expand Down
1 change: 1 addition & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ try {
} catch {
program.error('Error: base is not a valid URL')
}
if (!opts.base.endsWith('/')) opts.base += '/'

if (opts.changefreq && opts.changefreq.length) {
const frequencies = ['always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'never']
Expand Down
16 changes: 16 additions & 0 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,19 @@ test('match media assets', (t) => {
const { stdout } = run('fixtures', '-m', '**/*.{jpg,png}', '-o', '-f', 'txt')
t.is(stdout, 'https://x.com/media/cats.jpg\nhttps://x.com/media/dogs.png')
})

test('output not malformed if base is non-root', (t) => {
const run2 = (root, ...args) =>
execaSync('node', [
path.join(__testdir, '..', 'src', 'cli.js'),
'-b',
'https://x.com/foo',
'-r',
path.join(__testdir, ...root.split('/')),
...args
])
const { stdout } = run2('fixtures/about', '-o', '-f', 'txt')
t.is(stdout, 'https://x.com/foo')
const { stdout: stdout2 } = run2('fixtures/about', '-o', '-f', 'txt', '--slash')
t.is(stdout2, 'https://x.com/foo/')
})

0 comments on commit 359430b

Please sign in to comment.