docsifyjs / docsify

🃏 A magical documentation site generator.
https://docsify.js.org
MIT License
27.47k stars 5.67k forks source link

Can docsify set up lazy loading for article markdown files #2236

Closed javastacks closed 1 year ago

javastacks commented 1 year ago

Feature request

Problem or desire

I have thousands of markdown files, it will send thousands of request for all markdown files in _sidebar.md file when loading the _sidebar.md file, which leads to a slow response.

Proposal

Can docsify set up lazy loading for markdown links in the _sidebar.md file, so that markdown files are only requested when the link is clicked.

Or are there any alternative ways to disabled this feature?

Implementation

I have no idea, thanks.

sy-records commented 1 year ago

It also saves the index to the localStorage if you use search.

javastacks commented 1 year ago

It also saves the index to the localStorage if you use search.

Hello, Do you know any ways to solve, thanks a lot.

sy-records commented 1 year ago

If you don't need to search, you can use routes. see https://docsify.js.org/#/configuration?id=routes

        routes: {
            '/(.+)': function (route, matched, next) {
                fetch('https://example.com/' + route + '.md', {
                    headers: {
                    }
                })
                    .then(response => response.text())
                    .then(data => {
                        next(data);
                    })
                    .catch(function (err) {
                        next('!> Get content failed.');
                    });
            },
        },
javastacks commented 1 year ago

If you don't need to search, you can use routes. see https://docsify.js.org/#/configuration?id=routes

        routes: {
            '/(.+)': function (route, matched, next) {
                fetch('https://example.com/' + route + '.md', {
                    headers: {
                    }
                })
                    .then(response => response.text())
                    .then(data => {
                        next(data);
                    })
                    .catch(function (err) {
                        next('!> Get content failed.');
                    });
            },
        },

Thank you.

I just looked at that, it is loading dynamic content, but I need the sidebar, so it might still request all markdown files when loading sidebar...

So, are there any other ways to solve, thanks a lot.

sy-records commented 1 year ago

Don't add .md to _sidebar.md and it should work. I have a site that uses it that way.

  - Name
    - [Foo](foo)
    - [Bar](bar)
javastacks commented 1 year ago

Don't add .md to _sidebar.md and it should work. I have a site that uses it that way.

  - Name
    - [Foo](foo)
    - [Bar](bar)

Thanks, I've tried it and it didn't work, it still request all the md files with the.md suffix automatically, could you please recheck your codes for how you did?

Thanks again!

sy-records commented 1 year ago

I tested it using docsify's repo with no problems, please remove the search plugin.

Btw, there is also no need to configure routes and remove .md

trusktr commented 1 year ago

Downside of removing search plugin is visited pages will not be searchable.

Maybe we should add an option for search plugin to index only visited pages (not ideal, but maybe more desirable than nothing?).

Also in the future we will have a command line to generate search index ahead of time, instead of at runtime in the browser.