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
commit 44b6201b75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 50 additions and 9 deletions

View File

@ -44,8 +44,13 @@
// Download SVG: // Download SVG:
const downloadSvg = (url?: string) => { const downloadSvg = (url?: string) => {
download(url || ''); download(url || '');
const category = Array.isArray(svgInfo.category)
? svgInfo.category.sort().join(' - ')
: svgInfo.category;
toast.success(`Downloading...`, { toast.success(`Downloading...`, {
description: `${svgInfo.title} - ${svgInfo.category}` description: `${svgInfo.title} - ${category}`
}); });
}; };
@ -81,8 +86,12 @@
download(content, `${svgInfo.title}.zip`, 'application/zip'); download(content, `${svgInfo.title}.zip`, 'application/zip');
}); });
const category = Array.isArray(svgInfo.category)
? svgInfo.category.sort().join(' - ')
: svgInfo.category;
toast.success('Downloading light & dark variants...', { toast.success('Downloading light & dark variants...', {
description: `${svgInfo.title} - ${svgInfo.category}` description: `${svgInfo.title} - ${category}`
}); });
}; };
@ -105,22 +114,26 @@
await navigator.clipboard.writeText(content); await navigator.clipboard.writeText(content);
} }
const category = Array.isArray(svgInfo.category)
? svgInfo.category.sort().join(' - ')
: svgInfo.category;
if (isInFigma) { if (isInFigma) {
toast.success('Ready to paste in Figma!', { toast.success('Ready to paste in Figma!', {
description: `${svgInfo.title} - ${svgInfo.category}` description: `${svgInfo.title} - ${category}`
}); });
return; return;
} }
if (wordmarkSvg) { if (wordmarkSvg) {
toast.success('Copied wordmark SVG to clipboard!', { toast.success('Copied wordmark SVG to clipboard!', {
description: `${svgInfo.title} - ${svgInfo.category}` description: `${svgInfo.title} - ${category}`
}); });
return; return;
} }
toast.success('Copied to clipboard!', { toast.success('Copied to clipboard!', {
description: `${svgInfo.title} - ${svgInfo.category}` description: `${svgInfo.title} - ${category}`
}); });
}; };
@ -178,6 +191,25 @@
<p class="truncate text-[15px] font-medium text-balance text-center select-all"> <p class="truncate text-[15px] font-medium text-balance text-center select-all">
{svgInfo.title} {svgInfo.title}
</p> </p>
<div class="flex flex-wrap justify-center">
{#if Array.isArray(svgInfo.category)}
{#each svgInfo.category.sort() as c, index}
<a
href={`/directory/${c.toLowerCase()}`}
class="text-sm lowercase text-neutral-500 hover:underline font-mono">{c}</a
>
{#if index < svgInfo.category.length - 1}
<span class="text-neutral-500">.</span>
{/if}
{/each}
{:else}
<a
href={`/directory/${svgInfo.category.toLowerCase()}`}
class="text-sm lowercase text-neutral-500 hover:underline font-mono"
>{svgInfo.category}</a
>
{/if}
</div>
<a <a
href={`/directory/${svgInfo.category.toLowerCase()}`} href={`/directory/${svgInfo.category.toLowerCase()}`}
class="text-sm lowercase text-neutral-400 hover:underline font-mono">{svgInfo.category}</a class="text-sm lowercase text-neutral-400 hover:underline font-mono">{svgInfo.category}</a

View File

@ -1153,7 +1153,7 @@ export const svgs: iSVG[] = [
}, },
{ {
title: 'WordPress', title: 'WordPress',
category: 'Software', category: ['Software', 'CMS'],
route: '/library/wordpress.svg', route: '/library/wordpress.svg',
url: 'https://wordpress.org/' url: 'https://wordpress.org/'
}, },

View File

@ -8,7 +8,7 @@
// Get categories: // Get categories:
import { svgs } from '@/data/svgs'; import { svgs } from '@/data/svgs';
const categories = 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); .filter((category, index, array) => array.indexOf(category) === index);
// Toaster: // Toaster:

View File

@ -13,7 +13,13 @@ export const load = (async ({ params }) => {
} }
// Filter out the svg with the matching slug: // 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 { return {
category: slug as string, category: slug as string,

View File

@ -1,9 +1,12 @@
import type { tCategory } from './categories'; import type { tCategory } from './categories';
type tCategoryPair = [tCategory, tCategory];
type CategoryTriple = [tCategory, tCategory, tCategory];
export interface iSVG { export interface iSVG {
id?: number; id?: number;
title: string; title: string;
category: tCategory; category: tCategory | tCategoryPair | CategoryTriple;
route: route:
| string // for backwards compat of when theme support was not added | string // for backwards compat of when theme support was not added
| { | {