Rick Cogley's Tech Logr

Short Technical Laser Bursts %%

RC Logr 20190301 191716

Friday, 1 Mar, 2019

I integrated holiday name display in Logr, pulling the needed holiday data in json format from my ops db, then parsing it when building the site with Hugo. The gist is, with the post date in a format that is the same as one of the fields in the data, read the data in, and match the post date to the record that has that date, then pull the holiday text from that record and show it. 🏖

The json data looks like:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
...
{
  "@row.id": 312,
  "Date": "2019-02-11T00:00:00+00:00",
  "Date in YYYYMMDD": "20190211",
  "Day of Week": "Monday",
  "Date with Month Name": "11 Feb 2019",
  "Name": "National Foundation Day",
  "Name Jp": "建国記念の日"
},
...

And the Hugo template that pulls it looks like:

1
2
3
4
5
6
7
8
...
{{ $dt := .Key }}
{{ range where $.Site.Data.holidays ".Date with Month Name" $dt }}
{{ with (index . "Name") }}
<p class="three bg-near-white br3">🗓 "<strong><i>{{ . }}</i></strong>" in Japan</p>
{{ end }}
{{ end }}
...

RC Logr 20190301 191716 - I integrated holiday name … Rick Cogley
Back to Home