【问题标题】:Getting an error from jekyll-sitemap plugin: undefined method `fetch' for true:TrueClass in sitemap.xml从 jekyll-sitemap 插件中获取错误:未定义的方法 `fetch' for true:TrueClass in sitemap.xml
【发布时间】:2020-01-03 18:12:10
【问题描述】:

这里的第一个问题是 Ruby 和 Jekyll 的新手,如果我错过了一些重要的细节,请原谅我。

我正在尝试使用 bundle exec jekyll serve 生成我的静态网站,但我不断收到以下错误消息:

  Liquid Exception: undefined method `fetch' for true:TrueClass in sitemap.xml

编辑:问题是我在 _config.yml 中的集合配置中删除/修改了某些内容。

应该是的

collections:
  my_collection:
    output: true

...但只是

collections:
      output: true

不确定它是否总是这样,或者我是否以某种方式对其进行了修改。检查你的 _config.yml!

【问题讨论】:

标签: ruby jekyll bundler jekyll-extensions


【解决方案1】:

我已经测试了 gem,没有出现任何错误。

_config.yml

plugins:
  - jekyll-sitemap

collections_dir: my_collections

collections:
  books:
    output: true

宝石文件

source 'https://rubygems.org' do 
  gem "jekyll"
  gem 'jekyll-sitemap'
end

my_collections\books 中的 book.md

---
title: first book
---

first book

生成的 sitemap.xml

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://localhost:4000/books/book/</loc>
</url>
<url>
<loc>http://localhost:4000/</loc>
</url>
</urlset>

正如我在上面的评论中所说,我假设您的 _config.yml 文件中的集合配置存在问题。此外,official plugin page 上还列出了一些已知问题。

【讨论】:

  • 就是这个!!!我不知何故删除了我的收藏配置中的一条重要线路。刚刚更换它,一切都运行顺利。非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-11
相关资源
最近更新 更多