-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Add Breadcrumb customization options #6953
Comments
Hi, in a perfect world, this would be the case; however, this is virtually not achievable. Routes are very arbitrary. Because you can use Now, maybe the issue is just a misconception of how breadcrumbs work, but being maximally charitable, this is actually what we plan to do: including more segments in the breadcrumbs. However, the problem is that the |
Thanks for the info, this is more complex than I appreciated. It seems like the discussions in #6786 may include changes that would address my issue. I've posted a comment there. |
As commented in the other issue, it looks like a plugin option such as: breadcrumbPrefix: [
{ to: "/", label: "🏠" },
{ to: "/docs", label: "Docs home" }
]; could work for you? Eventually, we could also add "breadcrumb item types", to cover more dynamic cases like showing a human-readable sidebar label? breadcrumbPrefix: [
{ to: "/", label: "🏠" },
{ to: "/docs", label: "Docs home" },
{ type: "sidebarName" }
]; Does it make sense? (note we don't have any human-readable docs-plugin label or sidebar label yet) Some related questions:
|
I don't think I fully appreciate what can be done if we have the option type: "sidebarName", but I like the breadcrumbPrefix idea in general. I think having an individual doc override the breadcrumb makes sense. Something like:
I think this might be useful when the default breadcrumbPrefix is ["/", "/docs"] for the doc that has a slug of "/" (full url is "/docs") so the breadcrumb isn't " / -> /docs -> /docs where the last item is the current page, which is also the last item in the breadcrumbPrefix. (Although maybe this could be address in other logic.) |
Docusaurus site has 2 sidebars: Docs and API This means that one of those labels could eventually appear in the breadcrumb. For example: adding frontMatter can be convenient yes. Maybe for maximum flexibility you should be able to provide the full breadcrumb too? breadcrumb: [ { to: "/", label: "🏠" } , {to: "/docs/xyz", label :"XYZ" }]
breadcrumb:
prefix: [ { to: "/", label: "🏠" }] 🤷♂️ I don't understand the last part 😅 |
Thanks for the explanation. Having { type: "sidebarName" } as an option makes sense now. I think sites with multiple sidebars could use that functionality. My point about an individual doc overriding the default breadcrumb prefix is that when on a page that is included in the default breadcrumb prefix, that might generate a breadcrumb that lists the page twice: once as part of the prefix, and once as the current page. Having the means to change the breadcrumb prefix for just that page might be a useful way to avoid that issue. (But again, there are other solutions). I think having a breadcrumb prefix and a full breadcrumb override makes sense. One use case could be shortening the breadcrumbs (skipping some entries) for sites that have lots of structure. Or localizing it so you can't go 'too far' back in one shot. |
Hi guys, firstly, thanks for your contribution to the community, I really appreciate what you're doing and my team enjoys using Docusaurus. Preface/contextWe're currently using it to build an internal wiki website that would have several tech-stack scopes. Basically, the structure is similar like in @slorber's example. At the same time, we'd like to preserve the consistency within the
We're using several autogenerated sidebars (each one represents a directory within It's all working fine except the breadcrumbs, it basically ignores the starting directory in As the guys suggested, we could use the breadcrumb prefix like: So, my idea would be to also be able to use docs/
frontend/
_category_.json <!-- { breadcrumbPrefix: [ { to: "/", label: "🏠" } , {to: "/frontend", label :"Frontend" }] } -->
frameworks/
angular/
best-practices.md
whatever.md
backend/
_category_.json <!-- { breadcrumbPrefix: [ { to: "/", label: "🏠" } , {to: "/backend", label :"Backend" }] } -->
python/
best-practices.md
whatever.md This way, a breacrumb prefix could be auto-generated for all of the pages within these directories. For
I'm interested to hear your opinion on this, guys. And thanks again! |
Hi chernodub, I think I'm understanding what you want, and it seems to me, unless I'm missing something, that as currently structured the breadcrumbs will do what you want (except for the link to /docs). If you use the category index convention, and have:
then you will get an auto-generated breadcrumbs for /docs/backend/python/whatever of "Home" -> "Backend" -> "Python" -> "Whatever" I think the only part that is missing is if you want "Home" -> "Docs" -> "Frontend" and/or to "Docs/" -> "Frontend" without the "Home" Am I misunderstanding anything? |
Yes, you're right, that was my mistake, since I didn't know (at the time of writing my previous comment) that a root folder (specified in
const sidebars = {
frontend: [{type: 'autogenerated', dirName: 'frontend', breadcrumb: 'Frontend'}],
dotnet: [{type: 'autogenerated', dirName: 'dotnet', breadcrumb: 'Backend'}],
}; I still may miss something, so feel free to lead me to a right direction |
Autogenerated will be eventually unwrapped to regular sidebar items, so the idea is that we need to set metadata for each sidebar, like |
Sounds reasonable, this will definitely fit a use-case I described before |
It would be great to have an option to provide some arbitrary breadcrumbs to Docusaurus. Previously I used a custom breadcrumbs component for some pages of a Docusaurus website with a complex structure. But now there's a cute out-of-the-box component and I would like to enable it for the rest of the website. The point is that I cannot use a single template currently and have to copy it to ensure the components look indistinguishable. Perhaps it would be acceptable to introduce something like |
just a breadcrumb_label option in doc front matter would be great |
Does anyone want to send a PR? |
I was trying to have the home breadcrumb link go to a custom URL (not SolutionEjectnpm run swizzle @docusaurus/theme-classic DocBreadcrumbs -- --eject Customize the URL
- const homeHref = useBaseUrl('/');
+ const homeHref = useBaseUrl('/overview'); You should also update the aria labels in @slorber What if we extracted |
I'm not against extracting a few breadcrumbs components if that can simplify things on the short term until we figure out a good api/options. We can keep the components as unsafe to swizzle until we find the best structure |
For what it's worth, I encountered the same requirement. |
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
If you have the docs module configured where the structure matches the category index convention as mentioned for autogenerated sidebars, for example you have the following pages and URLs:
/docs/docs.md -> /docs/
/docs/item1.md -> /docs/item1
/docs/cat1/cat1.md -> /docs/cat1
/docs/cat1/sub1.md -> /docs/cat1/sub1
/docs/cat1/sub2.md -> /docs/cat1/sub2
it seems like in this usage, the breadcrumbs should match the URL structure and show all the links contained in the full URL. However, if you are on the sub2.md page, the bread crumbs goes from "/" to "/docs/cat1" and skip over the "/docs" url link:
"/" -> "/docs/cat1" -> "/docs/cat1/sub2"
I think the breadcrumb should either be
"/docs" -> "/docs/cat1" -> "/docs/cat1/sub2"
or
"/" -> "/docs" -> "/docs/cat1" -> "/docs/cat1/sub2"
Basically, the first idea would be to have the breadcrumbs "home" to go to "/docs" instead of "/" (when /docs is a valid URL). I think this makes sense since the breadcrumbs are specific to the docs module, so it isn't clear that "home" should go to the website home instead of the docs home. Maybe the way to implement this is for a parameter to set the breadcrumb home URL.
Another option would to (maybe optionally) add the "/docs" to the breadcrumb structure.
Reproducible demo
https://docusaurus.io/docs/sidebar/autogenerated
Steps to reproduce
Create structure like shown in https://docusaurus.io/docs/sidebar/autogenerated and enable breadcrumbs.
Expected behavior
breakcrumbs would look like
"/docs" -> "/docs/cat1" -> "/docs/cat1/sub2"
or
"/" -> "/docs" -> "/docs/cat1" -> "/docs/cat1/sub2"
Actual behavior
breadcrumbs are
"/" -> "/docs/cat1" -> "/docs/cat1/sub2"
Your environment
Tested on beta17
Self-service
The text was updated successfully, but these errors were encountered: