How to display the last build date in Eleventy (#snippet)

I came across a nifty eleventy trick shared by Hugo Giraudel. They shared that it only takes a few lines of JavaScript to display the time when an eleventy site was generated and rendered. If you look in the footer of this site, you…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

I came across a nifty eleventy trick shared by Hugo Giraudel. They shared that it only takes a few lines of JavaScript to display the time when an eleventy site was generated and rendered. If you look in the footer of this site, you'll see when it was rebuilt. The implementation took me two minutes. ?

One thing that amazes me about eleventy is its flexible data layer. There are multiple ways to feed the build process with data to display. The options range from static JSON files to promises-based JavaScript functions.

In my case, I have a config.js file that holds a lot of configuration and now it includes a builtAt field, too.

// config.js
module.exports = {
  // bunch of other stuff
  // ...
  builtAt: new Date().toLocaleString(),
};

In my templates (I use Nunjucks), I can now use the data provided by config.js and access the time when the site was generated.

<p>
  This site was rebuilt at <strong>{{config.builtAt}}</strong>using the CEN stack
</p>

Thanks Hugo, for sharing this nifty trick!


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2020-12-03T23:00:00+00:00) How to display the last build date in Eleventy (#snippet). Retrieved from https://www.scien.cx/2020/12/03/how-to-display-the-last-build-date-in-eleventy-snippet/

MLA
" » How to display the last build date in Eleventy (#snippet)." Stefan Judis | Sciencx - Thursday December 3, 2020, https://www.scien.cx/2020/12/03/how-to-display-the-last-build-date-in-eleventy-snippet/
HARVARD
Stefan Judis | Sciencx Thursday December 3, 2020 » How to display the last build date in Eleventy (#snippet)., viewed ,<https://www.scien.cx/2020/12/03/how-to-display-the-last-build-date-in-eleventy-snippet/>
VANCOUVER
Stefan Judis | Sciencx - » How to display the last build date in Eleventy (#snippet). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2020/12/03/how-to-display-the-last-build-date-in-eleventy-snippet/
CHICAGO
" » How to display the last build date in Eleventy (#snippet)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2020/12/03/how-to-display-the-last-build-date-in-eleventy-snippet/
IEEE
" » How to display the last build date in Eleventy (#snippet)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2020/12/03/how-to-display-the-last-build-date-in-eleventy-snippet/. [Accessed: ]
rf:citation
» How to display the last build date in Eleventy (#snippet) | Stefan Judis | Sciencx | https://www.scien.cx/2020/12/03/how-to-display-the-last-build-date-in-eleventy-snippet/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.