-
-
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
Versioned navbar item link to generated index #7975
Comments
A |
But how should I use that? It requires Examples page is using the same sidebar as everything else. Its just a generated index page for the folder contents. https://crawlee.dev/docs/examples |
Ah, so your sidebar contains things other than this generated index, and you want a versioned link that links to the generated index. FWIW, we don't have this—we also have a TODO in our own code because you can't have a versioned link to a generated index in Markdown either. I'll triage this as a feature request. Related to: #6041 |
@slorber I never understood why the |
I was trying to find a workaround via client side JS code that patches the href attributes of those 3 links, but to have them work I need to remove the ajax click handler and make real redirect. Is there a way to do an "ajax redirect" (so just like if I would click the link, but with a different href)? Something like what the |
For the time being you can probably provide a custom |
We'll support custom Navbar Items in the future and also structured the code so that you can already do this yourself today with swizzle (see #7231) Agree we don't have a good way to link to generated index for now, either through navbar (this issue) or markdown links (#6041) The best workaround I can suggest today would be to link to a # Examples
Here are all the examples:
import DocCardList from '@theme/DocCardList';
import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
<DocCardList items={useCurrentSidebarCategory().items}/> Now you have a real doc to link to: |
Probably not very useful, but it's just a simpler form of the version dropdown behavior: it shows the current version, you can click on it, and it links to the first doc in the first sidebar of that given version. Now I'm not against enhancing it a bit, so that passing an explicit Similarly we could have a versioned markdown link like |
That's a different topic that we'd rather discuss as a separate issue. It's a third-party plugin and I can't tell how you should use it. What I would do is probably create one plugin instance per version. |
Thanks for the details! I managed to make it work, although it felt like I met few bugs on the go I had to work around. For example now I have the index page in examples folder, but it is still rendered in sidebar as well as in on the page. I though This is how the sidebar is defined: {
type: 'category',
label: 'Examples',
link: {
type: 'doc',
id: 'examples/examples',
},
items: [
{
type: 'autogenerated',
dirName: 'examples',
},
],
} ---
id: examples
title: Examples
---
import DocCardList from '@theme/DocCardList';
import { useCurrentSidebarCategory } from '@docusaurus/theme-common';
<DocCardList items={useCurrentSidebarCategory().items} /> |
@B4nan this seems related to a bug/annoying default behavior reported here: #5689 (comment) Unfortunately, we don't have any simple way to exclude the Example category subitem automatically or manually currently. The only solution I can think of is to write some customized sidebarItemGenerator and run your own filtering there. const filteredDocIds = ["examples"];
function isFiltered(item) {
return item.type === "doc" && filteredDocIds.includes(item.id);
}
function filterSidebarItems(items) {
return items
.filter(item => !isFiltered(item))
// recursive filtering (optional)
.map(item => {
if (item.type === "category") {
return { ...item, items: filterSidebarItems(item.items) };
}
return item;
});
}
module.exports = {
plugins: [
[
"@docusaurus/plugin-content-docs",
{
async sidebarItemsGenerator({ defaultSidebarItemsGenerator, ...args }) {
const sidebarItems = await defaultSidebarItemsGenerator(args);
return filterSidebarItems(sidebarItems);
}
}
]
]
}; Does it make sense? |
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
We currently have 3 navbar links we would like to support versioning in. They all use
to: '...'
nowadays, which always points to the latest stable version and ignores the currently selected one. I know we can usetype: 'doc'
withdoc
id to have a versioned link, but I dont see a way to do this for a generated index page.I can try to provide minimal repro if needed, but it would take a bit more time as I would have to setup versioned content, so giving you our production site instead for now.
Reproducible demo
https://github.com/apify/crawlee/tree/master/website
Steps to reproduce
Try to change the "examples" navbar item to use
type: 'doc'
in the config:Examples are defined in sidebars.js as generated-index type:
Expected behavior
Should work and generate version aware link to the
/examples
URL (e.g./next/examples
when next is selected).Actual behavior
It complains about such
id
not existing:I also tried to put there
doc: 'examples/index'
without luck. Only thing that works is passing down one of the available doc ids as the error lists them (in other words, linking to some particular example, not to the generated index page).Also note that the selection of active link seems to be broken if I change it to one of the actual example pages, e.g.
doc: 'examples/accept-user-input'
. With that the link is always active as long as I am on some doc item page (note the URL, the examples one is just/docs/examples
so they dont collide anyhow):Maybe a bit unrelated followup is the API link next to it - that is a link to https://github.com/milesj/docusaurus-plugin-typedoc-api plugin, it also supports versioning. How would I go about supporting version aware links for that one?
Your environment
Self-service
The text was updated successfully, but these errors were encountered: