Skip to content
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

V2: document docs plugin multi-instance #3299

Closed
NikitaIT opened this issue Aug 17, 2020 · 15 comments · Fixed by #3978
Closed

V2: document docs plugin multi-instance #3299

NikitaIT opened this issue Aug 17, 2020 · 15 comments · Fixed by #3978
Assignees
Labels
documentation The issue is related to the documentation of Docusaurus

Comments

@NikitaIT
Copy link

NikitaIT commented Aug 17, 2020

📚 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:

Expected result

The image shows the expected result - two pages with two sidebars.

  • First page is Docs with url /docs and index-page on /docs/doc1 from dir docs.
  • Second page is Resources with url /resources and index-page on /resources/doc2 from dir resources.

image

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 Docs with url /docs and index-page on /docs/doc1 from dir docs.
  • Second page is Resources with url /docs/resources and index-page on /docs/resources from dir docs/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",
},
@NikitaIT NikitaIT added documentation The issue is related to the documentation of Docusaurus status: needs triage This issue has not been triaged by maintainers labels Aug 17, 2020
@NikitaIT
Copy link
Author

P.S. I think this configuration is not intuitive, so it can be seen as a suggestion for simplification.

@slorber
Copy link
Collaborator

slorber commented 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
Copy link
Author

NikitaIT commented 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 set disableVersioning: true, because by default the second plugin will reload the versions and throw Identifier 'React' has already been declared.

@slorber
Copy link
Collaborator

slorber commented 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
Copy link
Author

@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
Copy link

Thanks @NikitaIT for a great tutorial on getting multiple, separate and unique, documentation pages!

@tjperry07
Copy link

tjperry07 commented 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

module.exports = {
  docs: {
    Docusaurus: ['doc1'],
  },
  dataProd: {
    Welcome: ['dataProd/welcome_data']
  }
};

inside of /docs

.
├── dataProd
│   └── welcome_data.md
└── doc1.md

docusaurus.config.js

        {
          to: 'docs/',
          label: 'Docs',
          position: 'left',
        },
        {
          to: "docs/dataProd/welcome_data",
          label: "Data Prod",
          position: "left",
        },

@mathetos
Copy link

mathetos commented 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.

plugins: [
    [
      "@docusaurus/plugin-content-docs",
      {
        id: 'dev',
        path: "./dev", // Path to data on filesystem, relative to site dir.
        routeBasePath: "dev", // URL Route.
        include: ["**/*.md"],
        sidebarPath: require.resolve('./sidebarsDev.js'),
      },
    ],
    [
      "@docusaurus/plugin-content-docs",
      {
        id: 'support',
        path: "./support", // Path to data on filesystem, relative to site dir.
        routeBasePath: "support", // URL Route.
        include: ["**/*.md"],
        sidebarPath: require.resolve('./sidebarsSupport.js'),
      },
    ],
    [
      "@docusaurus/plugin-content-docs",
      {
        id: 'marketing',
        path: "./marketing", // Path to data on filesystem, relative to site dir.
        routeBasePath: "marketing", // URL Route.
        include: ["**/*.md"],
        sidebarPath: require.resolve('./sidebarsMarketing.js'),
      },
    ],
  ],

@slorber slorber self-assigned this Oct 1, 2020
@slorber
Copy link
Collaborator

slorber commented Oct 1, 2020

sorry about that, I keep in mind to write this doc soon :)

@mathetos
Copy link

mathetos commented 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!

@slorber slorber changed the title V2: Multiple page docs exemple V2: document docs plugin multi-instance Oct 13, 2020
@slorber
Copy link
Collaborator

slorber commented 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)

image

@srlopez
Copy link

srlopez commented Dec 22, 2020

@mathetos @slorber
I think I need a link to the full docusaurus.config.js file 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 docs section in preset?
How it looks the items of the navbar?

By the way:

npx docusaurus --version
2.0.0-alpha.70

As result no index.html created on dev folder.

@slorber
Copy link
Collaborator

slorber commented 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
Copy link

@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 of path: "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
Copy link
Collaborator

slorber commented Dec 31, 2020

@mathetos that's surprising because the default path is actually just docs and it works fine for a long time now.

Thanks for the feedback

@Josh-Cena Josh-Cena removed the status: needs triage This issue has not been triaged by maintainers label Mar 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation The issue is related to the documentation of Docusaurus
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants