decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.65k stars 3.02k forks source link

Allow modification of content in `prePublish` hook #7133

Open drzax opened 3 months ago

drzax commented 3 months ago

Is your feature request related to a problem? Please describe. I want the CMS to automatically set the published date for entries when an entry is published for the first time. This should be doable with the prePublish hook a handler something like:

CMS.registerEventListener({
        name: "prePublish",
        handler: ({entry}) => {
          const now = new Date().toISOString();
          let data = entry.get('data');
          if (data.get('status') === 'draft') {
            data = data.set('published', now);
          }
          return data.set('status', 'published');
        }
      });

But the invokePrePublishEvent function (unlike invokePreSaveEvent) doesn't return the updated data.

Describe the solution you'd like I'd like the prePublish hook to allow updating entry data.

Describe alternatives you've considered I tried to think of a way to do this only using the preSave hook, but don't think it's possible.

Additional context It would be worth considering whether all hooks (or at least all pre-hooks should be able to update data.