Skip to content

feat: add modified timestamp #1281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions _components/Feedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@ export default function Feedback({ file }: { file: string | undefined }) {
return <></>;
} else {
const githubPath = "https://github.com/denoland/docs/edit/main" + file;

let modifiedDate = null;
try {
const dateString = new TextDecoder().decode(
(new Deno.Command("git", {
args: [
"log",
"-1",
"--pretty=%cI",
"./" + file,
],
})).outputSync().stdout,
);

modifiedDate = new Date(dateString);
} catch (e) {
console.log(e);
}

return (
<section
id="feedback-section"
Expand Down Expand Up @@ -138,6 +157,20 @@ export default function Feedback({ file }: { file: string | undefined }) {
</button>
</div>
</div>
{modifiedDate &&
(
<div class="mt-4">
This page was last modified on{" "}
<time datetime={modifiedDate.toString()}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<time datetime={modifiedDate.toString()}>
<time datetime={modifiedDate.toISOString()}>

The toString() method of Date instances returns a string representing this date interpreted in the local timezone.

toString() returns localized date; but <time> requires datetime in ISO8601 format.

{modifiedDate.toLocaleString("en", {
year: "numeric",
month: "short",
day: "numeric",
})}
</time>.
</div>
)}

<a
rel=""
class="mt-4 !underline underline-offset-2 text-xs block"
Expand Down