From 0fd5c487402fc52ed73266aa2c8321c6ba2016f5 Mon Sep 17 00:00:00 2001 From: Matthew Berman <748450+mberman84@users.noreply.github.com> Date: Mon, 22 Jun 2026 11:59:31 -0700 Subject: [PATCH] Add explicit date sort directions --- scripts/check.mjs | 3 +++ site/index.html | 5 +++-- site/script.js | 25 +++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/scripts/check.mjs b/scripts/check.mjs index baa0220..80fd729 100644 --- a/scripts/check.mjs +++ b/scripts/check.mjs @@ -124,6 +124,9 @@ assert(agentHtml.includes("For AI agents")); assert(css.includes(".loop-row")); assert(css.includes(".sort-control")); assert(browserScript.includes("data-category-filter")); +assert(html.includes('')); +assert(html.includes('')); +assert(browserScript.includes('"oldest"')); assert(browserScript.includes('sortSelect.addEventListener("change"')); assert(browserScript.includes('params.set("sort", activeSort)')); assert(browserScript.includes("library-pagination")); diff --git a/site/index.html b/site/index.html index 399c617..28729ce 100644 --- a/site/index.html +++ b/site/index.html @@ -198,7 +198,7 @@ ] } - + Loop Library: Repeatable AI Agent Workflows | Forward Future @@ -427,7 +427,8 @@

Sort diff --git a/site/script.js b/site/script.js index 2846426..b9d3ba3 100644 --- a/site/script.js +++ b/site/script.js @@ -73,7 +73,12 @@ const loopTableBody = document.querySelector(".loop-table tbody"); const loopRowPositions = new Map( loopRows.map((row, index) => [row, index]), ); -const SORT_OPTIONS = new Set(["featured", "newest", "alphabetical"]); +const SORT_OPTIONS = new Set([ + "featured", + "newest", + "oldest", + "alphabetical", +]); let activeSort = "featured"; @@ -93,6 +98,18 @@ function compareNewest(a, b) { return loopRowPositions.get(b) - loopRowPositions.get(a); } +function compareOldest(a, b) { + const publishedDifference = (a.dataset.published ?? "").localeCompare( + b.dataset.published ?? "", + ); + + if (publishedDifference !== 0) { + return publishedDifference; + } + + return loopRowPositions.get(a) - loopRowPositions.get(b); +} + function compareFeatured(a, b) { const featuredDifference = Number(b.dataset.featured === "true") - @@ -123,7 +140,11 @@ function applySort(sort) { }); } - return activeSort === "newest" ? compareNewest(a, b) : compareFeatured(a, b); + if (activeSort === "newest") { + return compareNewest(a, b); + } + + return activeSort === "oldest" ? compareOldest(a, b) : compareFeatured(a, b); }); if (loopTableBody) {