如何向 Hugo 站点添加自定义 CSS
在 hugo.toml 中,添加
hugo.toml
[params]
custom_css = ["css/myblog.css"]现在你需要找到主题中生成布局 head 的文件。使用例如
find_stylesheet_links.sh
ag '<link rel="stylesheet"'来查找这是哪个文件
对我来说(tailbliss 主题),它是 themes/tailbliss/layouts/partial/head.html,我相信其他主题也类似。
在该文件中,添加
themes/mytheme/layouts/partial/head.html
{{ range .Site.Params.custom_css -}}
<link rel="stylesheet" href="{{ . | absURL }}">
{{- end }}现在,在 static/css/myblog.css 中创建实际的静态 CSS 文件。
当你现在运行 hugo serve 时,你会立即看到自定义 CSS 文件引入的更改。
Check out similar posts by category:
Hugo
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow