mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-15 10:07:33 +02:00
feat(content-docs): sidebar category linking to document or auto-generated index page (#5830)
Co-authored-by: Joshua Chen <sidachen2003@gmail.com> Co-authored-by: Armano <armano2@users.noreply.github.com> Co-authored-by: Alexey Pyltsyn <lex61rus@gmail.com>
This commit is contained in:
parent
95f911efef
commit
cfae5d0933
105 changed files with 3904 additions and 816 deletions
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {CategoryGeneratedIndexMetadata, DocMetadataBase} from './types';
|
||||
import {SidebarItemCategoryWithGeneratedIndex} from './sidebars/types';
|
||||
import {SidebarsUtils, toNavigationLink} from './sidebars/utils';
|
||||
import {createDocsByIdIndex} from './docs';
|
||||
|
||||
function getCategoryGeneratedIndexMetadata({
|
||||
category,
|
||||
sidebarsUtils,
|
||||
docsById,
|
||||
}: {
|
||||
category: SidebarItemCategoryWithGeneratedIndex;
|
||||
sidebarsUtils: SidebarsUtils;
|
||||
docsById: Record<string, DocMetadataBase>;
|
||||
}): CategoryGeneratedIndexMetadata {
|
||||
const {sidebarName, previous, next} =
|
||||
sidebarsUtils.getCategoryGeneratedIndexNavigation(category.link.permalink);
|
||||
if (!sidebarName) {
|
||||
throw new Error('unexpected');
|
||||
}
|
||||
|
||||
return {
|
||||
title: category.link.title ?? category.label,
|
||||
description: category.link.description,
|
||||
slug: category.link.slug,
|
||||
permalink: category.link.permalink,
|
||||
sidebar: sidebarName,
|
||||
previous: toNavigationLink(previous, docsById),
|
||||
next: toNavigationLink(next, docsById),
|
||||
};
|
||||
}
|
||||
|
||||
export function getCategoryGeneratedIndexMetadataList({
|
||||
docs,
|
||||
sidebarsUtils,
|
||||
}: {
|
||||
sidebarsUtils: SidebarsUtils;
|
||||
docs: DocMetadataBase[];
|
||||
}): CategoryGeneratedIndexMetadata[] {
|
||||
const docsById = createDocsByIdIndex(docs);
|
||||
|
||||
const categoryGeneratedIndexItems =
|
||||
sidebarsUtils.getCategoryGeneratedIndexList();
|
||||
return categoryGeneratedIndexItems.map((category) =>
|
||||
getCategoryGeneratedIndexMetadata({
|
||||
category,
|
||||
sidebarsUtils,
|
||||
docsById,
|
||||
}),
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue