orama icon indicating copy to clipboard operation
orama copied to clipboard

Docusaurs plugin fails to start when Blog disabled

Open Phil-Sime opened this issue 1 year ago • 1 comments

Describe the bug

When I attempt to start my Docusaurus site with a configuration that has blogs disabled the Orama Docusarus plugin throws an error.

The config file docusaurus.config.js contains this line to disable the blog functionality

  blog: false,

This is the error I receive

[ERROR] TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at /Users/user-redacted/Dev/github/GitHub/repo-redacted/node_modules/@orama/plugin-docusaurus-v3/lib/index.js:73:43
    at Array.forEach (<anonymous>)
    at Object.allContentLoaded (/Users/user-redacted/Dev/github/GitHub/repo-redacted/node_modules/@orama/plugin-docusaurus-v3/lib/index.js:52:24)
    at /Users/user-redacted/Dev/github/GitHub/repo-redacted/node_modules/@docusaurus/core/lib/server/plugins/plugins.js:91:22
    at async /Users/user-redacted/Dev/github/GitHub/repo-redacted/node_modules/@docusaurus/core/lib/server/plugins/plugins.js:108:76
    at async Promise.all (index 4)
    at async /Users/user-redacted/Dev/github/GitHub/repo-redacted/node_modules/@docusaurus/core/lib/server/plugins/plugins.js:106:9
    at async /Users/user-redacted/Dev/github/GitHub/repo-redacted/node_modules/@docusaurus/core/lib/server/plugins/plugins.js:146:40
    at async loadSite (/Users/user-redacted/Dev/github/GitHub/repo-redacted/node_modules/@docusaurus/core/lib/server/site.js:127:45)
    at async createReloadableSite (/Users/user-redacted/Dev/github/GitHub/repo-redacted/node_modules/@docusaurus/core/lib/commands/start/utils.js:46:16)
    at async Command.start (/Users/user-redacted/Dev/github/GitHub/repo-redacted/node_modules/@docusaurus/core/lib/commands/start/start.js:22:28)

If I enable blog with this line it works

  blog: { }, // Blog needs to be enabled for search to work

To Reproduce

  1. Install Docusaurus
  2. Disable the blog via the Docusaurus config blog: false
  3. Install DOcusaurus Orama plugin
  4. Start site

Expected behavior

I expect the plugin to skip the blog feature if it is disabled.

Environment Info

OS: MacOS 14.4.1
Docusaurus version: v3.2.1
Node version: v21.7.3

Affected areas

Search

Additional context

Remove these lines from node_modules/@orama/plugin-docusaurus-v3/lib/index.js "fixes" the issue in my case as I don't use blog functionality.

                    case "blogs":
                        const blogsInstances = Object.keys(value);
                        blogsInstances.forEach(async (instance) => {
                            const loadedInstance = value[instance];
                            allOramaDocsPromises.push(...loadedInstance.blogPosts.map(({ metadata }) => generateDocs({
                                siteDir: ctx.siteDir,
                                version: "current",
                                category: "blogs",
                                data: metadata
                            })));
                        });
                        break;

Phil-Sime avatar May 23 '24 16:05 Phil-Sime

Hi @Phil-Sime! Since you identified the issue already, would you be up for sending a PR? :)

micheleriva avatar May 23 '24 17:05 micheleriva

This can be closed as it was fixed in https://github.com/askorama/orama/pull/747

d4nyll avatar Aug 02 '24 15:08 d4nyll