Replies: 5 comments 15 replies
-
Hey Currently, it is not possible but it makes sense to me. I guess it does not make much sense for a category to have only a single doc in it. |
Beta Was this translation helpful? Give feedback.
-
The same effect will be riched by:
|
Beta Was this translation helpful? Give feedback.
-
There's a workaround for current version: You can configure function unwrapCategory(items) {
return items.map((item) => {
if (item.type === 'category' && item.items.length === 1) {
return item.items[0];
}
return item;
});
}
sidebarItemsGenerator: async function ({defaultSidebarItemsGenerator, ...args}) {
const sidebarItems = await defaultSidebarItemsGenerator(args);
return unwrapCategory(sidebarItems);
}, FYI, using a |
Beta Was this translation helpful? Give feedback.
-
Hi @slorber , Seems the problem could also be solved by the new feature Category index convention in beta 10. But I could not figure it out to make the category item show up in sidebar. Let say, I have the following folder structure: docs No matter I named the markdown file with the same of the folder, index.md or readme.md. May I have your assist please? Thank you. |
Beta Was this translation helpful? Give feedback.
-
I needed something similar, which is to have what I'm calling "transparent" folders that don't generate a category. Here's what I ended up with: module.exports = async function ({ defaultSidebarItemsGenerator, ...args }) {
const sidebarItems = await defaultSidebarItemsGenerator(args);
return hideTransparentFolders(sidebarItems);
};
// In order to keep images nearby to markdown and not lose links to them if we rename things, we
// can wrap each file in a folder that contains the MD and the images. However, sometimes this
// is not a natural category, so we wan that folder to be "transparent". Our convention is to
// indicate that we want the folder to be transparent by appending "-" to the folder.
function hideTransparentFolders(items) {
if (!items) {
return items;
}
return items.flatMap((item) => {
if (
item.type === "category" &&
item.label.indexOf("-") === item.label.length - 1 // name ends in our transparent folder indicator
) {
return item.items;
}
if (item.items) {
return {
...item,
items: hideTransparentFolders(item.items),
};
} else {
return item;
}
});
} |
Beta Was this translation helpful? Give feedback.
-
Hi,
I do like the new feature supporting sub folder about blog.
I'm wondering if it is possible to have the last level folder ignored when I'm using the autogenerated sidebars feature?
Let say, I have the folder structure:
docs
|-- category1
|-- document1
|-- document1.md
|-- image01.png
|-- image02.png
I would like to put markdown file and related assets in the same folder to get better edit experience and also management.
And the autogenerated sidebar will be:
docs
|-- category1
|-- document1 (generated by folder)
|-- document1 (generated by md file)
Is it possible to ignore the generated by folder one while using autogenerated sidebars?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions