Skip to content

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

@SamChou19815

Description

@SamChou19815

🐛 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error in the Docusaurus core causing instability or issues with its execution

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions