11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
16.9k stars 491 forks source link

(Possible) Documentation issue with page.date #900

Open cfjedimaster opened 4 years ago

cfjedimaster commented 4 years ago

Describe the bug The docs say that page.date will be the file's created date unless overridden. I was testing this and noticed it would update every time I modified the file, acting more like the file modification date than creation.

After speaking with some folks on the tnd Slack, we assumed it was because Eleventy was regenerating the HTML every time I saved the file. So it was the file creation value, but the file was recreated on my edits.

However... when I stopped using eleventy --serve and just output a static version, I'm seeing the same thing. A file I made at time X and modified at Y will show Y in the static output.

Are the docs wrong about the default?

cfjedimaster commented 4 years ago

Could it be this? https://askubuntu.com/questions/918300/when-is-birth-date-for-a-file-actually-used

zachleat commented 4 years ago

I assume you’re referencing https://www.11ty.dev/docs/dates/ specifically:

image

Eleventy currently runs the entire build and transforms all input files and writes all files to the output directory. So yes, the file is being created with every build!

https://github.com/11ty/eleventy/issues/108 will change this behavior.

cfjedimaster commented 4 years ago

But I'm not seeing this when I create a build. By what you said, if i run eleventy in my folder now than page.date should be the current time, right? But I'm seeing it use the lastmod value instead.

zachleat commented 4 years ago

Are you saying that lastmod and current time are different? I would assume that most of the time (during local dev) they will be the same.

Relevant code: https://github.com/11ty/eleventy/blob/556f2d83196a3845e34b1d7f23c6cef2365f0e66/src/Template.js#L656

Docs: https://nodejs.org/docs/latest-v12.x/api/fs.html#fs_stats_birthtimems

cfjedimaster commented 4 years ago

So I made a file, docs/banana.md. I made it at 11AM let's say. I edited it at 11:15. While running eleventy --serve, the value I saw was 11:15. That makes sense because when I edited it, Eleventy recreated the file.

However, I stopped running the server, rm -rf _site, run eleventy, and in the generated files, I still see 11:15.

Make sense?

cfjedimaster commented 4 years ago

To add more context - I have setup my site to deploy to Netlify. In my testing there with 2 docs (both outputting the page.date value), when I edit one and trigger a new deploy, both files have the same output. That makes sense, which makes me think its the lack of a proper "birth" value (see my link above) that could be the issue. When I stat the files in WSL I see no value for birth, but only the lastmod, so maybe Eleventy has to use lastmod on my machine, but on Netlify it can properly use file creation date.

So... maybe only an issue for certain types of *nix installs?

Ryuno-Ki commented 4 years ago

Do you have the stat command available? That will give you information about a file (atleast on GNU/Linux - perhaps macOS as well).

Otherwise, use fs.stat in a node REPL to check.