Jekyll说Liquid Exception:documentation.html中的US-ASCII中的无效字节序列

时间:2016-03-28 12:32:34

标签: utf-8 jekyll

我正在尝试在GitLab CI上运行jekyll build

这是我的.gitlab-ci.yml

pages:
  script:
  - export LC_ALL=en_US.UTF-8
  - export LANG=en_US.UTF-8
  - gem install jekyll
  - jekyll build --destination public
  artifacts:
    paths:
    - public

当任务运行时,我收到此错误:

      Generating... 
  Liquid Exception: invalid byte sequence in US-ASCII in documentation.html
jekyll 3.1.2 | Error:  invalid byte sequence in US-ASCII

ERROR: Build failed with: exit code 1

更多信息

documentation.html是:

---
layout: page
title: Documentation
description: Learn how to create awesome poppers
---
<!-- This page is generated by the grunt doc task of the master branch! Don't edit it! -->
{% markdown documentation.md %}

documentation.md是由grunt-jsdoc2md生成的降价文档。

这是我正在使用的markdown插件:

=begin
  Jekyll tag to include Markdown text from _includes directory preprocessing with Liquid.
  Usage:
    {% markdown <filename> %}
  Dependency:
    - kramdown
=end
module Jekyll
  class MarkdownTag < Liquid::Tag
    def initialize(tag_name, text, tokens)
      super
      @text = text.strip
    end
    require "kramdown"
    def render(context)
      tmpl = File.read File.join Dir.pwd, "_includes", @text
      site = context.registers[:site]
      tmpl = (Liquid::Template.parse tmpl).render site.site_payload
      html = Kramdown::Document.new(tmpl).to_html
    end
  end
end
Liquid::Template.register_tag('markdown', Jekyll::MarkdownTag)

尝试

如您所见,我已尝试将LC_ALLLANG设为en_US.UTF-8

我还在encoding: utf-8添加了_config.yml,但它仍无效...

另一种尝试是在markdown插件中使用@text = text.encode("iso-8859-1").force_encoding("utf-8").strip

建议?

2 个答案:

答案 0 :(得分:8)

I had the same problem and found this solution, which worked for me. https://gitlab.com/gitlab-org/gitlab-ce/issues/14983

image: ruby:2.3

before_script:
  - apt-get update >/dev/null
  - apt-get install -y locales >/dev/null
  - echo "en_US UTF-8" > /etc/locale.gen
  - locale-gen en_US.UTF-8
  - export LANG=en_US.UTF-8
  - export LANGUAGE=en_US:en
  - export LC_ALL=en_US.UTF-8

答案 1 :(得分:1)

我删除了markdown插件并使用了这个:

---
layout: page
title: Documentation
description: Learn how to create awesome poppers
---
<!-- This page is generated by the grunt doc task of the master branch! Don't edit it! -->
{% capture documentation %}
{% include documentation.md %}
{% endcapture %}
{{ documentation | markdownify }}

现在一切似乎都很好。