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
6 changes: 6 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
timeout-minutes: 10
permissions:
contents: read
actions: read
env:
# The build otherwise reports usage to telemetry.astro.build.
ASTRO_TELEMETRY_DISABLED: 1
Expand Down Expand Up @@ -58,6 +59,11 @@ jobs:
working-directory: site
- run: npm test
working-directory: site
# The home page's "Last count" is when Likes were last counted, not when the site was built.
- name: Find the last Likes count
run: echo "LIKES_AT=$(gh run list -R "$GITHUB_REPOSITORY" -w likes.yml -s success -L 1 --json updatedAt --jq '.[0].updatedAt // ""')" >> "$GITHUB_ENV"
env:
GH_TOKEN: ${{ github.token }}
- run: npm run build
working-directory: site
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
Expand Down
7 changes: 7 additions & 0 deletions site/src/lib/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@ export const pct = (likes: number, delta: number) => {
const before = likes - delta;
return before > 0 ? Math.round((delta / before) * 100) : null;
};

// When Likes were last counted: deploy passes the last successful Sync Likes run.
// Without it (local and PR builds) the build time stands in.
export function lastCount(v: string | undefined, now = new Date()): Date {
const ok = v && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/.test(v);
return ok ? new Date(v) : now;
}
4 changes: 2 additions & 2 deletions site/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import Base from "../layouts/Base.astro";
import Leaderboard from "../components/Leaderboard.astro";
import Explain from "../components/Explain.astro";
import { loadAll, liveList, trending } from "../lib/data.ts";
import { centralStamp, icon, num } from "../lib/format.ts";
import { centralStamp, icon, lastCount, num } from "../lib/format.ts";

const { entries, categories } = loadAll();
const live = liveList(entries);
const climber = trending(entries)[0];
const built = new Date();
const built = lastCount(process.env.LIKES_AT);
const stamp = centralStamp(built);
---

Expand Down
13 changes: 12 additions & 1 deletion site/tests/format.test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { centralStamp } from "../src/lib/format.ts";
import { centralStamp, lastCount } from "../src/lib/format.ts";

test("centralStamp shows CST in winter", () => {
assert.equal(
Expand All @@ -15,3 +15,14 @@ test("centralStamp shows CDT in summer", () => {
"Jul 1, 12:00 PM CDT",
);
});

test("lastCount uses the last Likes run, else the build time", () => {
const now = new Date("2026-11-07T12:00:00Z");
assert.equal(
lastCount("2026-11-07T09:17:42Z", now).toISOString(),
"2026-11-07T09:17:42.000Z",
);
for (const bad of [undefined, "", "null", "yesterday", "2026-11-07"]) {
assert.equal(lastCount(bad, now), now);
}
});
Loading