Skip to content

Commit

Permalink
fix: use provided pages config
Browse files Browse the repository at this point in the history
  • Loading branch information
tlaundal committed Feb 5, 2023
1 parent f31500f commit 9cfb0e7
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
71 changes: 71 additions & 0 deletions src/internal/build-sitemap.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import test from 'ava';
import {buildPageEntries} from './build-sitemap.js';

const options = {
origin: 'http://example.com',
defaults: {
lastmod: 'lastmod',
changefreq: 'never',
priority: 1,
},
sitemapFile: 'sitemap.xml',
pages: {},
} as const;

test('buildPageEntries creates entries for all provided paths', t => {
t.deepEqual(buildPageEntries(['/', '/page'], options), [
{
...options.defaults,
loc: 'http://example.com/',
},
{
...options.defaults,
loc: 'http://example.com/page',
},
]);
});

test('buildPageEntries allows overriding values per path paths', t => {
t.deepEqual(buildPageEntries(['/', '/page'], {
...options,
pages: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'/page': {
changefreq: 'always',
},
},
}), [
{
...options.defaults,
loc: 'http://example.com/page',
changefreq: 'always',
},
{
...options.defaults,
loc: 'http://example.com/',
},
]);
});

test('buildPageEntries allows explicitly including pages', t => {
t.deepEqual(buildPageEntries(['/', '/page'], {
...options,
pages: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'/dynamic': {},
},
}), [
{
...options.defaults,
loc: 'http://example.com/dynamic',
},
{
...options.defaults,
loc: 'http://example.com/',
},
{
...options.defaults,
loc: 'http://example.com/page',
},
]);
});
6 changes: 3 additions & 3 deletions src/internal/build-sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import type {Builder} from '@sveltejs/kit';
import type {Options, PageDetails} from '..';
import {renderSitemap} from './render-sitemap.js';

function buildPageEntries(
paths: IterableIterator<string>,
export function buildPageEntries(
paths: Iterable<string>,
options: Options,
) {
const pages: Record<string, Partial<PageDetails>> = {};
const pages: Record<string, Partial<PageDetails>> = {...options.pages};
for (const path of paths) {
if (!(path in pages)) {
pages[path] = {};
Expand Down

0 comments on commit 9cfb0e7

Please sign in to comment.