Skip to content
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

Display last updated date #1337

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions _config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ site.scopedUpdates(
(path) => path.startsWith("/api/deno/"),
);

// Do more expensive operations if we're building the full site
if (Deno.env.get("BUILD_TYPE") == "FULL") {
console.log("Including resource-heavy operations in the build");

// Use Lume's built in date function to get the last modified date of the file
// This will replace the default date exposed to the page layouts
site.data("date", "Git Last Modified");

// Generate Open Graph images
// TODO: Add custom OG iomage generation
// site.use(ogImages());
}

const SKIP_CHECK_URLS = (Deno.env.get("SKIP_CHECK_URLS") || "false")
.toLowerCase();

Expand Down
13 changes: 13 additions & 0 deletions _includes/doc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ export default function Page(props: Lume.Data, helpers: Lume.Helpers) {
throw new Error("Missing sidebar for " + props.url);
}

function displayDate(date: string) {
return new Date(date).toLocaleDateString("en-US", {
year: "numeric",
month: "short",
day: "numeric",
});
}
Comment on lines +22 to +28
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to render this as YYYY-mm-dd

also I think this should take a Date arg rather than string

function displayDate(date: Date): string {
  return date.toISOString().slice(0, 10);
}


function walk(
sidebarItems: SidebarItem[],
): [SidebarItem[], number] | undefined {
Expand Down Expand Up @@ -153,6 +161,11 @@ export default function Page(props: Lume.Data, helpers: Lume.Helpers) {
}}
>
</h1>

<div class="text-sm mt-0 mb-8 text-foreground-secondary">
Last updated: {displayDate(props.date.toISOString())}
</div>

{props.available_since && (
<div class="bg-gray-200 rounded-md text-sm py-3 px-4 mb-4 font-semibold">
Available since {props.available_since}
Expand Down
3 changes: 2 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
},
"tasks": {
"serve": "deno run -A lume.ts -s",
"serve:full": "BUILD_TYPE=FULL deno run -A lume.ts -s",
"serve:no_logs": "LUME_LOGS=WARN SKIP_CHECK_URLS=true deno run -A lume.ts -s",
"start": "deno task serve",
"dev": "deno task serve",
"build": "deno run -A lume.ts",
"build": "BUILD_TYPE=FULL deno run -A lume.ts",
"debug": "deno task build && deno task prod",
"prod": "cd _site && deno run --allow-read --allow-env --allow-net server.ts",
"reference": "cd reference_gen && deno task types && deno task doc",
Expand Down
Loading