fix(docs,theme): auto-generated category index should not display unlisted content (#8319)

This commit is contained in:
Sébastien Lorber 2022-11-10 18:31:01 +01:00 committed by GitHub
parent 1d5afbaaa5
commit d8c72fb32d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 189 additions and 28 deletions

View file

@ -79,27 +79,38 @@ export function findSidebarCategory(
* Best effort to assign a link to a sidebar category. If the category doesn't
* have a link itself, we link to the first sub item with a link.
*/
export function findFirstCategoryLink(
export function findFirstSidebarItemCategoryLink(
item: PropSidebarItemCategory,
): string | undefined {
if (item.href) {
if (item.href && !item.linkUnlisted) {
return item.href;
}
for (const subItem of item.items) {
if (subItem.type === 'link') {
return subItem.href;
} else if (subItem.type === 'category') {
const categoryLink = findFirstCategoryLink(subItem);
if (categoryLink) {
return categoryLink;
}
const link = findFirstSidebarItemLink(subItem);
if (link) {
return link;
}
// Could be "html" items
}
return undefined;
}
/**
* Best effort to assign a link to a sidebar item.
*/
export function findFirstSidebarItemLink(
item: PropSidebarItem,
): string | undefined {
if (item.type === 'link' && !item.unlisted) {
return item.href;
}
if (item.type === 'category') {
return findFirstSidebarItemCategoryLink(item);
}
// Other items types, like "html"
return undefined;
}
/**
* Gets the category associated with the current location. Should only be used
* on category index pages.
@ -391,15 +402,16 @@ export function useDocRootMetadata({route}: DocRootProps): null | {
}
/**
* Filter categories that don't have a link.
* Filter items we don't want to display on the doc card list view
* @param items
*/
export function filterDocCardListItems(
items: PropSidebarItem[],
): PropSidebarItem[] {
return items.filter((item) => {
if (item.type === 'category') {
return !!findFirstCategoryLink(item);
const canHaveLink = item.type === 'category' || item.type === 'link';
if (canHaveLink) {
return !!findFirstSidebarItemLink(item);
}
return true;
});