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

Instead of specifying the path of the sidebar.md file in loadSideBar, is it possible to statically declare the contents of the sidebar md file? #2521

Open
shlee1223 opened this issue Dec 26, 2024 · 4 comments

Comments

@shlee1223
Copy link

shlee1223 commented Dec 26, 2024

Feature request

Problem or desire

Instead of specifying the path of the sidebar.md file in loadSideBar, is it possible to statically declare the contents of the sidebar md file?

For example,

  loadSidebar: true,
  loadSidebar: '_sidebar.md'

==>

  loadSidebar: true,
  loadSidebar: function() {
    return `
    - [Introduction](README.md)
    - [Guide](guide.md)
    - [API Reference](api.md)
    `;
   }

I have tested the above method and similar methods, but they all failed. Is there any workaround, even if it is a different method?

I look forward to your help. Thank you.

@shlee1223 shlee1223 changed the title is it possible to statically declare the structure of the sidebar using JavaScript? Instead of specifying the path of the sidebar.md file in loadSideBar, is it possible to statically declare the contents of the sidebar md file? Dec 26, 2024
@sy-records
Copy link
Member

Why not use a file?

@shlee1223
Copy link
Author

Why not use a file?

Thanks for the answer. Although using files is fine, I would like to control the content of the sidebar dynamically using JavaScript.

@sy-records
Copy link
Member

I'm not sure it's possible. It hasn't been done.

Duplicate of #2520

@sy-records
Copy link
Member

    window.$docsify = {
      plugins: [
        function loadSidebar(hook, vm) {
          hook.ready(function () {
            var html = vm.compiler._marked(`- [Introduction](README.md)
    - [Guide](guide.md)
    - [API Reference](api.md)`);
            document.querySelector('.sidebar-nav').innerHTML = html;
          });
        },
      ],
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants