loopwerk / Saga

A static site generator written in Swift
https://loopwerk.github.io/Saga/documentation/saga/
MIT License
77 stars 3 forks source link

Relying on filesystem dates is a bad idea #21

Open kevinrenskers opened 3 days ago

kevinrenskers commented 3 days ago

Currently Saga reads the file's creation and last modified dates, and stores those into the Item. The dates are then used inside of the atom feed generation for example. But the creation date is also the fallback for the published date: if you don't include a date field in your markdown metadata then the published date is set to the file creation date.

This is a problem because the file creation date is not stored in git, and when you do a fresh checkout the file creation date is set to "right now" instead of the actual past creation date. This is also a problem on my own website. While I do override the published date to something consistent, the last modified date is used in the atom feed.. and these dates just keep on changing because Netlify fetches the repo and the dates change.

Basically, using file attributes doesn't seem like a good idea?

On the other hand, this is not a problem with Saga but a problem with git. For people who don't store their website in git or who create the static sites on their own computer, this wouldn't be a problem. So maybe it would be better to add something to the Saga docs about this?

See also https://stackoverflow.com/questions/1964470/whats-the-equivalent-of-subversions-use-commit-times-for-git:

Each time I clone my repository, I want the timestamps of files to reflect when they were last changed in the remote repository, not when I cloned the repository.

kevinrenskers commented 3 days ago

It seems that git-restore-mtime could solve the file modification date issues. This is not installed on Netlify, I've sent them a feature request.

I think this should be added to the documentation, so that people at least are aware of the behavior of the file attributes not being reliable.

kevinrenskers commented 2 days ago

OK this totally works 🎉 https://github.com/loopwerk/loopwerk.io/commit/e94cb8597aefced031496dc1110b071afb29aeb7