|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { describe, it } from 'node:test'; |
| 3 | + |
| 4 | +import { setConfig } from '@doc-kit/core/utils/configuration/index.mjs'; |
| 5 | + |
| 6 | +import { generate } from '../generate.mjs'; |
| 7 | + |
| 8 | +const config = await setConfig({ target: ['sitemap'] }); |
| 9 | + |
| 10 | +config.sitemap.output = undefined; |
| 11 | +config.sitemap.baseURL = 'https://example.com'; |
| 12 | + |
| 13 | +const entry = (api, depth = 1) => ({ |
| 14 | + api, |
| 15 | + path: `/${api}`, |
| 16 | + heading: { depth }, |
| 17 | +}); |
| 18 | + |
| 19 | +const extractLocations = sitemap => |
| 20 | + Array.from(sitemap.matchAll(/<loc>(.*?)<\/loc>/g), match => match[1]); |
| 21 | + |
| 22 | +describe('sitemap', () => { |
| 23 | + it('lists depth-1 pages alongside the index URL', async () => { |
| 24 | + const sitemap = await generate([ |
| 25 | + entry('fs', 1), |
| 26 | + entry('fs', 2), |
| 27 | + entry('http', 1), |
| 28 | + ]); |
| 29 | + |
| 30 | + assert.deepEqual(extractLocations(sitemap), [ |
| 31 | + 'https://example.com/fs.html', |
| 32 | + 'https://example.com/http.html', |
| 33 | + 'https://example.com/', |
| 34 | + ]); |
| 35 | + }); |
| 36 | + |
| 37 | + it('does not list the index page twice when index.md is an input', async () => { |
| 38 | + const sitemap = await generate([entry('index', 1), entry('foo', 1)]); |
| 39 | + |
| 40 | + assert.deepEqual(extractLocations(sitemap), [ |
| 41 | + 'https://example.com/foo.html', |
| 42 | + 'https://example.com/', |
| 43 | + ]); |
| 44 | + }); |
| 45 | +}); |
0 commit comments