Skip to content
Merged
Show file tree
Hide file tree
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
34 changes: 31 additions & 3 deletions _config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,37 @@ site.ignore(
// the default layout if no other layout is specified
site.data("layout", "doc.tsx");

// Populate lastModified from git history using a single git command
site.preprocess([".md", ".mdx"], (filteredPages) => {
const result = Deno.spawnAndWaitSync("git", [
"log",
"--pretty=format:%aI",
"--name-only",
"--diff-filter=ACMR",
"HEAD",
]);

const output = new TextDecoder().decode(result.stdout);
const lastModified = new Map<string, string>();
let currentDate = "";

for (const line of output.split("\n")) {
if (!line) continue;
if (line.match(/^\d{4}-/)) {
currentDate = line;
} else if (!lastModified.has(line)) {
lastModified.set(line, currentDate);
}
}

for (const page of filteredPages) {
const src = page.sourcePath?.replace(/^\//, "");
if (src && lastModified.has(src)) {
page.data.lastModified = new Date(lastModified.get(src)!);
}
}
});

// Load API categories data globally
import denoCategories from "./reference_gen/deno-categories.json" with {
type: "json",
Expand Down Expand Up @@ -373,9 +404,6 @@ site.data("apiCategories", {

// Do more expensive operations if we're building the full site
if (Deno.env.get("BUILD_TYPE") == "FULL" && !Deno.env.has("SKIP_OG")) {
// Use Lume's built in date function to get the last modified date of the file
// site.data("date", "Git Last Modified");;

// Generate Open Graph images
site.data("openGraphLayout", "/open_graph/default.jsx");
site.use(
Expand Down
12 changes: 12 additions & 0 deletions _includes/doc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ export default function Doc(data: Lume.Data, helpers: Lume.Helpers) {
{data.children}
</div>
</article>
{data.lastModified && !isReference && !isLintRule && (
<p class="text-sm text-foreground-secondary mt-8">
Last updated on{" "}
<time dateTime={data.lastModified.toISOString()}>
{data.lastModified.toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
})}
</time>
</p>
)}
<data.comp.Feedback file={file} />
</div>
</main>
Expand Down
Loading