Ad/iklan :

3gp Mp4 HD
Play/Download
Live 3D App
Search.Pencarian Menu

Add text send email to rh3252705.adda@blogger.com or Click this (Text porn Will delete) | Tambah teks kirim email ke rh3252705.adda@blogger.com atau Klik ini (Teks porno akan dihapus)
Total post.pos : 16329+

[Go Make Things] How to show snippets of content only on certain dates in Hugo SSG

Today, I wanted to share how I schedule content snippets to only display on my Hugo website between certain dates.

Let's dig in!

WTF would you need to do this?

Back when I still sold courses, I would run sales for holidays, and want to display messages on my site to promote them.

Stuff like…

❄️ Holiday Sale! Today through New Year's Day, get 40% off all of my courses!

And…

❄️ Last Chance! My holiday sale ends today. Don't miss your chance to get 40% off all of my courses!

I didn't want these messages to show up before the sale started, and I didn't want them to still be up on my sale after the sale ended, either.

And as you can see from the example above, sometimes I'd switch up the messaging as the sale was coming to an end.

For the first few years, I did this manually, updating my text in various places and pushing those changes live on specific dates.

Then I found a simpler way to do automate this in Hugo.

Step 1: a data file

Hugo has a built-in way to store information in data files: JSON, TOML, YAML, or XML you can use to hold data and use it elsewhere.

Let's say I had a file called messages.yml, that looked like this…

sale: "<p>❄️ <strong>Holiday Sale!</strong> Today through New Year's Day, get 40% off all of my courses!</p>"

I could access that content and use it in a template, partial, or shortcode like this…

I decided to setup a file like this for all of the messages on my site.

But instead of just having a default message, I would also have some limited ones that are scheduled with a start and end date in YYYYMMDD format.

sale:   	message: ""  	limited:  		- message: "<p>❄️ <strong>Holiday Sale!</strong> Today through New Year's Day, get 40% off all of my courses!</p>"  		  start: 20241226  		  end: 20241230  		- message: "<p>❄️ <strong>Holiday Sale!</strong> Today and tomorrow, get 40% off all of my courses!</p>"  		  start: 20241231  		  end: 20241231  		- message: "<p>❄️ <strong>Last Chance!</strong> My holiday sale ends today. Don't miss your chance to get 40% off all of my courses!</p>"  		  start: 20250101  		  end: 20250101

Now, I have a way to define a bunch of content ahead of time, with the specific dates it should be visible.

Step 2: a shortcode

UPDATE: ConvertKit keeps stripping out all of the shortcode content here because it looks like the liquid syntax they use for templating in their backend.

To read this section, please view the live version of this article on my website.

Step 3: showing these on the appropriate day

To get the messages to actually update on the correct day, I have a cron job that runs a build every day.

This is part of the same process I use to schedule posts ahead of time. It runs at midnight every day, and at 10:30 am (for scheduled posts).

Like this? A Go Make Things membership is the best way to support my work and help me create more free content.

Cheers,
Chris

Want to share this with others or read it later? View it in a browser.

Share :

Facebook Twitter Google+
0 Komentar untuk "[Go Make Things] How to show snippets of content only on certain dates in Hugo SSG"

Back To Top