【问题标题】:Getting an "Liquid Exception: Liquid syntax error" while using Jekyll使用 Jekyll 时出现“液体异常:液体语法错误”
【发布时间】:2018-09-14 02:20:33
【问题描述】:

我在 Windows 10 上运行 bundle exec jekyll serve --trace。我收到以下控制台消息:

D:\MyPorfolio\perrot.github.io>bundle exec jekyll serve
Configuration file: D:/MyPorfolio/perrot.github.io/_config.yml
            Source: D:/MyPorfolio/perrot.github.io
       Destination: D:/MyPorfolio/perrot.github.io/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
  Liquid Exception: Liquid syntax error (line 8): Syntax Error in 'for loop' - Valid syntax: for [item] in [collection] in 2018-09-14-Rendering a python dict in jinja2.markdown

杰基尔 3.7.3 |错误:Liquid 语法错误(第 8 行):“for 循环”中的语法错误 - 有效语法:for [item] in [collection]

有谁知道如何解决这个问题?提前致谢。

文件2018-09-14-Rendering a python dict in jinja2.markdown内容为:

---
layout: post
title:  "Rendering a python dict in jinja2"
date:   2018-09-14 00:01:57 +0800
categories: python jinja2
---

    ```python
    url_list = [{'target': 'http://10.58.48.103:5000/', 'clicks': '1'}, 
                {'target': 'http://slash.org', 'clicks': '4'},
                {'target': 'http://10.58.48.58:5000/', 'clicks': '1'},
                {'target': 'http://de.com/a', 'clicks': '0'}]
    #Python 2.7

    {% for key, value in url_list.iteritems() %}
        <li>{{ value["target"] }}</li> 
    {% endfor %}
    #Python 3

    {% for key, value in url_list.items() %}
        <li>{{ value["target"] }}</li> 
    {% endfor %}
    ```

【问题讨论】:

  • 您与上一个工作版本相比有何变化?任何代码发布?文件2018-09-14-... 或其使用的布局似乎有问题。
  • @marcanuy 感谢您的快速回复。我修改了我的帖子,并在 jinja2.markdown 中附加了 2018-09-14-Rendering a python dict 的内容。

标签: ruby jekyll


【解决方案1】:

1 - {% raw %} 标签是this postthis post 中python 代码解决方案的一部分。

2 - 解决方案的另一部分can be a bug in the way Jekyll manages excerpts

删除代码中的空行,它将起作用。

【讨论】:

  • 感谢您的回复。我使用命令“bundle update”将 Jekyll 升级到最新版本 3.7.4,并在 highlight 和 raw 之间留一个空行。但它仍然有一个错误“Liquid Exception: Liquid syntax error (line 3): 'highlight' tag was never closed”。该错误已在 v3.8.x 中修复。我不知道如何将我的 Jekyll 升级到 3.8.x 版本。
  • 抱歉,highlight 和 raw 之间的空格是 3.8.x 中的修复。由于您必须坚持使用 gh 页面,因此您唯一的解决方案是删除代码中的空行。编辑了我的答案。
【解决方案2】:

Liquid 尝试处理您的源代码,尤其是 jinja2 控制标签,为此您需要告诉 Liquid 避免使用 raw 标签处理它:

{% highlight python %}
{% raw %}
   url_list = [{'target': 'http://10.58.48.103:5000/', 'clicks': '1'}, 
                {'target': 'http://slash.org', 'clicks': '4'},
                {'target': 'http://10.58.48.58:5000/', 'clicks': '1'},
                {'target': 'http://de.com/a', 'clicks': '0'}]
    #Python 2.7

    {% for key, value in url_list.iteritems() %}
        <li>{{ value["target"] }}</li> 
    {% endfor %}
    #Python 3

    {% for key, value in url_list.items() %}
        <li>{{ value["target"] }}</li> 
    {% endfor %}

{% endraw %}
{% endhighlight %}

【讨论】:

  • 感谢您的回答。但是我收到了另一个错误消息: Liquid Exception: Liquid syntax error (line 2): 'raw' tag was never closed in D:/MyPorfolio/perrot.github.io/_posts/2018-09-14-Rendering a python dict in jinja2.markdown/#excerpt Liquid 异常:Liquid 语法错误(D:/MyPorfolio/perrot.github.io/_includes/head.html 第 2 行):'raw' 标签从未关闭包含在 /_layouts/default.html jekyll 3.7 中.3 |错误:Liquid 语法错误(D:/MyPorfolio/perrot.github.io/_includes/head.html 第 2 行):“原始”标签从未关闭包含
  • 你加入了endraw吗?
  • 是的,我只是将 _.markdown 的内容替换为您的帖子。它包含一个 endraw 标签。
猜你喜欢
  • 2017-12-01
  • 2020-12-26
  • 1970-01-01
  • 1970-01-01
  • 2019-05-28
  • 2016-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多