jekyll 服务抛出“没有将哈希隐式转换为整数”错误

问题描述 投票:0回答:5

我正在学习 Michael Hartl 的 Learn Enough CSS 课程。我当前的文件夹布局如下:

- _layouts
- _site
index.html

其中

index.html
是:

---
layout: test
---

我在

test.html
中有
_layouts
为:

Hello again, world.

每当我运行

jekyll serve
时,我都会收到此错误:

Error reading file /Users/pj/Documents/LETGD/repos/pohjie.github.io/_layouts/test.html: no implicit conversion of Hash into Integer 
Error reading file /Users/pj/Documents/LETGD/repos/pohjie.github.io/index.html: no implicit conversion of Hash into Integer 

有人知道发生了什么事吗?我使用的是 M1 MacBook,不确定这是否是一个可能的原因,因为我也花了很多时间安装 Ruby。

谢谢!

jekyll
5个回答
6
投票

虽然降级确实有效,但它可能非常烦人并且(取决于您需要的地方)有问题。如果您只想要一个简单的解决方法,您可以利用

jekyll build
仍然适用于 Ruby 3 的事实,并单独提供页面:

bundler exec jekyll build && bash -c 'cd _site && python -m http.server 3000'

唯一的缺点是你失去了自动重新加载功能。如果您更改任何内容,则需要重新启动 jekyll。但是您可以在 Ruby 3 环境中运行它,而无需修改环境本身。


3
投票

降级到 Ruby 2.7 是一个选项(正如其他人所说),但我不想这样做,所以我这样做了:

  1. 将补丁应用到pathutil

    来自 Liviu Stefan 的回答

    Ruby 3.0 不推荐使用最后一个参数作为关键字参数。必须在变量之前添加双杠 ** 才能支持该行为。

    这是我在本地应用补丁的方法:

    sudo sed -i.bak 's/, kwd/, **kwd/' $(gem which pathutil)
    
  2. 之后我又遇到了一个错误:

    /var/lib/gems/3.0.0/gems/jekyll-3.9.0/lib/jekyll/commands/serve/servlet.rb:3:in `require': cannot load such file -- webrick (LoadError)
    

    我通过运行修复了这个问题(来自 bundle exec jekyllserve:无法加载此类文件):

    bundle add webrick
    

2
投票

引用此来源:-

Github-Pages 使用 Jekyll 3.9,与 Ruby 3 不兼容。 降级到 Ruby 2.7 应该可以避免这个问题。

这对我有用。


0
投票

Ruby 3.0 已弃用 使用最后一个参数作为关键字参数。必须在变量之前添加双杠 ** 才能支持该行为。

本地修改相当简单;找到相关补丁:here

需要应用于:

/home//gems/gems/pathutil-0.16.2/lib/pathutil.rb


0
投票

要继续使用 Ruby 3 或更高版本,您可以在 Gemfile 中指定此 Ruby 3 兼容更新

gem "pathutil", github: "sdogruyol/pathutil", ref: '6ab144a7706c2bc5fa0dfdfa498e94ff66e944c6'

完整的 Gemfile 将如下所示。 (我还在此处包含了 webrick,因为它是 Ruby 3 及更高版本所需的单独解决方法)。

source "https://rubygems.org" # This will help ensure the proper Jekyll version is running. gem "jekyll" gem "webrick" gem "pathutil", github: "sdogruyol/pathutil", ref: '6ab144a7706c2bc5fa0dfdfa498e94ff66e944c6' # if you want jekyll plugins # group :jekyll_plugins do # gem 'jekyll-paginate' # (etc) # end
然后照常运行 

bundle update

bundle exec jekyll serve --incremental

© www.soinside.com 2019 - 2024. All rights reserved.