From 8d03ccfbf0b45db8958071ff41c88c85d9c00d4b Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Mon, 12 Oct 2026 18:47:48 +0700 Subject: [PATCH] Sort What's new plugins by submission time (#6713) Co-authored-by: paseo-bot[bot] --- packages/website/src/plugins/registry.test.ts | 45 ++++++++++--------- packages/website/src/plugins/registry.ts | 8 ++-- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/packages/website/src/plugins/registry.test.ts b/packages/website/src/plugins/registry.test.ts index ec6724137d..9dd132f1b5 100644 --- a/packages/website/src/plugins/registry.test.ts +++ b/packages/website/src/plugins/registry.test.ts @@ -76,33 +76,38 @@ describe("plugin registry", () => { ]); expect(featuredPlugins(listed, ["acme/not-published"])).toEqual([]); }); - it("lists what's new by first-listing date, not submission or update dates", () => { - const listedFirst = { + it("lists what's new by submission time, not review, listing or update dates", () => { + const submittedFirst = { ...plugin, - id: "acme/listed-first", - submittedAt: "2026-09-20", - reviewedAt: "2026-09-21", - updatedAt: "2026-10-02", - publishedAt: "2026-09-02", + id: "acme/submitted-first", + submittedAt: "2026-09-02T00:00:00.000Z", + reviewedAt: "2026-10-02T00:00:00.000Z", + updatedAt: "2026-10-02T00:00:00.000Z", + publishedAt: "2026-10-02T00:00:00.000Z", }; - const listedLater = { + const submittedLater = { ...plugin, - id: "acme/listed-later", - submittedAt: "2026-09-01", - reviewedAt: "2026-09-01", - updatedAt: "2026-09-01", - publishedAt: "2026-09-30", + id: "acme/submitted-later", + submittedAt: "2026-09-30T00:00:00.000Z", + reviewedAt: "2026-09-30T00:00:00.000Z", + updatedAt: "2026-09-30T00:00:00.000Z", + publishedAt: "2026-09-30T00:00:00.000Z", }; - expect(newestFirst([listedFirst, listedLater]).map((p) => p.id)).toEqual([ - "acme/listed-later", - "acme/listed-first", + expect(newestFirst([submittedFirst, submittedLater]).map((p) => p.id)).toEqual([ + "acme/submitted-later", + "acme/submitted-first", ]); const now = "2026-10-03T12:00:00.000Z"; - expect(addedAgo(listedLater, now)).toBe("3d ago"); - expect(addedAgo(listedFirst, now)).toBe("4w ago"); + expect(addedAgo(submittedLater, now)).toBe("3d ago"); + expect(addedAgo(submittedFirst, now)).toBe("4w ago"); }); - it("orders by listing date and by installs in a window, keeping index order for ties", () => { - const older = { ...plugin, id: "acme/older", publishedAt: "2026-09-01" }; + it("orders same-day submissions by their time", () => { + const morning = { ...plugin, id: "acme/morning", submittedAt: "2026-10-12T00:00:00.000Z" }; + const noon = { ...plugin, id: "acme/noon", submittedAt: "2026-10-12T11:38:00.000Z" }; + expect(newestFirst([morning, noon]).map((p) => p.id)).toEqual(["acme/noon", "acme/morning"]); + }); + it("orders by submission time and by installs in a window, keeping index order for ties", () => { + const older = { ...plugin, id: "acme/older", submittedAt: "2026-09-01" }; const twin = { ...plugin, id: "acme/twin" }; expect(newestFirst([older, plugin, twin]).map((p) => p.id)).toEqual([ "acme/example", diff --git a/packages/website/src/plugins/registry.ts b/packages/website/src/plugins/registry.ts index 37a4455d0c..c55741ecdc 100644 --- a/packages/website/src/plugins/registry.ts +++ b/packages/website/src/plugins/registry.ts @@ -106,9 +106,9 @@ export function featuredPlugins(plugins: Plugin[], featured: string[]): Plugin[] const byId = new Map(plugins.map((plugin) => [plugin.id, plugin])); return [...new Set(featured)].flatMap((id) => byId.get(id) ?? []); } -/** Most recently listed first; equal dates keep index order. */ +/** Most recently submitted first, so updates never resurface a plugin; equal times keep index order. */ export function newestFirst(plugins: Plugin[]): Plugin[] { - return [...plugins].sort((a, b) => b.publishedAt.localeCompare(a.publishedAt)); + return [...plugins].sort((a, b) => Date.parse(b.submittedAt) - Date.parse(a.submittedAt)); } /** Most installs in the window first; equal counts keep index order. */ export function mostInstalled( @@ -119,9 +119,9 @@ export function mostInstalled( const count = (plugin: Plugin) => installs[plugin.id]?.[window] ?? 0; return [...plugins].sort((a, b) => count(b) - count(a)); } -/** How long ago the plugin was first listed, relative to the loader's clock. */ +/** How long ago the plugin was submitted, relative to the loader's clock. */ export function addedAgo(plugin: Plugin, now: string): string { - const days = Math.floor((Date.parse(now) - Date.parse(plugin.publishedAt)) / DAY_MS); + const days = Math.floor((Date.parse(now) - Date.parse(plugin.submittedAt)) / DAY_MS); if (days <= 0) return "today"; if (days === 1) return "yesterday"; if (days < 14) return `${days}d ago`;