Future-proof your Jekyll copyright date

Written by Michael Lee on February 13, 2017

I’m sure it shouldn’t bother me as much, but one of my pet-peeves about websites is when the new year rolls around and their copyright date year isn’t updated. It immediately gives off the impression the site isn’t maintained.

If your site is built with Jekyll, you could easily just update the date once if your footer is defined in an _includes file.

// This is my footer.html defined in the _includes file.
// I could just update line 3 and be done.
<footer class="site-footer sans-serif pr1 pl1 pb1">
  <div class="md-col-8 col-12 mx-auto">
    <span>&copy; 2017 <a href="/" class="black">Michael Lee</a></span>
    <a href="/about/" class='black mlhalf'>About</a>
    <a href="/writings/" class='black mlhalf'>Articles</a>
    <a href="/the-links/" class='black mlhalf'>Links</a>
  </div>
</footer>

A better approach would be to let Jekyll handle it for you. You can do that by using the time property exposed in the site hash like this {{ site.time | date: '%Y' }}.

The time property is the current time when the jekyll command is run. So the next time you go to generate your Jekyll site it’ll use the current time.

date: '%Y' is a Liquid filter which accepts Ruby date format directives. Which means %Y yields the year extracted from the time property in a 4 digit format. Here is the block of footer code now with the time property and Liquid filter.

<footer class="site-footer sans-serif pr1 pl1 pb1">
  <div class="md-col-8 col-12 mx-auto">
    <span>&copy; {{ site.time | date: '%Y' }} <a href="/" class="black">Michael Lee</a></span>
    <a href="/about/" class='black mlhalf'>About</a>
    <a href="/writings/" class='black mlhalf'>Articles</a>
    <a href="/the-links/" class='black mlhalf'>Links</a>
  </div>
</footer>

This solution isn’t fully automatic in that once the clock ticks past midnight on New Year’s eve into New Year’s day that your footer will be updated, but it allows you to not worry about manually changing the date before your first post of the new year. If you want a fully automatic solution you’d probably want to go with a JavaScript solution that doesn’t depend on you building your site to update the copyright year.

Thanks for taking the time to read this article. I'd love to stay in touch and share more tips on programming and design, side projects and working remotely. Sign up and I'll send you my articles straight to your email.

:wave: Hey hey, I'm Michael Lee! I really appreciate you taking the time to read this article.

Be sure to check out my other articles.

Previous post: Programming for fun