[November 2019: sources moved to GitHub]
Awhile back I replaced the (increasingly unwieldy) monthly archive section over there in the right-hand column with a yearly archive section: one link per year that Pun Salad has been in existence. Each link takes you to a yearly calendar, which, in turn, contains links to the monthly archives (when you click on a month name) or daily posts (when you click on a day). Example output here for 2017.
The code to generate those calendars is embedded in the (very) special purpose CGI script that powers Pun Salad, but I thought the calendar generation code might be of interest to people.
Notes:
-
The script is run with a single year argument, and produces HTML on
standard output.
-
The Perl module
Time::Piecedoesmostall of the heavy lifting for the necessary date calculations. It probably breaks down for years far in the past or future; I haven't messed with that too much. I tested that it gives the same calendar for 1901 as the Linux cal command does, so that's good. -
The
HTML::Templatemodule is used to specify the HTML framework for the calendar. Obviously, that's where you might want to customize the appearance. The code assumes the template resides in your top-level~/Templatesdirectory. -
The calendar is a table of months; each month is a table of days. This
means, of course, that the generator is essentially a four-deep nested
loop. Eek! A voice from my old structured programming days said: "you
really shouldn't nest loops that deeply". So I broke out the
month-generation into a Perl subroutine, and now I feel better about
myself.
As usual, this is not earth-shattering code, but I hope someone finds it useful, if only for tutorial purposes.
![[Amazon Link]](/ps/asin_imgs/B07JGFJHXM.jpg)
![[Amazon Link]](/ps/asin_imgs/0515121487.jpg)
![[IMDb Link]](https://ia.media-imdb.com/images/G/01/imdb/plugins/rating/images/imdb_46x22.png)
![[Amazon Link]](/ps/asin_imgs/B00MEEVVT4.jpg)

![[The Blogger]](/ps/images/barred.jpg)


