Allow not specfying section header in sidebar. (#2448)

Someone may forget to specify a section header in SIDEBAR,
which would cause build error previously.
This commit is contained in:
Jang Rush 2022-01-24 23:33:56 +08:00 committed by GitHub
parent 1f45d23103
commit 20dc304172
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,7 +5,14 @@ const { currentPage } = Astro.props;
const currentPageMatch = currentPage.slice(1);
const langCode = getLanguageFromURL(currentPage);
// SIDEBAR is a flat array. Group it by sections to properly render.
const sidebarSections = SIDEBAR[langCode].reduce((col, item) => {
const sidebarSections = SIDEBAR[langCode].reduce((col, item, i) => {
// If the first item is not a section header, create a new container section.
if (i === 0) {
if (!item.header) {
const pesudoSection = { text: "" };
col.push({ ...pesudoSection, children: [] });
}
}
if (item.header) {
col.push({ ...item, children: [] });
} else {