feat: allow collapsing widget content, add categories widget
(cherry picked from commit 9a4ca8f6163d5e1375aa7c612e1338cce5a8c0b5)
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
---
|
||||
import WidgetLayout from "./WidgetLayout.astro";
|
||||
|
||||
import {i18n} from "../../i18n/translation";
|
||||
import I18nKey from "../../i18n/i18nKey";
|
||||
import {CategoryMap, getCategoryMap} from "../../utils/content-utils";
|
||||
import CategoriesLink from "./CategoriesLink.astro";
|
||||
|
||||
const categories = await getCategoryMap();
|
||||
|
||||
const COLLAPSED_HEIGHT = "120px";
|
||||
const COLLAPSE_THRESHOLD = 5;
|
||||
|
||||
function count(categoryMap: CategoryMap): number {
|
||||
let res = 0;
|
||||
for (const key in categoryMap) {
|
||||
res++;
|
||||
res += count(categoryMap[key].children);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
const isCollapsed = count(categories) >= COLLAPSE_THRESHOLD;
|
||||
|
||||
interface Props {
|
||||
categories: CategoryMap;
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
<WidgetLayout name={i18n(I18nKey.categories)} id="categories" isCollapsed={isCollapsed} collapsedHeight={COLLAPSED_HEIGHT}>
|
||||
<CategoriesLink categories={categories}></CategoriesLink>
|
||||
</WidgetLayout>
|
||||
Reference in New Issue
Block a user