【问题标题】:Can I have non-html/md files in a rendered collection?我可以在呈现的集合中包含非 html/md 文件吗?
【发布时间】:2014-10-10 15:30:04
【问题描述】:

我的 Jekyll 站点中有一个 writing 集合,我将 output 设置为 true,因为我希望渲染所有 .md.html 文件。但是,还有一些 .js.css 文件,我希望 Jekyll 能够正常提供这些文件。

我收到了这个错误

undefined method `data' for #<Jekyll::StaticFile:0x00000104d8bb70>

我相信这是因为 Jekyll 正在尝试解析 js/css 文件。

是否可以在我的收藏中正常提供静态文件?


更新这是完整的跟踪:

Configuration file: project/_config.yml
            Source: project
       Destination: project/_site
      Generating...
Unable to find a valid configuration: sass_path=project/_compass
~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/jekyll-redirect-from-0.6.2/lib/jekyll-redirect-from/redirector.rb:38:in `has_alt_urls?': undefined method `data' for #<Jekyll::StaticFile:0x000001035f8f58> (NoMethodError)
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/jekyll-redirect-from-0.6.2/lib/jekyll-redirect-from/redirector.rb:14:in `block in generate_alt_urls'
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/jekyll-redirect-from-0.6.2/lib/jekyll-redirect-from/redirector.rb:13:in `each'
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/jekyll-redirect-from-0.6.2/lib/jekyll-redirect-from/redirector.rb:13:in `generate_alt_urls'
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/jekyll-redirect-from-0.6.2/lib/jekyll-redirect-from/redirector.rb:9:in `generate'
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/jekyll-2.4.0/lib/jekyll/site.rb:251:in `block in generate'
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/jekyll-2.4.0/lib/jekyll/site.rb:250:in `each'
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/jekyll-2.4.0/lib/jekyll/site.rb:250:in `generate'
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/jekyll-2.4.0/lib/jekyll/site.rb:45:in `process'
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/jekyll-2.4.0/lib/jekyll/command.rb:28:in `process_site'
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/jekyll-2.4.0/lib/jekyll/commands/build.rb:55:in `build'
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/jekyll-2.4.0/lib/jekyll/commands/build.rb:33:in `process'
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/jekyll-2.4.0/lib/jekyll/commands/build.rb:17:in `block (2 levels) in init_with_program'
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/mercenary-0.3.4/lib/mercenary/command.rb:220:in `call'
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/mercenary-0.3.4/lib/mercenary/command.rb:220:in `block in execute'
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/mercenary-0.3.4/lib/mercenary/command.rb:220:in `each'
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/mercenary-0.3.4/lib/mercenary/command.rb:220:in `execute'
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/mercenary-0.3.4/lib/mercenary/program.rb:35:in `go'
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/mercenary-0.3.4/lib/mercenary.rb:22:in `program'
        from ~/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/jekyll-2.4.0/bin/jekyll:18:in `<top (required)>'
        from ~/.rvm/gems/ruby-2.1.1/bin/jekyll:23:in `load'
        from ~/.rvm/gems/ruby-2.1.1/bin/jekyll:23:in `<main>'
        from ~/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
        from ~/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'

【问题讨论】:

  • 即使在集合文件夹中,.js 和 .css 如果没有前面的内容,也不会被解析。你能做一个 jekyll build --trace 以获得更多信息吗?
  • 我更新了。为什么投反对票?
  • 不是我。看我赞成。

标签: jekyll


【解决方案1】:

您通常应该能够在集合中使用静态文件,但存在 jekyll-redirect 0.6.2 错误 (ticket is here)。

解决方法

1。使用 Github 页面配置

如果您计划从 Github 页面为您的网站提供服务,您需要添加 Gemfile

source 'https://rubygems.org'
gem 'github-pages'

然后做一个bundle update。这将解决问题,因为 Jekyll-redirect 0.3.1 不会尝试为集合进行重定向。

2。移动你的静态文件

将您的静态文件移出您的收藏文件夹以避免收藏静态文件的错误。

3。移除重定向插件

如果您不需要它或只需要一两个页面,请将其从 Gemfile 中删除,并通过复制重定向页面来制作所需的重定向页面。

【讨论】:

  • 这个问题已经困扰了大约一年了。果然,#2 - 移动你的静态文件,为我解决了。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-28
  • 2022-08-19
  • 2016-10-12
  • 1970-01-01
  • 1970-01-01
  • 2012-01-22
  • 2016-01-06
相关资源
最近更新 更多