Skip to content

Commit

Permalink
feat: Add target to categories
Browse files Browse the repository at this point in the history
  • Loading branch information
devcshort committed Nov 1, 2024
1 parent 171bb29 commit 122cb22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions bin/createAppFromStrapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,13 @@ module.exports = function createFromStrapi(dir) {
return {
name: cat['name'],
href: cat['href'],
target: cat['target'] || '_blank',
image:
matchingCategory?.['image']?.['data']?.['attributes']?.['url'],
subcategories: cat['subcategories'].map((sub) => ({
name: sub['name'],
href: sub['href'],
target: sub['target'] || '_blank',
query: sub['query'],
queryType: sub['queryType'],
})),
Expand All @@ -263,10 +265,12 @@ module.exports = function createFromStrapi(dir) {
{
name: category['name'],
href: category['href'],
target: category['target'] || '_blank',
image: category['image']?.['data']?.['attributes']?.['url'],
subcategories: category['subcategories'].map((sub) => ({
name: sub['name'],
href: sub['href'],
target: sub['target'] || '_blank',
query: sub['query'],
queryType: sub['queryType'],
})),
Expand Down
12 changes: 9 additions & 3 deletions src/features/home/components/categories-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ type Props = {
name: string;
image?: string;
href?: string;
target?: string;
subcategories: any[];
};

const Category = ({ image, name, href, subcategories }: Props) => {
const Category = ({ image, name, href, target, subcategories }: Props) => {
if (subcategories && subcategories.length > 0) {
return (
<div className="flex items-start gap-2">
Expand Down Expand Up @@ -45,9 +46,14 @@ const Category = ({ image, name, href, subcategories }: Props) => {
)}&query_type=${encodeURIComponent(el.queryType)}`
}`}
prefetch={false}
target={el.target}
>
{el.name}
{el.href ? <ExternalLink className="size-4" /> : null}
{el.target === '_blank' && el.href ? (
<ExternalLink className="size-4" />
) : (
false
)}
</Link>
))}
</div>
Expand All @@ -56,7 +62,7 @@ const Category = ({ image, name, href, subcategories }: Props) => {
}

return (
<Link href={href || '/'} className="group hover:underline">
<Link href={href || '/'} className="group hover:underline" target={target}>
<Card>
<CardContent>
{image && (
Expand Down

0 comments on commit 122cb22

Please sign in to comment.