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…
And…
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 fileHugo 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
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
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 shortcodeUPDATE: 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 dayTo 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, Want to share this with others or read it later? View it in a browser. |
Beranda » Tanpa Label » [Go Make Things] How to show snippets of content only on certain dates in Hugo SSG
0 Komentar untuk "[Go Make Things] How to show snippets of content only on certain dates in Hugo SSG"