Nanoc + Bower =错误 - 找到2个内容文件

时间:2013-04-26 11:45:52

标签: ruby bower nanoc

我正在使用nanoc来生成静态站点。

最近我添加了Bower来管理前端依赖项。

当我通过Bower添加Bootstrap时,我将包放在/assets/bower/

Bootstrap包中包含多个文件,包括:

bootstrap/js/tests/vendor/qunit.css
bootstrap/js/tests/vendor/qunit.js

我的Rules文件有以下规则:

route '/assets/*' do
  extension = item[:extension]
  if extension == 'coffee'
    extension = 'js'
  end
  item.identifier.chop + '.' + extension
end

compile '*', :rep => :spec do
  if !item[:spec_files].nil? && !item.binary?
    filter :erb
    layout 'spec'
  end
end

route '*', :rep => :spec do
  if !item[:spec_files].nil? && !item.binary?
     '/specs' + @item.identifier[0..-2] + '.html'
  end
end

compile '*' do
  if !item.binary?
    filter :erb
    layout_name = item[:layout] || 'default'
    layout layout_name
  end
end

route '*' do
  if item.binary?
     item.identifier.chop + '.' + item[:extension]
  else
     item.identifier[0..-2] + '.html'
  end
end

运行nanoc时出现以下错误:

 RuntimeError: Found 2 content files for
 content/assets/bower/bootstrap/js/tests/vendor/qunit; expected 0 or 1

我尝试为/ assets / bower /文件夹添加2个新的“空”规则但仍然出错。

route '/assets/bower/*' do
end

compile '/assets/bower/*' do      
end

有什么建议吗?

稍后编辑:

看起来nanoc支持静态数据源,同时也考虑了文件扩展名。

https://github.com/nanoc/nanoc-site/blob/master/content/docs/troubleshooting.md

仍然不确定我是否可以并行使用这两个数据源。

1 个答案:

答案 0 :(得分:1)

不幸的是,在最后一次扩展之前,您不能在同一目录中拥有两个具有相同名称的文件。对于nanoc 4.0,它将被重写以改变它。

您肯定可以同时使用多个数据源,但这意味着您无法将过滤器应用于qunit文件,只会重定向输出。

您明确必须能够像Bower一样安装文件吗?如果可以的话,将它们分成scriptsstyles可能是个更好的主意 - 无论如何,您几乎肯定会根据文件类型进行过滤,这意味着您可以在规则中使用去吧

compile '/whatever-path/scripts/' do
    filter :concatenate
    filter :uglify_js
end

而不是

compile '/whatever-path/ do
  case item[:extension]
  when 'js'
    filter :uglify_js
  when 'scss'
    filter :sass
  end
end