1- import { createWriteStream , type WriteStream } from 'node:fs' ;
1+ import { createWriteStream } from 'node:fs' ;
22import { mkdir } from 'node:fs/promises' ;
33import { normalize , resolve } from 'node:path' ;
44import { pipeline , Readable } from 'node:stream' ;
55import { promisify } from 'node:util' ;
6- import type { AstroConfig } from 'astro' ;
76import { SitemapAndIndexStream , SitemapIndexStream , SitemapStream } from 'sitemap' ;
8- import replace from 'stream-replace-string' ;
97import type { SitemapItem } from './index.js' ;
108import { getLatestLastmod } from './utils/lastmod.js' ;
119
@@ -29,22 +27,19 @@ type WriteSitemapChunkConfig = {
2927} ;
3028
3129// adapted from sitemap.js/sitemap-simple
32- export async function writeSitemapChunk (
33- {
34- filenameBase,
35- hostname,
36- sitemapHostname = hostname ,
37- sourceData,
38- destinationDir,
39- limit = 50000 ,
40- customSitemaps = [ ] ,
41- publicBasePath = './' ,
42- xslURL : xslUrl ,
43- lastmod,
44- namespaces = { news : true , xhtml : true , image : true , video : true } ,
45- } : WriteSitemapChunkConfig ,
46- astroConfig : AstroConfig ,
47- ) {
30+ export async function writeSitemapChunk ( {
31+ filenameBase,
32+ hostname,
33+ sitemapHostname = hostname ,
34+ sourceData,
35+ destinationDir,
36+ limit = 50000 ,
37+ customSitemaps = [ ] ,
38+ publicBasePath = './' ,
39+ xslURL : xslUrl ,
40+ lastmod,
41+ namespaces = { news : true , xhtml : true , image : true , video : true } ,
42+ } : WriteSitemapChunkConfig ) {
4843 await mkdir ( destinationDir , { recursive : true } ) ;
4944
5045 // Normalize publicBasePath
@@ -78,18 +73,7 @@ export async function writeSitemapChunk(
7873 const writePath = resolve ( destinationDir , path ) ;
7974 const publicPath = normalize ( normalizedPublicBasePath + path ) ;
8075
81- let stream : WriteStream ;
82- if ( astroConfig . trailingSlash === 'never' || astroConfig . build . format === 'file' ) {
83- // workaround for trailing slash issue in sitemap.js
84- const host = hostname . endsWith ( '/' ) ? hostname . slice ( 0 , - 1 ) : hostname ;
85- const searchStr = `<loc>${ host } /</loc>` ;
86- const replaceStr = `<loc>${ host } </loc>` ;
87- stream = sitemapStream
88- . pipe ( replace ( searchStr , replaceStr ) )
89- . pipe ( createWriteStream ( writePath ) ) ;
90- } else {
91- stream = sitemapStream . pipe ( createWriteStream ( writePath ) ) ;
92- }
76+ const stream = sitemapStream . pipe ( createWriteStream ( writePath ) ) ;
9377
9478 const url = new URL ( publicPath , sitemapHostname ) . toString ( ) ;
9579 // Stamp this index entry with the freshest lastmod among the
0 commit comments