statamic / ssg

The official Statamic Static Site Generator
229 stars 23 forks source link

SSG sometimes doesn't format dates properly #77

Closed tao closed 1 year ago

tao commented 2 years ago

This might be a bit difficult to replicate... but I have a Github action that runs SSG daily to update the website. Sometimes it generates {{ date }} properly as September 24th, 2021 and sometimes it just prints the timestamp 2021-09-24 00:00:00.

For example:

Screenshot 2021-10-09 at 23 18 51

Screenshot 2021-10-09 at 23 18 43

I don't notice anything in the logs that's different, and the sync happens daily at the same time so nothing changes between them except new content being added.

If I do re-run the Github Action it generates the page with the normal formatted dates, so nothing changes between runs but it prints the date randomly.

katwlodarczyk commented 2 years ago

Have the same issue...

jasonvarga commented 1 year ago

Just figured out the cause for this accidentally while working on another issue.

The date format is set in a middleware. On regular content pages (entries etc) middleware doesn't actually get run. On routes, (e.g. Route::statamic(), extra urls in the config, etc) middleware do get run. So the date format will only be set on pages after any the middleware has run. It seems random because we literally randomize the pages before generating them. (#57)

A short term "fix" would be to re-set the date format in the SSG somewhere, rather than rely on the middleware. A better fix would be to run the middleware. As it stands, if you were attempting to run your own middleware, it wouldn't happen.