mirror of
https://github.com/saicaca/fuwari.git
synced 2026-01-13 07:42:52 +01:00
feat: remove support for nested categories
This commit is contained in:
@@ -3,31 +3,25 @@ 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";
|
||||
import {Category, getCategoryList} from "../../utils/content-utils";
|
||||
import {getCategoryUrl} from "../../utils/url-utils";
|
||||
import ButtonLink from "../control/ButtonLink.astro";
|
||||
|
||||
const categories = await getCategoryMap();
|
||||
const categories = await getCategoryList();
|
||||
|
||||
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;
|
||||
const isCollapsed = categories.length >= COLLAPSE_THRESHOLD;
|
||||
|
||||
interface Props {
|
||||
categories: CategoryMap;
|
||||
categories: Category[];
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
<WidgetLayout name={i18n(I18nKey.categories)} id="categories" isCollapsed={isCollapsed} collapsedHeight={COLLAPSED_HEIGHT}>
|
||||
<CategoriesLink categories={categories}></CategoriesLink>
|
||||
{categories.map((c) =>
|
||||
<ButtonLink url={getCategoryUrl(c.name)} badge={c.count} label=`View all posts in the ${c.name} category`>{c.name}</ButtonLink>
|
||||
)}
|
||||
</WidgetLayout>
|
||||
@@ -1,21 +0,0 @@
|
||||
---
|
||||
|
||||
import {CategoryMap} from "../../utils/content-utils";
|
||||
import {getCategoryUrl} from "../../utils/url-utils";
|
||||
import ButtonLink from "../control/ButtonLink.astro";
|
||||
|
||||
interface Props {
|
||||
categories: CategoryMap;
|
||||
}
|
||||
|
||||
const {categories} = Astro.props;
|
||||
|
||||
---
|
||||
<div>
|
||||
{Object.entries(categories).map(([key, value]) =>
|
||||
<ButtonLink url={getCategoryUrl(key)} badge={value.count} label=`View all posts in the ${value.name} category`>{value.name}</ButtonLink>
|
||||
<div class="ml-2">
|
||||
{Object.keys(value.children).length > 0 && <Astro.self categories={value.children}></Astro.self>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
Reference in New Issue
Block a user