How can I add custom scripts in index.html's head part in Docusaurus V2?

后端 未结 3 703
渐次进展
渐次进展 2021-02-14 14:51

We are making a website with Docusaurus V2.

In Docusaurus V1, there is a scripts setting in siteConfig.js to cusutimize html\'s head content. B

相关标签:
3条回答
  • 2021-02-14 15:15

    I have no idea if you solved this. Your friend is the Lifecycle API.

    Specifically you want this: https://v2.docusaurus.io/docs/lifecycle-apis#injecthtmltags

    Build a plugin and use the above. D2 is looking pretty strong, I wish they'd release a stable version 2 soon!

    0 讨论(0)
  • 2021-02-14 15:26

    Instead of React Helmet, use '@docusaurus/Head' instead.

    import Head from '@docusaurus/Head';
    
    function Home() {
      const context = useDocusaurusContext();
      const { siteConfig = {} } = context;
      return (
        <Layout>
          <Head>
            <script src="..."></script>
          </Head>
        </Layout>
      );
    }
    

    We're working on this feature so you can add this via docusaurus.config.js. You can follow this PR to track the progress: https://github.com/facebook/docusaurus/pull/1831.

    We'll release v2.0.0-alpha.27 soon so that you can try it out. Thanks for your patience!

    0 讨论(0)
  • 2021-02-14 15:26

    i am also developing a blog which is based on docusaurus.
    and it provides the functionality to add script in head tag.
    follow below steps :
    1. Open siteConfig.js
    2. // Add custom scripts here that would be placed in tags.
    scripts: ['https://buttons.github.io/buttons.js'],

    0 讨论(0)
提交回复
热议问题