fix: allow tags to be optional in items

related to #430
This commit is contained in:
Mathias Schopmans
2024-03-13 14:47:33 +01:00
parent 04053c6700
commit 5750723c40
4 changed files with 11 additions and 8 deletions

View File

@@ -134,7 +134,7 @@ function getUniqueReleases(items: Item[]): string[] {
function getUniqueTags(items: Item[]): string[] { function getUniqueTags(items: Item[]): string[] {
const tags = new Set<string>(); const tags = new Set<string>();
for (const item of items) { for (const item of items) {
for (const tag of item.tags) { for (const tag of item.tags || []) {
tags.add(tag); tags.add(tag);
} }
} }
@@ -187,7 +187,7 @@ function postProcessItems(items: Item[]): {
// check if config has a key `tags` and if it is an array // check if config has a key `tags` and if it is an array
if (Array.isArray(tags) && tags.length) { if (Array.isArray(tags) && tags.length) {
// if tags are specified, only keep items that have at least one of the tags // 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; return true;
@@ -219,6 +219,11 @@ function postProcessItems(items: Item[]): {
delete processedItem.revisions; delete processedItem.revisions;
} }
// unset tags if there are none
if (!processedItem.tags?.length) {
delete processedItem.tags;
}
return processedItem; return processedItem;
}); });

View File

@@ -23,9 +23,7 @@ export function ItemDetail({ item }: ItemProps) {
<> <>
<div className={styles.header}> <div className={styles.header}>
<h1 className={styles.title}>{item.title}</h1> <h1 className={styles.title}>{item.title}</h1>
{item.tags.map((tag) => ( {item.tags?.map((tag) => <Tag key={tag} tag={tag} />)}
<Tag key={tag} tag={tag} />
))}
</div> </div>
<div className={styles.revisions}> <div className={styles.revisions}>
{notMaintainedText && isNotMaintained(item.release) && ( {notMaintainedText && isNotMaintained(item.release) && (

View File

@@ -21,7 +21,7 @@ export interface Item {
ring: string; ring: string;
quadrant: string; quadrant: string;
flag: Flag; flag: Flag;
tags: string[]; tags?: string[];
release: Release; release: Release;
revisions?: Revision[]; revisions?: Revision[];
position: [x: number, y: number]; position: [x: number, y: number];

View File

@@ -24,7 +24,7 @@ const Home: CustomPage = () => {
const quadrants = getQuadrants(); const quadrants = getQuadrants();
const tags = getTags(); const tags = getTags();
const items = getItems(undefined, true).filter( const items = getItems(undefined, true).filter(
(item) => !tag || item.tags.includes(tag), (item) => !tag || item.tags?.includes(tag),
); );
return ( return (
@@ -41,7 +41,7 @@ const Home: CustomPage = () => {
rings={rings} rings={rings}
items={items} items={items}
/> />
<Tags tags={tags} activeTag={tag} /> {tags.length > 0 && <Tags tags={tags} activeTag={tag} />}
<QuadrantList items={items} /> <QuadrantList items={items} />
</> </>
); );