我们正在使用 Docusaurus V2 制作一个网站。
在 Docusaurus V1 中,有一个 scripts
设置在siteConfig.js
自定义 html 的头部内容。但是,我在 Docusaurus V2 中找不到相应的设置。
根据https://docusaurus.io/blog/2018/09/11/Towards-Docusaurus-2#layout ,似乎可以自定义html的<head>
V2 的一部分。
Layout
The current state of Docusaurus is that it is in charge of the entire layout and styling, unintentionally making it very hard for users to customize their site's appearance to their wishes.
For Docusaurus 2, layout and styling should be controlled by the user. Docusaurus will handle the content generation, routing, translation, and versioning. Inspired by create-react-app and VuePress, Docusaurus will still provide a default theme, which the user can eject from, for further layout and styling customization. This means that it is very possible for the user to even change the HTML meta by using React Helmet. Community-based themes are also very possible. This approach of allowing users to be in charge of layout and styling is taken by most static site generators.
我尝试使用react-helmet
在src/pages/index.js
,使用以下代码:
function Home() {
const context = useDocusaurusContext();
const { siteConfig = {} } = context;
return (
<Layout
title={`Hello from ${siteConfig.title}`}
description="Description will go into a meta tag in <head />">
<Helmet>
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
</Helmet>
</Layout>
);
}
}
但是脚本https://appsforoffice.microsoft.com/lib/1/hosted/office.js
没有出现在里面<head></head>
有人遇到过类似的问题吗?可以提供帮助吗?
最佳答案
更简单的方法:
创建文件/static/js/loadtags.js。将您的标签放在那里,例如:
UST_CT = [];UST = { s: Date.now(), addTag: function(tag) { UST_CT.push(tag) } };UST.addEvent = UST.addTag;
现在更新 docusaurus.config.js 中的脚本部分
scripts: [
{
src:
'/js/loadtags.js',
async: false,
},
{
src:
'https://improve.attrace.com/server/ust.min.js?v=4.3.2',
async: true,
},
],
关于javascript - 如何在 Docusaurus V2 的 index.html 头部添加自定义脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57859350/