Skip to content

Commit

Permalink
fix: allow tags to be optional in items
Browse files Browse the repository at this point in the history
related to AOEpeople#430
  • Loading branch information
mathiasschopmans committed Mar 13, 2024
1 parent 04053c6 commit 5750723
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
9 changes: 7 additions & 2 deletions scripts/buildData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function getUniqueReleases(items: Item[]): string[] {
function getUniqueTags(items: Item[]): string[] {
const tags = new Set<string>();
for (const item of items) {
for (const tag of item.tags) {
for (const tag of item.tags || []) {
tags.add(tag);
}
}
Expand Down Expand Up @@ -187,7 +187,7 @@ function postProcessItems(items: Item[]): {
// check if config has a key `tags` and if it is an array
if (Array.isArray(tags) && tags.length) {
// if tags are specified, only keep items that have at least one of the tags
return item.tags.some((tag) => tags.includes(tag));
return item.tags?.some((tag) => tags.includes(tag));
}

return true;
Expand Down Expand Up @@ -219,6 +219,11 @@ function postProcessItems(items: Item[]): {
delete processedItem.revisions;
}

// unset tags if there are none
if (!processedItem.tags?.length) {
delete processedItem.tags;
}

return processedItem;
});

Expand Down
4 changes: 1 addition & 3 deletions src/components/ItemDetail/ItemDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ export function ItemDetail({ item }: ItemProps) {
<>
<div className={styles.header}>
<h1 className={styles.title}>{item.title}</h1>
{item.tags.map((tag) => (
<Tag key={tag} tag={tag} />
))}
{item.tags?.map((tag) => <Tag key={tag} tag={tag} />)}
</div>
<div className={styles.revisions}>
{notMaintainedText && isNotMaintained(item.release) && (
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface Item {
ring: string;
quadrant: string;
flag: Flag;
tags: string[];
tags?: string[];
release: Release;
revisions?: Revision[];
position: [x: number, y: number];
Expand Down
4 changes: 2 additions & 2 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Home: CustomPage = () => {
const quadrants = getQuadrants();
const tags = getTags();
const items = getItems(undefined, true).filter(
(item) => !tag || item.tags.includes(tag),
(item) => !tag || item.tags?.includes(tag),
);

return (
Expand All @@ -41,7 +41,7 @@ const Home: CustomPage = () => {
rings={rings}
items={items}
/>
<Tags tags={tags} activeTag={tag} />
{tags.length > 0 && <Tags tags={tags} activeTag={tag} />}
<QuadrantList items={items} />
</>
);
Expand Down

0 comments on commit 5750723

Please sign in to comment.