withastro / docs

Astro documentation
https://docs.astro.build/
MIT License
1.34k stars 1.5k forks source link

Error in Add last modified time recipe code? #8779

Closed sarah11918 closed 1 month ago

sarah11918 commented 4 months ago

πŸ“š Subject area/topic

recipe -- remark plugin last modified time

πŸ“‹ Page(s) affected (or suggested, for new content)

https://docs.astro.build/en/recipes/modified-time/

πŸ“‹ Description of content that is out-of-date or incorrect

From Feedback Fish:

The recipe works on my local dev server, but when i deploy it via github action, for some reason i got 'Invalid date' instead. Im not too sure how to troubleshoot this issue, and it would be great if the docs can cover that as an example as well

πŸ–₯️ Reproduction in StackBlitz (if reporting incorrect content or code samples)

No response

Fryuni commented 3 months ago

Relying on Git history on CI platforms is a bit problematic. We document this on Starlight's lastUpdated option since it is affected by it.

I wrote about the specific case of Vercel, but the same applies to GH actions. The actions/checkout action that does the cloning defaults to a fetch depth of 1.

Maybe something like the Starlight docs would be good here, but I don't think it should have anything specific to any platform. This problem happens to almost all of them, and each has a different way to opt out of that behavior when they even have that option.

sarah11918 commented 3 months ago

When you say "maybe something like", do you mean adding the text about "this may not be accurate?", or do you mean trying to write the recipe "in the way that Starlight does it"?

Fryuni commented 3 months ago

Adding this or something similar in the recipe:

Reporting the Git time may not be accurate depending on the environment in which the project is being built. Hosting platforms, CIs, and automated testing platforms commonly don't retrieve the full git history required for Git to return the correct values.

sarah11918 commented 1 month ago

Gotcha! Would accept a PR to this recipe that adds this after the introduction, just before the recipe starts, in a note:


:::note[Relying on Git history]
By default, this feature relies on your repository’s Git history and may not be accurate on some deployment platforms performing [shallow clones](https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---depthltdepthgt).
:::