Skip to content

Commit

Permalink
Dynamic Sitemap - cleanup (ProjectEvergreen#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstockdi committed Jul 21, 2024
1 parent db619c8 commit 076ce0f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 52 deletions.
50 changes: 0 additions & 50 deletions packages/cli/src/plugins/resource/plugin-resouce-sitemap.js

This file was deleted.

46 changes: 46 additions & 0 deletions packages/plugin-adapter-sitemap/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,50 @@ const greenwoodPluginAdapterSitemap = (options = {}) => [{
}
}];


/*
*
* Sitemap
*
*/

import { ResourceInterface } from '@greenwood/cli/src/lib/resource-interface.js';

class SitemapResource extends ResourceInterface {
constructor(compilation, options) {
super(compilation, options);
}

async shouldServe(url) {
return url.pathname.endsWith('sitemap.xml')
}


async serve(url) {

//TODO: check if module exists

const { projectDirectory } = this.compilation.context;

try {
const sitemapModule = await import(`${projectDirectory}/src/sitemap.xml.js`);
const sitemap = await sitemapModule.generateSitemap(this.compilation);
return new Response(sitemap, { headers: { 'Content-Type': 'text/xml' } });

} catch (error) {
console.error('Error loading module: ./sitemap.xml.js', error);
return new Response("<error>Sitemap oops.</error>", { headers: { 'Content-Type': 'text/xml' } });
}

}

}

const greenwoodPluginResourceSitemap = {
type: 'resource',
name: 'plugin-sitemap',
provider: (compilation, options) => new SitemapResource(compilation, options)
};

export { greenwoodPluginResourceSitemap };
export { greenwoodPluginAdapterSitemap };
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

import { greenwoodPluginAdapterSitemap } from '../../../src/index.js';
import { greenwoodPluginAdapterSitemap, greenwoodPluginResourceSitemap } from '../../../src/index.js';

export default {
plugins: [
greenwoodPluginAdapterSitemap()
greenwoodPluginAdapterSitemap(),
greenwoodPluginResourceSitemap
]
};

0 comments on commit 076ce0f

Please sign in to comment.