我是MkDocs的新手,我使用MkDocs建立了一个网站,我想在<head>...</head>
中添加一些脚本。
我在我的降价文件顶部尝试了这段代码,但它不起作用:
<head>
<script>
...
</script>
</head>
我发现脚本将以<body>...</body>
而不是<head>...</head>
显示。
如何将<script>
放在标签<head>
?
您可以使用材料。 在您的主题 (mkdocs.yml( 中,添加对自定义目录的引用,在该目录中,您可以添加一个名为 main 的文件.html该文件将包含在"head"部分中 有关更多详细信息,请参阅 https://squidfunk.github.io/mkdocs-material/customization/#overriding-partials。
假设您使用 MkDocs 材料作为主题,您可以在mkdocs.yml中将条目添加到extra_javascript
列表中。
mkdocs.yml:
site_name: "..."
theme: "..."
# ...
extra_javascript:
- https://cdn.someCdn.someLibrary.js # Online Resource
- js/ourJsFile.js # Path relative to "docs" Directory
# Works the same way for CSS!
extra_css:
- css/someCSS.css # Again, relative to the "docs" Directory
供参考: https://squidfunk.github.io/mkdocs-material/customization/#adding-assets
extrahead
占位符应存在于所有主题中,允许对<head>
进行添加。
您需要在 YAML 文件中指定一个custom_dir
,并且在此目录中有一个带有extrahead
块的main.html
。
看:
https://www.mkdocs.org/user-guide/customizing-your-theme/#using-the-theme_dir
试试这个:
<!DOCTYPE html>
<html>
<head>
<script src="https://file.js"></script>
</head>
<body>
{{ content }}
</body>
</html>