Hugo 在帖子中使用内联 javascript

Hugo use inline javascript within posts

当嵌入到帖子中时,我无法让 Hugo 加载内联 javascript。我正在尝试导入的 javascript 是电子邮件注册表单。从其他示例来看,语法似乎是正确的。网站或主题中是否有任何设置会阻止 javascript 加载?

雨果版本:v0.74.1 主题:hello-friend-ng

Post 和前题

---
author:
  name: "author"
date: 2020-04-03
linktitle: Inline javascript
type:
- post
- posts
title: Inline javascript
tags: ["debug"]
---

_Should show a email sign up form_

<script async data-uid="481686e31f" src="https://unique-writer-1890.ck.page/481686e31f/index.js"></script>

config.toml

谢谢!

我认为这是 Hugo 世界中最常被问到的问题之一。¹从 Hugo v0.60.0 开始,默认的 Markdown 渲染器是 Goldmark 而 Goldmark 默认忽略原始 HTML ,例如 <script ...。要使用原始 HTML,您需要在 config.toml:

中指定类似的内容
[markup]
  [markup.goldmark]
    [markup.goldmark.renderer]
      unsafe = true

我在 fragments 14 and 15 in my Hugo Tips and Fragments 中写过这个。

旁注:您的前言包括:

type:
- post
- posts

但我不认为 type 是一个列表。相反,我认为您需要使用以下之一:

type: post
type: posts

¹ 另一个 Hugo 常见问题解答是关于 Hugo bundlesindex.md_index.md