Trigger event on new content

Lets say that I created a new post and I want to do something when it happens. How can I do that? Is this possible using hugo?

What do you want to do when “it happens?”

I want to run javascript to share to all my social media accounts. Can it be done?

I don’t think that you can do this on the frontend. I might be wrong though.

But in Hugo the URL of a post is known even before you publish, since you set it yourself.

You could schedule posts with Buffer or Facebook or whatever, using the URL of a post that will be published at a later date (as long as you trigger a build of your site at the desired date with the new post).

The thread starter is a little vague here, but there are two scenarios here, none of them with built-in support in Hugo:

  1. Watching for changes in destination folder /public or in /content with fswatch or similar and trigger a script on changes. Plenty of examples around doing similar.
  2. Add a hook in GitHub on commits. This is what Wercker, Netlify and CircleCI etc. are doing to trigger deployment on changes to a GitHub repository.
1 Like

Im sorry if im confusing anyone here, as I only wanted to know if there is such a way like an event triggered by Hugo itself.

Is both a combined process as a solution or both of them are individually a solution? :smiley: sorry for my english

First solution applies if you host your site on a server and you have admin rights, the second solution applies if you use a Github repo.

Okay, I’ll try and see about the second option as I’m currently using netlify to host my hugo site. Thanks