Skip to content

Commit b3959ae

Browse files
committed
simplify ProductChangelog
1 parent 010dd5f commit b3959ae

File tree

1 file changed

+31
-38
lines changed

1 file changed

+31
-38
lines changed

src/components/ProductChangelog.astro

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { reference } from "astro:content";
44
import { z } from "astro:schema";
55
import { getCollection, render } from "astro:content";
66
import { slug } from "github-slugger";
7+
import { format } from "date-fns";
8+
79
import RSSButton from "~/components/RSSButton.astro";
810
import AnchorHeading from "~/components/AnchorHeading.astro";
9-
import { format } from "date-fns";
1011
import ProductPills from "~/components/changelog/ProductPills.astro";
1112
1213
const props = z
@@ -19,67 +20,59 @@ const props = z
1920
}),
2021
)
2122
.and(
22-
z.object({
23-
hideEntry: z.string().optional(),
24-
}),
25-
);;
23+
z.object({
24+
hideEntry: z.string().optional(),
25+
}),
26+
);
27+
2628
const input = await props.parseAsync(Astro.props);
29+
2730
let filter: GetChangelogsOptions["filter"];
2831
let rss: string;
29-
let areaFeed: boolean
32+
3033
if ("product" in input) {
3134
rss = `/changelog/rss/${input.product.id}.xml`;
32-
areaFeed = false;
35+
3336
filter = (e) => {
3437
return (
35-
!e.data.hidden &&
36-
e.data.products.some(({ id }) => id === input.product.id) &&
37-
input.hideEntry !== e.id
38-
);
38+
!e.data.hidden &&
39+
e.data.products.some(({ id }) => id === input.product.id) &&
40+
input.hideEntry !== e.id
41+
);
3942
};
4043
} else {
4144
rss = `/changelog/rss/${slug(input.area)}.xml`;
42-
areaFeed = true;
45+
4346
const products = await getCollection("products", (e) => {
44-
return e.data.product.group === input.area &&
45-
input.hideEntry !== e.id;
47+
return e.data.product.group === input.area && input.hideEntry !== e.id;
4648
});
49+
4750
filter = (e) => {
4851
return e.data.products.some((x) => products.some((y) => x.id === y.id));
4952
};
5053
}
54+
5155
const changelogs = await getChangelogs({ filter });
5256
---
5357

5458
<RSSButton href={rss} />
5559

5660
{
5761
changelogs.map(async (entry) => {
58-
59-
6062
const { Content } = await render(entry);
61-
// If areaFeed is true, add ProductPills
62-
if (areaFeed === true) {
63-
return (
64-
<AnchorHeading depth={2} title={format(entry.data.date, "yyyy-MM-dd")} />
65-
<ProductPills products={entry.data.products} />
66-
<br />
67-
<strong>{entry.data.title}</strong>
68-
<br />
69-
<Content />
70-
);
71-
}
72-
7363

74-
// Default output
75-
return (
76-
<>
77-
<AnchorHeading depth={2} title={format(entry.data.date, "yyyy-MM-dd")} />
78-
<br />
79-
<strong>{entry.data.title}</strong>
80-
<br />
81-
<Content />
82-
</>
64+
return (
65+
<>
66+
<AnchorHeading
67+
depth={2}
68+
title={format(entry.data.date, "yyyy-MM-dd")}
69+
/>
70+
{"area" in input && <ProductPills products={entry.data.products} />}
71+
<br />
72+
<strong>{entry.data.title}</strong>
73+
<br />
74+
<Content />
75+
</>
8376
);
8477
})
85-
}
78+
}

0 commit comments

Comments
 (0)