From d94bcba83a997b3ae93dc69bb93dafd8753e7c2c Mon Sep 17 00:00:00 2001 From: Jonathan Stockdill Date: Mon, 22 Jul 2024 10:38:35 +0000 Subject: [PATCH] Dynamic Sitemap - combining plugins (#1232) --- packages/plugin-adapter-sitemap/src/index.js | 29 +++++++++---------- .../cases/build.default/greenwood.config.js | 5 ++-- .../cases/develop.default/greenwood.config.js | 5 ++-- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/packages/plugin-adapter-sitemap/src/index.js b/packages/plugin-adapter-sitemap/src/index.js index bc45d10e0..aafd11ba8 100644 --- a/packages/plugin-adapter-sitemap/src/index.js +++ b/packages/plugin-adapter-sitemap/src/index.js @@ -1,4 +1,5 @@ import fs from 'fs/promises'; +import { ResourceInterface } from '@greenwood/cli/src/lib/resource-interface.js'; async function sitemapAdapter(compilation) { try { @@ -16,24 +17,12 @@ async function sitemapAdapter(compilation) { } } -const greenwoodPluginAdapterSitemap = (options = {}) => [{ - type: 'adapter', - name: 'plugin-adapter-sitemap', - provider: (compilation) => { - return async () => { - await sitemapAdapter(compilation, options); - }; - } -}]; - /* * * Sitemap * */ -import { ResourceInterface } from '@greenwood/cli/src/lib/resource-interface.js'; - class SitemapResource extends ResourceInterface { constructor(compilation, options) { super(compilation, options); @@ -62,11 +51,19 @@ class SitemapResource extends ResourceInterface { } -const greenwoodPluginResourceSitemap = { +const greenwoodPluginSitemap = (options = {}) => [{ + type: 'adapter', + name: 'plugin-adapter-sitemap', + provider: (compilation) => { + return async () => { + await sitemapAdapter(compilation, options); + }; + } +}, +{ type: 'resource', name: 'plugin-sitemap', provider: (compilation, options) => new SitemapResource(compilation, options) -}; +}]; -export { greenwoodPluginResourceSitemap }; -export { greenwoodPluginAdapterSitemap }; \ No newline at end of file +export { greenwoodPluginSitemap }; \ No newline at end of file diff --git a/packages/plugin-adapter-sitemap/test/cases/build.default/greenwood.config.js b/packages/plugin-adapter-sitemap/test/cases/build.default/greenwood.config.js index 1537f1e2d..fe547b47b 100644 --- a/packages/plugin-adapter-sitemap/test/cases/build.default/greenwood.config.js +++ b/packages/plugin-adapter-sitemap/test/cases/build.default/greenwood.config.js @@ -1,9 +1,8 @@ -import { greenwoodPluginAdapterSitemap, greenwoodPluginResourceSitemap } from '../../../src/index.js'; +import { greenwoodPluginSitemap } from '../../../src/index.js'; export default { plugins: [ - greenwoodPluginAdapterSitemap(), - greenwoodPluginResourceSitemap + greenwoodPluginSitemap(), ] }; \ No newline at end of file diff --git a/packages/plugin-adapter-sitemap/test/cases/develop.default/greenwood.config.js b/packages/plugin-adapter-sitemap/test/cases/develop.default/greenwood.config.js index 1537f1e2d..fe547b47b 100644 --- a/packages/plugin-adapter-sitemap/test/cases/develop.default/greenwood.config.js +++ b/packages/plugin-adapter-sitemap/test/cases/develop.default/greenwood.config.js @@ -1,9 +1,8 @@ -import { greenwoodPluginAdapterSitemap, greenwoodPluginResourceSitemap } from '../../../src/index.js'; +import { greenwoodPluginSitemap } from '../../../src/index.js'; export default { plugins: [ - greenwoodPluginAdapterSitemap(), - greenwoodPluginResourceSitemap + greenwoodPluginSitemap(), ] }; \ No newline at end of file