5

是否可以为特定(或所有)项目使用多个布局?例如,我有几个项目,我想对其应用两种不同的布局。一个是绿色的,一个是蓝色的背景(但是)。我想在我的输出目录(例如v1和v2)的两个不同文件夹中编译它们。

我在玩规则和编译块,但我不知道这是如何工作的。因为,每个项目在编译过程中只编译一次,我不能告诉 nanoc 第一次用 layout1 编译它,第二次用 layout2 编译它。我试过这样,但它导致输出文件损坏。

compile '*' do
  if item.binary?
    # don’t filter binary items
  else
    filter :erb
    layout 'layout1'
    layout 'layout2'
  end
end

希望我说清楚了,有人可以提供帮助。

谢谢,晚礼服

4

1 回答 1

9

项目表示就是为此目的。您可以创建两种不同的表示形式,例如默认一种和另一种表示,然后将编译和路由规则应用于它们,如下所示:

# default rep, although you can pass
# :rep => :default explicitly too
compile '/stuff/*/' do
  filter :erb
  layout 'default'
end

route '/stuff/*/' do
  # /stuff/foo/ -> /boring/stuff/foo/
  # Just an example; you probably need something else
  '/boring' + item.identifier
end

compile '/stuff/*/', :rep => :special do
  filter :erb
  layout 'special' # this is different
end

route '/stuff/*/', :rep => :special do
  # /stuff/foo/ -> /special/stuff/foo/
  # Again, just an example
  '/special' + item.identifier
end
于 2011-08-27T07:30:37.320 回答