Possible to output build date and time to console?

Hello, I’m currently building a static site using Astro that pulls data from an external JSON file and rebuilds the site automatically on a daily basis. What I would like to achieve is to output the time and date of the last build into the console so that internal team members can see when it was last updated (eg. Last updated: 04/01/2024 02:00). How can I achieve this?

@ninjaroll As with anything there are lots of ways you could achieve this.

I don’t work with Astro so don’t know an “Astro specific way of achieving it” or even how your pages are constructed, but one way of doing it would be to simply place the code in a global template.

The crux of it being that you need the JavaScript itself to have been generated during the build so that it contains the date value you want as a string, and then at runtime it would just output it.

A completely fabricated example to demonstrate the basic concept:

<html>
  <head>
    <title>{dynamicTitle}</title>
  </head>
  <body>
    {dynamicBody}
    <script>
      console.log({buildDate})
    </script>
  </body>
</html>

Here’s some Astro documentation for doing similar which you can probably pull some implementation from:
https://docs.astro.build/en/recipes/modified-time/