Skip to content

Commit 77513a3

Browse files
KianNHkodster28
andauthored
[Docs Site] Limit /changelog/ to 5 entries per product (#23975)
* [Docs Site] Limit /changelog/ to 5 entries per product * pagination * offload to search * Up # of default in view --------- Co-authored-by: kodster28 <[email protected]>
1 parent 7ca48b2 commit 77513a3

File tree

2 files changed

+43
-48
lines changed

2 files changed

+43
-48
lines changed

src/components/changelog/ProductSelect.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ export default function ProductSelect({ products, groups }: Props) {
6565
select.value = option.value;
6666
select.dispatchEvent(event);
6767
}
68+
69+
const search = document.querySelector<HTMLAnchorElement>(
70+
"#changelog-search-button",
71+
);
72+
73+
if (search) {
74+
if (
75+
options
76+
.find((opt) => opt.label === "Products")
77+
?.options?.includes(option)
78+
) {
79+
search.href = `/search/?contentType=Changelog+entry&product=${encodeURIComponent(option.label)}`;
80+
} else {
81+
search.href = `/search/?contentType=Changelog+entry`;
82+
}
83+
}
6884
};
6985

7086
return (

src/pages/changelog/index.astro

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,28 @@ import { productsByGroup } from "~/util/products";
1313
1414
import { render } from "astro:content";
1515
16-
const notes = await getChangelogs({
16+
let notes = await getChangelogs({
1717
filter: (entry) => !entry.data.hidden,
1818
});
1919
20+
const seen = new Map<string, number>();
21+
22+
notes = notes.flatMap((note) => {
23+
const products = note.data.products.map((product) => product.id);
24+
25+
for (const product of products) {
26+
const previous = seen.get(product) || 0;
27+
28+
seen.set(product, previous + 1);
29+
30+
if (previous >= 5) {
31+
return [];
32+
}
33+
}
34+
35+
return note;
36+
});
37+
2038
const props = {
2139
frontmatter: {
2240
title: "Changelogs",
@@ -48,7 +66,7 @@ const props = {
4866

4967
return (
5068
<div
51-
class:list={["mt-0! sm:flex", { "hidden!": idx >= 10 }]}
69+
class:list={["mt-0! sm:flex", { "hidden!": idx >= 50 }]}
5270
data-products={JSON.stringify(
5371
productIds.concat(
5472
productGroups.map((group) =>
@@ -86,12 +104,13 @@ const props = {
86104
})
87105
}
88106
<div class="flex items-center justify-center">
89-
<button
90-
id="changelogs-next-button"
91-
class="bg-cl1-brand-orange text-cl1-black h-12 cursor-pointer rounded-sm px-6 font-medium"
107+
<a
108+
id="changelog-search-button"
109+
href="/search/?contentType=Changelog+entry"
110+
class="bg-cl1-brand-orange text-cl1-black mr-2 flex h-12 items-center justify-center rounded-sm px-6 font-medium no-underline"
92111
>
93-
Load more items
94-
</button>
112+
Search for historical entries
113+
</a>
95114
</div>
96115
</StarlightPage>
97116

@@ -100,10 +119,6 @@ const props = {
100119
"#changelogs-next-filter",
101120
);
102121

103-
const button = document.querySelector<HTMLButtonElement>(
104-
"#changelogs-next-button",
105-
);
106-
107122
const url = new URL(window.location.href);
108123

109124
if (filter && url.searchParams.has("product")) {
@@ -126,21 +141,6 @@ const props = {
126141
return products.includes(value);
127142
}
128143

129-
button?.addEventListener("click", () => {
130-
const hidden = [
131-
...document.querySelectorAll<HTMLElement>("[data-products]"),
132-
]
133-
.filter(
134-
(e) =>
135-
e.classList.contains("hidden!") && filterByProduct(e, filter!.value),
136-
)
137-
.slice(0, 10);
138-
139-
hidden.forEach((e) => e.classList.remove("hidden!"));
140-
141-
hideButton();
142-
});
143-
144144
function updateFilter() {
145145
const entries = [
146146
...document.querySelectorAll<HTMLElement>("[data-products]"),
@@ -152,7 +152,7 @@ const props = {
152152

153153
const filtered = entries
154154
.filter((e) => filterByProduct(e, value))
155-
.slice(0, 10);
155+
.slice(0, 5);
156156

157157
for (const entry of entries) {
158158
const show = filtered.includes(entry);
@@ -173,27 +173,6 @@ const props = {
173173
}
174174

175175
history.replaceState(null, "", url.href);
176-
177-
hideButton();
178-
}
179-
180-
function hideButton() {
181-
const entries = [
182-
...document.querySelectorAll<HTMLDivElement>("[data-products]"),
183-
];
184-
185-
if (entries.length === 0) return;
186-
187-
const filtered = entries.filter((p) => filterByProduct(p, filter!.value));
188-
189-
const visible = filtered.filter((p) => !p.classList.contains("hidden!"));
190-
const hidden = filtered.length - visible.length;
191-
192-
if (hidden > 0) {
193-
button!.classList.remove("hidden!");
194-
} else {
195-
button!.classList.add("hidden!");
196-
}
197176
}
198177
</script>
199178

0 commit comments

Comments
 (0)