首页 > 解决方案 > Hugo 在帖子中使用内联 javascript

问题描述

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

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

邮政和前台事项

---
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>

配置文件

谢谢!

标签: javascripthugo

解决方案


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

[markup]
  [markup.goldmark]
    [markup.goldmark.renderer]
      unsafe = true

我在我的Hugo Tips and Fragments中的片段 14 和 15中写到了这一点。

旁注:您的正面内容包括:

type:
- post
- posts

但我不认为这type是一个清单。相反,我认为您需要使用以下方法之一:

type: post
type: posts

¹ 另一个 Hugo 常见问题是关于Hugo 捆绑包index.mdvs _index.md...</p>


推荐阅读