Skip to content

Commit

Permalink
fix(vite-plugin-nitro): pass public output path to sitemap builder (#601
Browse files Browse the repository at this point in the history
)
  • Loading branch information
brandonroberts authored Aug 10, 2023
1 parent b82e9fe commit 94e7568
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/vite-plugin-nitro/src/lib/build-sitemap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('build sitemap', () => {

it('should not perform functionality if no predefined routes are present', () => {
const spy = vi.spyOn(fs, 'writeFileSync');
buildSitemap(config, sitemapConfig, []);
buildSitemap(config, sitemapConfig, [], '');

expect(spy).not.toHaveBeenCalled();
});
Expand Down
9 changes: 3 additions & 6 deletions packages/vite-plugin-nitro/src/lib/build-sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export type PagesJson = {
export async function buildSitemap(
config: UserConfig,
sitemapConfig: SitemapConfig,
routes: string[] | (() => Promise<(string | undefined)[]>)
routes: string[] | (() => Promise<(string | undefined)[]>),
outputDir: string
) {
const routeList: string[] = await optionHasRoutes(routes);

Expand All @@ -32,11 +33,7 @@ export async function buildSitemap(
page.ele('lastmod').txt(item.lastMod);
}

const mapPath = `${path.resolve(
'dist',
config.root || '.',
'analog/public'
)}/sitemap.xml`;
const mapPath = `${path.resolve(outputDir)}/sitemap.xml`;
try {
console.log(`Writing sitemap at ${mapPath}`);
fs.writeFileSync(mapPath, sitemap.end({ prettyPrint: true }));
Expand Down
6 changes: 4 additions & 2 deletions packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ describe('nitro', () => {
expect(buildSitemapImportSpy).toHaveBeenCalledWith(
{},
{ host: 'example.com' },
prerenderRoutes.prerender.routes
prerenderRoutes.prerender.routes,
expect.anything()
);
});

Expand Down Expand Up @@ -171,7 +172,8 @@ describe('nitro', () => {
expect(buildSitemapImportSpy).toHaveBeenCalledWith(
{},
{ host: 'example.com' },
prerenderRoutes.prerender.routes
prerenderRoutes.prerender.routes,
expect.anything()
);
});

Expand Down
3 changes: 2 additions & 1 deletion packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ export function nitro(options?: Options, nitroOptions?: NitroConfig): Plugin[] {
await buildSitemap(
config,
options.prerender.sitemap,
options.prerender.routes!
options.prerender.routes!,
nitroConfig.output?.publicDir!
);
}

Expand Down

0 comments on commit 94e7568

Please sign in to comment.