Deth

Fitness and everything else

Reworking Some Shortcode To Partials

I have been spending the past couple of days reworking some of my short codes that I have been using with Hugo into partials and layouts.

I originally came up with the idea because I wanted to simplify how I generate the daily pages for the daily history of my weather station. I had been using a short code, and it worked well enough, but I realized that the titles are all basically the same and I wanted to change the way links between pages are generated. That was beyond the limitations of the short code, so I brainstormed and researched a bit.

I first made a layout to generate the headers and stuff and simplified my markdown files. That wasn’t too hard to do. I naturally made a few mistakes along the way, but I got them worked out. That allowed me to move the previous and next page links to the footer, where they belong. It also generates the page’s title based on the day, which is what I was doing manually anyway. Now All I have to do is set the layout to “wxhistory” in the markdown file and it’s good.

Soon after I got that working, I moved on to converting my weather table shortcode into a partial. That was easy enough. I just had to make a few little changes. While there, I changed the “if” statements to “with” where it made sense to make it a bit more readable. Now that it’s done, the only thing I need to do is have a file with the day and layout and the page will be generated. Normally, I like to write a bit of text about the day. I don’t have to, for example if we’re away on vacation, I can just add those files when we get home with no description since I wasn’t there to know what happened.

Because that wasn’t enough, I decided why not take advantage of the power of Hugo’s templates to generate a calendar page with links to each day’s weather. Eventually, after a few days of brainstorming, I found a calendar partial that sort of did what I wanted to do. I reworked it some and twisted it to fit my needs. I now have that up and running. I will make a few more tweaks to it and when I am happy with it and have it formatted more cleanly I will share it here in case anyone else could find such a thing useful. I also want to make sure I don’t have any more stray debugging things in there and stuff that’s not being used, since I tried several approaches before getting it working.

It’s funny to think about it, but I am doing with Google what, I thought, would be great to be able to do when I wrote all my HTML manually back in the late 90s. There was a lot of repeating, and I saw the potential to write something to make it easier. Unfortunately, I was using windows at that time and there just really wasn’t scripting available for it that I found, and I certainly didn’t have the skills then.