Skip to content

Commit

Permalink
Just sort, no limit, on collection page
Browse files Browse the repository at this point in the history
  • Loading branch information
kristianfreeman committed Jan 8, 2025
1 parent c54bcf7 commit eef7a29
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/routes/built-with.collections.$slug.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Layout from "../components/layout";
import Project from "../components/project";
import { isInitialRoute } from "../components/route-update-history.js";

import { sortAndLimitProjects } from "../utils";
import { sortProjects } from "../utils";

import { client } from "../lib/sanity";

Expand Down Expand Up @@ -59,7 +59,7 @@ const BuiltWithPage = () => {
<div className="Collections">
<div className="Collection">
<div className="Collection--projects">
{sortAndLimitProjects(collection)
{sortProjects(collection)
.map((project, pi) => (
<div className="Collection--project" key={pi}>
<Project
Expand Down
8 changes: 5 additions & 3 deletions app/utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ const resultTemplate = () => `

const sortAndLimitProjects = (collection) => {
const numToShow = collection.numProjectsToShow || 3;
return sortProjects(collection).slice(0, numToShow)
}

const sortProjects = (collection) => {
const sortOrder = collection.sortOrder || "_updated_at desc";
const [sortField, sortDirection] = sortOrder.split(" ");

Expand All @@ -140,18 +144,16 @@ const sortAndLimitProjects = (collection) => {
// Not sure, default to created_at desc
return a[sortField] > b[sortField] ? 1 : -1;
})
.slice(0, numToShow)

return projects;
}



export {
PROJECTS_PER_COLLECTION,
flatten,
normalizeCollection,
resultTemplate,
sortProjects,
sortAndLimitProjects,
useLocalStorage,
useSSR,
Expand Down

0 comments on commit eef7a29

Please sign in to comment.