Merge pull request #212 from ridemountainpig/multiple-category

Add SVG with multiple category feature
This commit is contained in:
Pablo Hdez
2024-01-24 11:05:01 +00:00
committed by GitHub
5 changed files with 50 additions and 9 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);
// Toaster:
+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,