1

我是 MkDocs 新手,我使用 MkDocs 建立了一个网站,我想将一些脚本添加到<head>...</head>.

我在我的降价文件顶部尝试了这段代码,但没有奏效:

<head>
<script>
...
</script>
</head>

我发现脚本会显示在<body>...</body>而不是在<head>...</head>.

如何放置<script><head>标签中?

4

3 回答 3

0

假设您使用 MkDocs Material作为主题,在您的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

于 2021-11-08T19:01:29.200 回答
0

你可以使用材料。在您的主题(mkdocs.yml)中,添加对自定义目录的引用,在该目录中,您可以添加一个名为 main.html 的文件,该文件将包含在“head”部分中 请参阅https://squidfunk.github.io /mkdocs-material/customization/#overriding-partials了解更多详情。

于 2021-09-09T12:53:37.587 回答
-2

尝试这个:

<!DOCTYPE html>
<html>
  <head>
 <script src="https://file.js"></script>
  </head>
  <body>
    {{ content }}
  </body>
</html>
于 2020-05-16T09:57:19.630 回答