Repository navigation
Closed
Labels
documentationThe issue is related to the documentation of Docusaurus
Description
📚 Documentation
Usecase
As a developer, I want to be able to create 2 pages of documentation.
Why am I writing this?
This is often necessary, and oftentimes developers don't find the right way to do it. One of the official examples from the examples page in the documentation:
- Works: https://buildtracker.dev/docs/guides/guides
- Not works: https://buildtracker.dev/docs/guides/
Expected result
The image shows the expected result - two pages with two sidebars.
- First page is
Docswith url/docsand index-page on/docs/doc1from dirdocs. - Second page is
Resourceswith url/resourcesand index-page on/resources/doc2from dirresources.
Solution
Warning: md-link from resources to docs should be relative like [doc1](../docs/doc1)
// sidebarsDocs.js
module.exports = {
docs: {
Installation: ["doc1"], // from path `docs/doc1`
},
};
// sidebarsResources.js
module.exports = {
resources: {
Installation: ["doc2"], // from path `resources/doc2`
},
};Then need to create files from docusaurus.config.js folder:
docs/
- doc1.md
resources/
- doc2.md
Then need to connect two content-docs plugins (one from preset-classic) with different ids.
// docusaurus.config.js
presets: [
[
"@docusaurus/preset-classic",
{
docs: {
// id: "w1", for first plugin-content-docs with "docs/" path, do not set this if you want versioning to work
homePageId: "doc1",
sidebarPath: require.resolve("./sidebarsDocs.js"),
},
},
],
],
plugins: [
[
"@docusaurus/plugin-content-docs",
{
id: "w2", // for first plugin-content-docs with "resources/" path
homePageId: "doc2",
path: "./resources", // Path to data on filesystem, relative to site dir.
routeBasePath: "resources", // URL Route.
include: ["**/*.md"],
sidebarPath: require.resolve("./sidebarsResources.js"),
disableVersioning: true, // if not set with vesions, throw: Identifier 'React' has already been declared
},
],
],And set routes to themeConfig.navbar.items.
// docusaurus.config.js: themeConfig.navbar.items
{
to: "docs/",
label: "Docs",
position: "left",
},
{
to: "resources/",
activeBasePath: "resources",
label: "Resources",
position: "left",
}Alternative expected result
- First page is
Docswith url/docsand index-page on/docs/doc1from dirdocs. - Second page is
Resourceswith url/docs/resourcesand index-page on/docs/resourcesfrom dirdocs/resources.
Solution
Warning: not tested with docs versions
// sidebars.js
module.exports = {
docs: {
Installation: ["doc1"],
},
resources: {
Installation: ["resources"],
},
};Then need to create files from docusaurus.config.js folder:
docs/
- resources/
- - // other files for Resources page will be in this folder
- resources.md // index-page for Resources page, the same name with a content folder at the same level
- doc1.md
Then need to connect two content-docs plugins (one from preset-classic) with different ids.
// docusaurus.config.js
presets: [
[
"@docusaurus/preset-classic",
{
docs: {
// "docs/" path
homePageId: "doc1",
sidebarPath: require.resolve("./sidebars.js"),
},
},
],
],And set routes to themeConfig.navbar.items with activeBaseRegex.
// docusaurus.config.js: themeConfig.navbar.items
{
to: "docs/",
activeBaseRegex: "^(.*docs\\/(?!(resources\\/?)).*)", // ignore route "docs/resources/..."
label: "Docs",
position: "left",
},
{
to: "docs/resources/",
activeBasePath: "docs/resources",
label: "Resources",
position: "left",
},Reacted by Jackson, Copple and Matt Cromwell
Reacted by tjperry07
Metadata
Metadata
Assignees
Labels
documentationThe issue is related to the documentation of Docusaurus

Activity
NikitaIT commentedon Aug 17, 2020
P.S. I think this configuration is not intuitive, so it can be seen as a suggestion for simplification.
slorber commentedon Aug 18, 2020
Hey @NikitaIT
The docs multi-instance system is brand new, it wasn't working before alpha 61, and we can definitively improve the doc (I left it undocumented on purpose so that we can get a bit of feedbacks of early adopters before writing some doc.
Both options look valid to me, but it will also depend on how you see versioning working on your site, and what URLs you want. If you have 2 plugin instances, each can have different versionion schemes (ios/android sdks for example). Also each plugin instance has its own URL prefix.
One plugin instance means shared URL prefix + same versioning for both docs.
Also worth mentioning that you can use special navbar items to link to docs: https://v2.docusaurus.io/docs/theme-classic/#navbar-docs-version-dropdown
Also, if you use docs, it means you want to use doc navigation, a sidebar etc... If you don't need that, you can also simply created a markdown page (added recently): https://v2.docusaurus.io/docs/creating-pages/#add-a-markdown-page
If you want to write some doc, I'll be happy to accept a PR
NikitaIT commentedon Aug 18, 2020
About 2 docs with versions
It seems setting id in the classic with versioning is unnecessary, and breaks the documentation. So I remove
id: "w1"from the example. And if 2 docs with versions for first we should setdisableVersioning: true, because by default the second plugin will reload the versions and throwIdentifier 'React' has already been declared.slorber commentedon Aug 27, 2020
Sorry but I don't understand what you mean 😅 if you can send a PR to Docusaurus website that allows me to see the problem on the deploy preview that would be helpful.
NikitaIT commentedon Aug 29, 2020
@slorber This is not very important, just when adding folders with versions, the second instance of the plugin docs parses them again(without disableVersioning). Because both plugins do it at the same time, this leads to an error. The error is expected, but I decided to write about it here, just in case.
jacksongoode commentedon Aug 31, 2020
Thanks @NikitaIT for a great tutorial on getting multiple, separate and unique, documentation pages!
tjperry07 commentedon Sep 14, 2020
I tested out method 1 on a clean install, and it returns a 404 error when navigating to Resources.
See the code https://github.com/tjperry07/doc-testing
I did find a method that worked using multiple sidebars.
sidebars.js
inside of /docs
docusaurus.config.js
mathetos commentedon Oct 1, 2020
I was able to get three different "docs" sections added while running version 2.0.0-alpha-64.
They each have sub-directories, and custom sidebars. Worked really well once I finally figured it all out. Often, when I added new docs into new sub-directories, I had to restart yarn for the new files to be recognized. Other than that, if this was explicitly documented it would have saved me at least an hour of fidgeting and guessing.
slorber commentedon Oct 1, 2020
sorry about that, I keep in mind to write this doc soon :)
mathetos commentedon Oct 1, 2020
@slorber Not a problem at all, and not a complaint. Just wanted to chime in to validate that it's working and worth some solid docs. V2 really is slick, great work!
[-]V2: Multiple page docs exemple[/-][+]V2: document docs plugin multi-instance[/+]slorber commentedon Oct 13, 2020
Until I document this, note that to version a new plugin instance, a new cli command appear, see
docusaurus docs:version:community(community = pluginId of the second instance)srlopez commentedon Dec 22, 2020
@mathetos @slorber
I think I need a link to the full
docusaurus.config.jsfile in your reply.Something is wrong with my setup because I don't compile md files for the dev folder etc.
Have you remove the
docssection inpreset?How it looks the
itemsof thenavbar?By the way:
As result no
index.htmlcreated ondevfolder.slorber commentedon Dec 30, 2020
FYI I just added documentation for the multi-instance support.
Can early adopters read it and tell me if something is not clear enough please?
https://v2.docusaurus.io/docs/next/docs-multi-instance/
mathetos commentedon Dec 30, 2020
@slorber I haven't tested your sample code, but when I was working on mine above back in September, I couldn't get the relative path to work correctly as you have it in your snippet, which is why in mine above the path is
path: "./support"instead ofpath: "support"I can test it later perhaps, or maybe there's an update in V2 that addresses that?Other than that, the doc looks great!
slorber commentedon Dec 31, 2020
@mathetos that's surprising because the default path is actually just
docsand it works fine for a long time now.Thanks for the feedback