【问题标题】:Hugo use inline javascript within postsHugo 在帖子中使用内联 javascript
【发布时间】:2020-11-17 19:35:24
【问题描述】:

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

雨果版本: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>

config.toml

谢谢!

【问题讨论】:

    标签: javascript hugo


    【解决方案1】:

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

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

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

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

    type:
    - post
    - posts
    

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

    type: post
    type: posts
    

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

    【讨论】:

    • 这解释了我的一些困惑。我登陆的大多数位置说,“它只是工作。”感谢您花时间充分解释它。以及旁注,谢谢!
    猜你喜欢
    • 1970-01-01
    • 2020-07-23
    • 2020-05-12
    • 2016-12-05
    • 2022-10-08
    • 2020-10-22
    • 2023-02-04
    • 1970-01-01
    • 2021-05-06
    相关资源
    最近更新 更多