Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-save, pre-publish hooks to CMS #1348

Closed
cpjolicoeur opened this issue May 9, 2018 · 21 comments · Fixed by #3812
Closed

Add pre-save, pre-publish hooks to CMS #1348

cpjolicoeur opened this issue May 9, 2018 · 21 comments · Fixed by #3812

Comments

@cpjolicoeur
Copy link

Per discussion in the Gitter channel, just making an issue for thoughts & discussion around adding some "hooks" to the CMS for pre-save and pre-publish events. These hooks could allow the CMS user to modify file content before persisting to the backend (and/or other content changes anyone might want to do in the given hook).

@delucis
Copy link
Contributor

delucis commented May 9, 2018

I recently needed a widget to automatically generate a modified time for entries, but had to make do with generating it when the editor was opened. Seems like a good example of a widget that would benefit from these hooks.

Could components declare preSave() and prePublish() similar to the isValid() method that is already available?

@erquhart
Copy link
Contributor

erquhart commented May 12, 2018

I love the idea of events in general, big thumbs up for this. I'm not sure about the component methods approach - it introduces problems that are just unnecessary.

@tech4him1
Copy link
Contributor

tech4him1 commented May 13, 2018

Agreed, for the case of providing an initial value like @delucis mentioned, we can work on something like #725. Global hooks sound awesome though (I just feel like I'm back in WordPress land 😆)

@erquhart
Copy link
Contributor

Ha! Any ideas for alternatives?

@cedricdelpoux
Copy link

I think this feature could be very usefull for some cases.

I have my content in a git submodules. So each netlify-cms update commit to my submodule repo. But My main repo does not change anymore so netlify does not trigger a new deploy.

@visuallization
Copy link

Oh yes this feature would be really nice! I could then create dynamically pages with a script within in my nextjs app. So let's say: As an author I create a new page and publish it over netlify cms, "on save" -> the hook kicks in, executes the script which creates tsx files in pages/ based on the .md files in content/.

Are there any news about the progress here?

@davejm
Copy link

davejm commented May 26, 2019

See #2344 for a quick mockup of how this might be implemented. Unsure if this is the right direction but it's a suggestion.

@erquhart
Copy link
Contributor

erquhart commented Jun 4, 2019

Commented, thanks for using a PR to promote a path forward!

@stale
Copy link

stale bot commented Oct 29, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Oct 29, 2019
@delucis
Copy link
Contributor

delucis commented Oct 29, 2019

Has there been some movement on this or other ways of achieving this behaviour? I see that #2344 is still open.

@stale stale bot removed the wontfix label Oct 29, 2019
@cpjolicoeur
Copy link
Author

Well #2344 was also just closed for inactivity by the bot. :(

It seems this whole project is pretty hit-or-miss when it comes to activity. The stale bot was just added yesterday and seems to have wiped a bunch of stuff out.

@TidyIQ
Copy link

TidyIQ commented Oct 30, 2019

I also desperately need this. Is this a WIP or just stale?

@erquhart
Copy link
Contributor

This issue is not going to be closed. Introducing stale bot was a step towards maintaining a meaningful backlog - it’s actually a good thing. You’ll see us following up on virtually every issue on this repo over the next two weeks. Thank you all so much for your patience!

Sent with GitHawk

@erezrokah
Copy link
Contributor

#1171 is somehow related in the way both mechanisms hook into specific CMS operations

@ehayman
Copy link

ehayman commented Jan 30, 2020

Just chiming in that this would be SUPER helpful for my project! Would love to see a path forward.

@erezrokah
Copy link
Contributor

You can now add events handlers for prePublish and postPublish events: https://www.netlifycms.org/docs/beta-features/#registering-to-cms-events

Doesn't allow modifying the entry data before publish (at the moment and open to discussion) - can anyone share a use case for changing the data before publish that can't be achieved using a custom widget?

The reason for not allowing it yet is that it requires some thought on how to do it in a safe way. Meaning making sure any change conforms to the data validation enforced by the widgets.

@delucis
Copy link
Contributor

delucis commented Feb 3, 2020

@erezrokah My use case was for a last modified date field. This can be achieved with a custom widget, but my effort a while back (see my comment above) only allowed me to update that time when a post was opened for editing, not when it was saved, which I guess could be more idiomatically handled with prePublish.

@erezrokah
Copy link
Contributor

erezrokah commented Feb 3, 2020

Thanks @delucis, that does make sense. Will keep the issue open for further discussion and feedback.

@vai0
Copy link

vai0 commented Apr 13, 2020

@delucis have you been able to find a solution that allows for updating the time on publish rather than on opening the entry? i am also trying to create a "date modified" widget, but none of the solutions have been ideal.

@delucis
Copy link
Contributor

delucis commented Apr 13, 2020

@vai0 It’s a while since I worked on this, but no, I just made do with using the time the entry was opened, I think.

@s8gv
Copy link

s8gv commented Apr 23, 2020

Hi @vai0 and @delucis, I have the same use-case. I need to get the published/last updated date-time. I fyou have any workaround can you please let me know Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.