cmfcmf / docusaurus-search-local

Offline / Local Search for Docusaurus v2. Try it live at:
https://cmfcmf.github.io/OpenWeatherMap-PHP-API/
MIT License
438 stars 67 forks source link

Docs-only mode not working #21

Closed Techassi closed 3 years ago

Techassi commented 3 years ago

Bug description

If you use docs-only mode the indexer doesn't index directories but only the entry page.

Reproduction

Use docs-only mode described here

Environment

Package Versions

yarn list v1.22.5
├─ @cmfcmf/docusaurus-search-local@0.4.0
├─ @docusaurus/core@2.0.0-alpha.69
├─ @docusaurus/cssnano-preset@2.0.0-alpha.69
├─ @docusaurus/mdx-loader@2.0.0-alpha.69
├─ @docusaurus/plugin-content-blog@2.0.0-alpha.69
├─ @docusaurus/plugin-content-docs@2.0.0-alpha.69
├─ @docusaurus/plugin-content-pages@2.0.0-alpha.69
├─ @docusaurus/plugin-debug@2.0.0-alpha.69
├─ @docusaurus/plugin-google-analytics@2.0.0-alpha.69
├─ @docusaurus/plugin-google-gtag@2.0.0-alpha.69
├─ @docusaurus/plugin-sitemap@2.0.0-alpha.69
├─ @docusaurus/preset-classic@2.0.0-alpha.69
├─ @docusaurus/theme-classic@2.0.0-alpha.69
├─ @docusaurus/theme-common@2.0.0-alpha.69
├─ @docusaurus/theme-search-algolia@2.0.0-alpha.69
├─ @docusaurus/types@2.0.0-alpha.69
├─ @docusaurus/utils-validation@2.0.0-alpha.69
└─ @docusaurus/utils@2.0.0-alpha.69

Node Version

v15.0.1

Docusaurus Environment

Are you using a custom theme? No

docusaurus.config.js

module.exports = {
    title: 'Title',
    tagline: '',
    url: 'example.com',
    baseUrl: '/',
    favicon: 'img/favicon.ico',
    organizationName: 'org',
    projectName: 'docs',
    themeConfig: {
        sidebarCollapsible: false,
        navbar: {
            title: 'Title',
            logo: {
                alt: 'Alt text',
                src: 'img/logo.svg',
            },
            items: [
                {
                    to: '/',
                    activeBasePath: 'docs',
                    label: 'Docs',
                    position: 'left',
                },
            ],
        },
        footer: {
            style: 'dark',
            copyright: `Built with Docusaurus.`,
        },
    },
    presets: [
        [
            '@docusaurus/preset-classic',
            {
                docs: {
                    routeBasePath: '/',
                    sidebarPath: require.resolve('./sidebars.js'),
                },
                theme: {
                    customCss: require.resolve('./src/css/custom.css'),
                },
            },
        ],
    ],
    plugins: [
        [
            require.resolve('@cmfcmf/docusaurus-search-local'),
            {
                docsRouteBasePath: '/', // must correspond to the base route path configured for the docs plugin
                indexBlog: false, // whether to index blog pages
                indexDocs: true, // whether to index docs pages
                language: ['en', 'de'], // language of your documentation, see next section
                docsOnlyMode: true,
            },
        ],
    ],
};

Additional context

I introduced a new configuration option called docsOnlyMode (see above). It basically skips the URL prefix check in the flatMap function call:

if (indexDocs && docsOnlyMode) {
    return { route, url, type: "docs" };
}

...

I don't know if thats the most elegant solution but for my case it works. I can also open a PR to further discuss this issue.

franciscojaramillo commented 3 years ago

Could you please open a PR, I'm having the same issue...

cmfcmf commented 3 years ago

Sorry for not responding sooner - if you could open a PR that fixes it, I'll gladly take a look and merge it.

Techassi commented 3 years ago

Sure... I wil open a PR in a few days. Looking forward to your feedback!

franciscojaramillo commented 3 years ago

@Techassi Let me know if I can help in any way--very interested in getting this going

Techassi commented 3 years ago

Fixed for me with version 0.5.0 (commit e76534bfa394a85211baceea949ed9cf0600e101)