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) Blog only mode becomes much harder to use after alpha-62 #3360

Closed
SamChou19815 opened this issue Aug 28, 2020 · 1 comment
Closed

(v2) Blog only mode becomes much harder to use after alpha-62 #3360

SamChou19815 opened this issue Aug 28, 2020 · 1 comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution

Comments

@SamChou19815
Copy link
Contributor

🐛 Bug Report

In the documentation, it mentions that preset classic can support blog-only mode seamlessly: https://v2.docusaurus.io/docs/blog#blog-only-mode

However, several changes in alpha-62 makes it much harder in two possible scenarios of blog-only mode usage:

  1. alpha-62 will start complain and abort when docs folder or sidebars.json is missing. This means that if we are using preset-classic and have no docs, build cannot succeed. The workaround might be add some dummy docs.

  2. alpha-62 introduces some hooks from docs plugin. If we don't use preset-classic and only use blog plugin and theme-classic, build will fail because @theme/hooks only exist in docs plugin but some components in theme-classic import it:

    import {
    useVersions,
    useLatestVersion,
    useActiveDocContext,
    } from '@theme/hooks/useDocs';

To workaround the issue, I created a dummy useDocs.js in src/theme/hooks in my website:

https://github.com/SamChou19815/website/blob/e5899283386065581a3a37df9e816e9bf82e2ae8/packages/blog/src/theme/hooks/useDocs.js

but ideally blog-only mode can just work without this kind of hacks.

Have you read the Contributing Guidelines on issues?

Yes

To Reproduce

(Write your steps here:)

  1. npx @docusaurus/init@next init test classic
  2. Setup blog only mode according to https://v2.docusaurus.io/docs/blog#blog-only-mode
  3. yarn start. It failed. See Actual Behavior section below.

Expected behavior

Blog only mode should work out-of-the-box.

Actual Behavior

Scenario 1: (with preset-classic)

module.exports = {
  // ...
  presets: [
    [
      '@docusaurus/preset-classic',
      {
        blog: {
          path: './blog',
          routeBasePath: '/', // Set this value to '/'.
        },
        theme: {
          customCss: require.resolve('./src/css/custom.css'),
        },
      },
    ],
  ],
};
➜  test yarn start
yarn run v1.22.5
$ docusaurus start
Starting the development server...
Error: The docs folder does not exist for version [current]. A docs folder is expected to be found at /Users/sam/Downloads/test/docs
    at checkVersionMetadataPaths (/Users/sam/Downloads/test/node_modules/@docusaurus/plugin-content-docs/lib/versions.js:132:15)
    at Array.forEach (<anonymous>)
    at Object.readVersionsMetadata (/Users/sam/Downloads/test/node_modules/@docusaurus/plugin-content-docs/lib/versions.js:171:22)
    at pluginContentDocs (/Users/sam/Downloads/test/node_modules/@docusaurus/plugin-content-docs/lib/index.js:27:41)
    at /Users/sam/Downloads/test/node_modules/@docusaurus/core/lib/server/plugins/init.js:72:48
    at Array.map (<anonymous>)
    at Object.initPlugins [as default] (/Users/sam/Downloads/test/node_modules/@docusaurus/core/lib/server/plugins/init.js:27:10)
    at Object.loadPlugins (/Users/sam/Downloads/test/node_modules/@docusaurus/core/lib/server/plugins/index.js:49:35)
    at Object.load (/Users/sam/Downloads/test/node_modules/@docusaurus/core/lib/server/index.js:78:74)
    at start (/Users/sam/Downloads/test/node_modules/@docusaurus/core/lib/commands/start.js:44:34)
    at /Users/sam/Downloads/test/node_modules/@docusaurus/core/bin/docusaurus.js:73:5
    at Command.<anonymous> (/Users/sam/Downloads/test/node_modules/@docusaurus/core/bin/docusaurus.js:152:23)
    at Command.listener (/Users/sam/Downloads/test/node_modules/commander/index.js:370:29)
    at Command.emit (events.js:315:20)
    at Command.parseArgs (/Users/sam/Downloads/test/node_modules/commander/index.js:892:12)
    at Command.parse (/Users/sam/Downloads/test/node_modules/commander/index.js:642:21)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Scenario 2: (with @docusaurus/theme-classic + @docusaurus/plugin-content-blog)

module.exports = {
  // ...
  themes: [
    [
      require.resolve('@docusaurus/theme-classic'),
      { customCss: require.resolve('./src/css/custom.css') },
    ],
  ],
  plugins: [
    [
      require.resolve('@docusaurus/plugin-content-blog'),
      {
        path: './blog',
        routeBasePath: '/', // Set this value to '/'.
      },
    ],
  ],
};
./node_modules/@docusaurus/theme-classic/lib/theme/NavbarItem/DocsVersionNavbarItem.js
Module not found: Can't resolve '@theme/hooks/useDocs' in '/Users/sam/Downloads/test/node_modules/@docusaurus/theme-classic/lib/theme/NavbarItem'

Your Environment

  • Docusaurus version used: v2-alpha-62
  • Environment name and version (e.g. Chrome 78.0.3904.108, Node.js 10.17.0): Node.js 12
  • Operating system and version (desktop or mobile): desktop
@SamChou19815 SamChou19815 added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Aug 28, 2020
@slorber
Copy link
Collaborator

slorber commented Sep 1, 2020

Hey @SamChou19815

Here is an attempt to fix this issue: #3382

@slorber slorber removed the status: needs triage This issue has not been triaged by maintainers label Sep 1, 2020
slorber added a commit that referenced this issue Sep 1, 2020
)

* deprecated nextVersionLabel option

* useActivePlugin failfast option

* remove deprecated option nextVersionLabel

* routeBasePath: '' should be forbidden

* routeBasePath: '' should be forbidden

* Docs: do not show version badge if there is only 1 version: #3362

* allow sidebars file to not exist: fallback to empty sidebars
https://githu.com/facebook/docusaurus/issues/3366

* Ability to use classic theme/preset while not using docs/pages without trouble.
#3360

* fix netlify redirects

* do not throw if useDocs do not load?

* netlify deploy typo

* try to fix useDocs

* docs(v2): update Deploy to Vercel guide (#3344)

* filter annoying useDocs conditional require warning

* netlify deploy preview homepage

* typo

* try to trigger again CLA bot

Co-authored-by: Sam Ko <[email protected]>
@slorber slorber closed this as completed Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution
Projects
None yet
Development

No branches or pull requests

2 participants