Skip to content

Commit

Permalink
Sort screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
mitjapotocin committed Dec 8, 2023
1 parent 33836da commit 517088b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pages/screenshots/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import path from "path";
import MainLayout from "@components/UiKit/MainLayout";
import device from "@styles/utils/breakpoints";
import ImageGallery from "@components/ImageGallery/ImageGallery";
import sortByWeight from "@utils/sortByWeight";

interface IScreenshots {
title: string;
image: ImageProps;
thumbnailImage: ImageProps;
weight: number;
}

export async function getStaticProps() {
Expand All @@ -29,19 +31,19 @@ export async function getStaticProps() {
const { data: frontmatter } = matter(mdFile);

screenshots.push({
title: frontmatter.title,
...frontmatter,
image: getOptimizedImageAttributes(
path.join(path.sep, dirInPublic, frontmatter.image),
) as ImageProps,
thumbnailImage: getOptimizedImageAttributes(
path.join(path.sep, dirInPublic, frontmatter.thumbnailImage),
) as ImageProps,
});
} as IScreenshots);
}

return {
props: {
screenshots,
screenshots: sortByWeight(screenshots),
},
};
}
Expand Down
7 changes: 7 additions & 0 deletions utils/sortByWeight.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function sortByWeight(items: any[]) {
if (!Array.isArray(items)) {
throw new Error("Item is not an array");
}

return items.sort((a, b) => a.weight || 99999 - b.weight || 99999);
}

0 comments on commit 517088b

Please sign in to comment.