mirror of
https://github.com/pheralb/svgl.git
synced 2025-12-29 08:01:36 +08:00
feat: multiple category feature
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user