You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Hugo渲染含YAML代码块异常,仅显示'e>'求排查

Hugo渲染YAML代码块仅显示'e>'的排查与解决

问题定位

你提供的YAML代码经yamllint校验无语法错误,且代码块长度并非Hugo渲染的限制因素——核心问题是Hugo默认的Markdown渲染器(Goldmark)会误解析代码块中的Go模板语法。

代码里的${{ secrets.WIKI_REPO_TOKEN_RW }}包含Go模板标识{{ }},Hugo会将其当成自身模板指令尝试解析,进而打断代码块的正常渲染,最终输出截断内容。

解决方案

以下三种方法均可解决该问题:

  1. 给代码块添加-nocode标识
    在代码块的语言后缀后加-nocode,告知Goldmark跳过对该代码块的模板解析:
name: Update all wiki articles

on:
  push:
    branches:
      - main
    paths:
      - docs/vimwiki/**

jobs:
  publish:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./docs/vimwiki
    env:
      content: ./wiki/content
    steps:
      - uses: actions/checkout@v4
      - name: Cloning repo
        env:
          # Github personal access token 
          TOKEN: ${{ secrets.WIKI_REPO_TOKEN_RW }}
        run: |
            git config --global user.email "<>"
            git config --global user.name "Github Actions Runner"
            git clone --single-branch --branch main \
              "https://x-access-token:$TOKEN@github.com/hmaier-dev/wiki.git" "wiki"
      - name: Removing old files
        run: |
            find  $content -name '*.md' -type f -exec rm {} \;
            ls -la
      - name: Copy over new files
        run: |
            # Whitelist of all publishable wiki articles
            cp index.md $content
            # more publishable markdown files...
      - name: Setup Python
        uses: actions/setup-python@v3
        with:
          python-version: '3.12'
          
      # Optional:  
      # Give special treatment to index.wiki because it needs to get censored
      - name: Censor index.wiki
        run: |
          cd $content
          python ../build/extract.py index.md
          
      # Pushing to the public wiki
      - name: Commit and push new files
        run: |
            cd wiki
            git checkout main
            git add .
            git diff-index --quiet HEAD || git commit -m "Automatic wiki-publish"
            git push origin main
  1. 用raw短代码包裹代码块
    使用Hugo的raw短代码包裹整个代码块,阻止模板解析:
{{< raw >}}
```yaml
# 你的YAML代码内容

{{< /raw >}}

3. **手动转义模板标识**
给代码中的`{{ }}`添加反斜杠转义,让Hugo将其视为普通文本:
```yaml
TOKEN: \${{ secrets.WIKI_REPO_TOKEN_RW }}

验证说明

Hugo对代码块内容长度无硬性限制,无需考虑长度导致的渲染异常。

内容的提问来源于stack exchange,提问作者hmaier

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 11:21:06