-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Autogenerated sidebar item from subfolder don't respect index.md
at the subfolder root
#9153
Comments
Try this configuration:https://docusaurus.io/docs/sidebar/autogenerated you can't simply replace with an index.md. you have to autogenerate using the docs dirname here in docusaurus |
@caramelmelmel I'm using that configuration, check out the More generally, assuming this structure:
I would expect this:
to translate in:
because an |
no you cannot assume that index.md would directly translate to index.html here as docusaurus already automatically maps to docs in its route. Here's how you can do it
|
if you want to manipulate the keys you cannot just touch the docusaurus.config.js there are other repositories that use the component page routing from the config to perform something like this. Let me know if I did not answer your question. You have to have the |
Thanks @caramelmelmel, I think the use case I was trying to come across is not entirely clear, let me expand a bit. Imagine you want to have some part of the sidebar being autogenerated and some part being manually managed:
The corresponding sidebar config I would think it should suffice is:
but that would lead to:
reather than:
Taking your example, this:
would still not work as I would expect for:
leading to:
rather than:
I guess, regardless by the underlying implementation, I don't fully understand why the |
but as far as I know the auto and manual configurations cannot mix together as auto means I take from the folder itself based on the mapped Id for that one folder. |
Instead, this could not be a bug. You might want to ask about this in Discord. |
Posted on Discord but didn't have much traction. My biggest concern still stands so I'll leave this open:
I believe this ultimately makes mixing manual and autogenerated sidebars harder than it should be. |
You generate an entire sidebar from a folder; you don't just generate one category. |
Thanks @Josh-Cena!
Out curiosity, would there be any downside to make the root folder become a category if there is an |
I think a new sidebar item called |
@Josh-Cena Just to clarify, I think an autogenerated-category works by enabling a subfolder in docs to become an auto-generated category if an index.md is added? If I get you correctly? else, I would really want to work on this issue as I face the same problem of having index.md not appearing as a subfolder as I would like on my sidebar |
@fabriziocucci the current behavior is expected. The const sidebars = {
tutorialSidebar: [
"intro",
{type: 'autogenerated', dirName: 'tutorial-basics'},
{type: 'autogenerated', dirName: 'tutorial-extras'},
],
} This config is not supposed to use Similarly if you to: const sidebars = {
tutorialSidebar: [
{type: 'autogenerated', dirName: '.'},
],
} Then we don't use a What you really want is something like this: const sidebars = {
tutorialSidebar: [
"intro",
{
type: "category",
label: "Tutorial basics",
link: {type: 'doc', id: 'tutorial-basics/index'},
items: [{type: 'autogenerated', dirName: 'tutorial-basics'},],
},
{
type: "category",
label: "Tutorial Extras",
link: {type: 'doc', id: 'tutorial-extras/index'},
items: [{type: 'autogenerated', dirName: 'tutorial-extras'},],
}
],
} And yes I admit this is not as straightforward as what you thought would work, but it's a generic/low-level/flexible way to support many patterns without too much magic. Note in #5689 we would already like to support include/exclude attributes like this: const sidebars = {
tutorialSidebar: [
"intro",
{type: 'autogenerated', dirName: '.', include: ["tutorial-basics", "tutorial-extras"]},
],
} Or this: const sidebars = {
tutorialSidebar: [
"intro",
{type: 'autogenerated', dirName: '.', include: ["tutorial-basics"]},
{type: 'autogenerated', dirName: '.', include: ["tutorial-extras"]},
],
} So if we support this, the behavior you want becomes less needed. We can keep something based on the concept of "sidebar slice" (without magic nor edge-case exceptions), and still have a concise API.
@Josh-Cena I would prefer to first introduce |
@slorber what I really think about including index.md in the subfolder is that the user is able to customise the introduction page however he or she likes instead of using a category.json so by providing the /index.md functionality, and then autogenerating the sub bars in a sidebar, based on the presence of this index.md helps to provide this functionality of customisation here. |
Neither the presence of |
Thanks @slorber and @Josh-Cena for the comments. @slorber, regarding:
I was going to say, that's not gonna fully work without a way to exclude Being able to exclude files like in #5689 will definitely help, looking forward to it! @Josh-Cena, regarding:
For some reason, from a user prospective without any clue about the implementation details, I had exactly this expectation! I agree that I appreciate you guys taking the time to even evaluate this, keep up the good work! 🙂 |
{
type: "category",
label: "Tutorial basics",
link: {type: 'doc', id: 'tutorial-basics/index'},
items: [{type: 'autogenerated', dirName: 'tutorial-basics'},],
}, As far as I remember (not 100% sure) we have logic so that if it's already a category link, index is excluded from the sidebar slice to prevent this. We'll add the include/exclude feature first and eventually see if
If we implement this as a convention, then it becomes impossible to generate a sidebar slice including the index. By implementing your use case we might break another user use case, with no easy workaround to opt-out apart renaming a file that is maybe named "index" on purpose. I'd rather keep the ability to be able to support both if possible, even if it makes the API slightly less intuitive. I think your convention could make sense, but it's more like a shortcut and I'd prefer to delay implementing it until we are sure it's really needed. |
It actually highlight both links at the same time (category and page) but it does not remove the actual index page from the page list in the category. |
Another side effect of this is that when you're viewing the index category page, the pagination's "next" link is the same page. The pagination next link becomes unusable here as it links to itself. After following all of these threads, I decided to simply do an entire sidebar as autogenerated instead of trying to achieve this. It's too janky without being able to exclude the index file from the autogenerated child items. |
Have you read the Contributing Guidelines on issues?
Prerequisites
npm run clear
oryarn clear
command.rm -rf node_modules yarn.lock package-lock.json
and re-installing packages.Description
It seems that autogenerated items for subfolders containing an
index.md
file don't show up as sections.For instance, on the sample website from the the 5m tutorial, I would have expected this:
to create two sections in the sidebar because they both contain a
_category_.json
file but everything is actually flattened at the root. Replacing both_category_.json
with anindex.md
leads to the same results.Is this expected?
Reproducible demo
CodeSandbox
Steps to reproduce
npm init docusaurus@latest my-website classic
sidebars.js
from:to
Expected behavior
I would expect two sections to appear in the sidebar since both subfolders contain a
_category_.json
.Actual behavior
The content of the two sections is actually flattened at the root.
NOTE: replacing the
_category_.json
files with anindex.md
files leads to the same results.Your environment
Self-service
The text was updated successfully, but these errors were encountered: