diff --git a/.changeset/fix-autogenerate-publish-unpublish.md b/.changeset/fix-autogenerate-publish-unpublish.md new file mode 100644 index 00000000..1cb013da --- /dev/null +++ b/.changeset/fix-autogenerate-publish-unpublish.md @@ -0,0 +1,7 @@ +--- +"webtools-addon-sitemap": patch +--- + +fix(sitemap): trigger autoGenerate on publish and unpublish actions + +In Strapi 5, publish and unpublish are separate document service actions and do not go through the update action. Adds both to the autoGenerateMiddleware allowlist so the sitemap regenerates immediately on publish/unpublish. diff --git a/packages/addons/sitemap/server/middlewares/auto-generate.js b/packages/addons/sitemap/server/middlewares/auto-generate.js index 5aa4984e..b7b5bd03 100644 --- a/packages/addons/sitemap/server/middlewares/auto-generate.js +++ b/packages/addons/sitemap/server/middlewares/auto-generate.js @@ -17,8 +17,10 @@ const autoGenerateMiddleware = async (context, next) => { return next(); } - // Only add the middleware for the create, update and delete action. - if (!['create', 'update', 'delete'].includes(action)) { + // Only add the middleware for the create, update, delete, publish and unpublish actions. + // In Strapi 5, publish and unpublish are separate document service actions and do not + // go through update, so they must be explicitly included here. + if (!['create', 'update', 'delete', 'publish', 'unpublish'].includes(action)) { return next(); }