Skip to content

Commit 24fa52c

Browse files
committed
new stylesheet option for sitemap
1 parent 2f3d7c6 commit 24fa52c

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Go to the `v1` branch to see the changelog of Lume 1.
2424
- `katex`: `cssFile`, `placeholder` and `fontsFolder` option. The plugin downloads the CSS code.
2525
- `icons` plugin: Added css.gg and radix-ui.com/icons [#736]
2626
- `feed` plugin: Allow to pass an array of options or a function that return an array of options.
27+
- `sitemap` plugin: New option `stylesheet`.
2728

2829
### Changed
2930
- `Temporal` API is enabled by default.

plugins/sitemap.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export interface Options {
1919
/** The sitemap file name */
2020
filename?: string;
2121

22+
/** The xml-stylesheet document for styling */
23+
stylesheet?: string;
24+
2225
/**
2326
* The query to search pages included in the sitemap
2427
* @default "isRedirect!=true" excludes redirect pages produced by the redirects plugin
@@ -128,7 +131,15 @@ export function sitemap(userOptions?: Options) {
128131
},
129132
};
130133

131-
return stringify(sitemap);
134+
const result = stringify(sitemap);
135+
return options.stylesheet
136+
? result.replace(
137+
'<?xml version="1.0" encoding="UTF-8"?>',
138+
`<?xml version="1.0" encoding="UTF-8"?>\n<?xml-stylesheet type="text/xsl" href="${
139+
site.url(options.stylesheet)
140+
}"?>`,
141+
)
142+
: result;
132143
}
133144
};
134145
}

tests/__snapshots__/sitemap.test.ts.snap

+2
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ Sitemap: https://example.com/sitemap.xml",
436436
},
437437
{
438438
content: '<?xml version="1.0" encoding="UTF-8"?>
439+
<?xml-stylesheet type="text/xsl" href="/sitemap-style.xml"?>
439440
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
440441
<url>
441442
<loc>https://example.com/overrided-page2/</loc>
@@ -465,6 +466,7 @@ Sitemap: https://example.com/sitemap.xml",
465466
data: {
466467
basename: "sitemap",
467468
content: '<?xml version="1.0" encoding="UTF-8"?>
469+
<?xml-stylesheet type="text/xsl" href="/sitemap-style.xml"?>
468470
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
469471
<url>
470472
<loc>https://example.com/overrided-page2/</loc>

tests/sitemap.test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ Deno.test("Sitemap plugin", async (t) => {
1111
location: new URL("https://example.com/"),
1212
});
1313

14-
site.use(sitemap());
14+
site.use(sitemap({
15+
stylesheet: "/sitemap-style.xml",
16+
}));
1517
site.use(extractDate());
1618
site.ignore("static.yml");
1719

0 commit comments

Comments
 (0)