This site is being remade and I won't be updating this for a while. Expect a lot of broken links, design and functionality. If all goes well, things should be stable by the end of 2022. Thank you for understanding.


Rendering a Copyright Footer In Hugo

Republished Originally Published Updated

At the end of every year, people joke on how it’s time to update their site’s footer’s copyright year. I doubt it’s neccessary to specify the copyright year to claim copyright, but it’s a fun thing to do.

People tend to do this in JavaScript like this:

<small>© <time onload="let now=new Date();let year=now.getFullYear();this.datetime=year;this.innerText=year"></time></small>

While this works, it isn’t progressivey enhanced so there’s a chance it won’t always be there.

It makes more sense to do this in the template instead. This can be done in Hugo like this:

<small{{ with (now.Year "2006") }}<time datetime="{{ . }}">{{ . }}</time>{{ end }}</small>

Which should result in something like © 2021 with the following markup:

<small>© <time datetime="2021">2021</time></small>

Doing this brought down the markup from 124 characters to just 50, about 2.5x less! Even if I get rid of the arguably extranious stuff (let and this) which makes it 106 characters, that’s still 2.12x smaller!