feat: multiple category feature

This commit is contained in:
ridemountainpig
2024-01-16 11:27:57 +08:00
parent 0fc7ab88c4
commit 6d5e54b602
5 changed files with 46 additions and 13 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
// Get categories:
import { svgs } from '@/data/svgs';
const categories = svgs
.map((svg) => svg.category)
.flatMap((svg) => Array.isArray(svg.category) ? svg.category : [svg.category])
.filter((category, index, array) => array.indexOf(category) === index);
// Icons:
+7 -1
View File
@@ -13,7 +13,13 @@ export const load = (async ({ params }) => {
}
// Filter out the svg with the matching slug:
const svgsByCategory = svgs.filter((svg: iSVG) => svg.category.toLowerCase() === slug);
const svgsByCategory = svgs.filter((svg: iSVG) => {
if (Array.isArray(svg.category)) {
return svg.category.some(categoryItem => categoryItem.toLowerCase() === slug);
} else {
return svg.category.toLowerCase() === slug;
}
});
return {
category: slug as string,