Strapi / Headless CMS -> Cron job -> Hugo -> Deploy question?

Hi,

I was wondering if anyone has successfully used strapi with Hugo? We use Hugo and have a blog.

We are looking to move our content management to strapi, and it seems there would be two issues:

(1) Is it possible to use a cron job inside strapi to do (a) find a post which is past publish date - this should be fine, and (b) on finding such a post, extract info using GET blog post, format it nicely for JSON flavored markdown.

(2) Once we have the markdown, build, push to github and then deploy to firebase.

Obviously this is our use case, but it seems this would be a good solution to managing content outside Hugo but still using the hugo workflow.

The core use case is we like hugo, but less technical folks need to start managing content and don’t want to deal with markdown.

Any tips much appreciated. Thanks in advance.

Ok - so there appears to be another problem. This post was super helpful, and so I can now get data using data templates as long as they are singles.

How would something like this work on a blog? Below is the code I’m using for a single page -

For anyone else looking at this, this is not hard, but is nitpicky. Basically I moved the deployment from firebase -> github pages. Then the build could be managed by github actions. No worries.

Then, I can use the strapi frontend to push markdown to github, and it works like a charm.

Could you please go more into detail how you got your strapi data into hugo?

To me it looks like there is no option to load html pages directly from a cms api in hugo, but it works with jekyll for example. But what confuses me even more is, that there is not a single post about using hugo with strapi?

So I replicated the blog in strapi. Then, each article has a isPublished flag. Finally I set up cron job which checks if something isPublished? If not, it extracts the data and makes a js object with the contents, so its effectively the data in a json markdown file.

Then, i write it to github as a new commit.

const publishNew = async () => {
  console.log('publishNew');
  // draft should be false, status should be published,
  const newBlogContentToPublish = await strapi.api['blog-content'].services['blog-content'].find(
    { blog_content_draft: false, blog_content_status: 'draft', blog_content_publish_at_lt: new Date() }
  );

  // console.log(newBlogContentToPublish.length);

  newBlogContentToPublish.forEach(async blogContent => {
    // push to Github
    await publishToGithub(blogContent);

    // push to SendPulse
    await publishToSendpulse(blogContent);

    await strapi.api['blog-content'].services['blog-content'].update(
      { id: blogContent.id }, { blog_content_status: 'published' },
    );
  });
};

module.exports = {
  '*/1 * * * *': async () => {
    // publish new blog posts
    try {
      await publishNew();
    } catch (err) {
      console.log('publishNew task has ended with an error', err);
    }
  },
};

Once the commit is done, the Github actions is used to automatically build the website and deploy to github pages repo.

Hope that helps!

2 Likes