Future-proof your Jekyll copyright date

Written 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:col8 col12 mxauto">
    <span>&copy; 2017 <a href="/" class="black">Michael Lee</a></span>
    <a href="/about/" class='black ml0.5'>About</a>
    <a href="/writings/" class='black ml0.5'>Articles</a>
    <a href="/the-links/" class='black ml0.5'>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:col8 col12 mxauto">
    <span>&copy; {{ site.time | date: '%Y' }} <a href="/" class="black">Michael Lee</a></span>
    <a href="/about/" class='black ml0.5'>About</a>
    <a href="/writings/" class='black ml0.5'>Articles</a>
    <a href="/the-links/" class='black ml0.5'>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.

Stay in touch

Thanks for reading this article. I'd love to stay in touch and share more tips on programming and side projects with you. Sign up and I'll send you my articles straight to your email, you'll also get a free copy of the light themed version of my Git cheat sheet.
Git cheat sheet preview image