nanoc 和多种布局

发布于 2024-12-01 12:05:52 字数 437 浏览 2 评论 0原文

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

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

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

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

谢谢, 无尾礼服

is it possible to use multiple layouts for a specific (or all) item(s)?
For example, I have a couple of items, and I want to apply two different layouts to it. One with a green and one with a blue background (however). And I want to compile them in two different folders in my output directory (e.g. v1 and v2).

I was playing with the rules and the compile blocks, but I couldn't figure out how this could work. Because, every item gets compiled only one time during the compile process, I can't tell nanoc to compile it the first time with layout1 and the second time with layout2. I tried sth like this, but it led to broken output files.

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

Hope I made myself clear and somebody can help.

thx,
tux

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

另类 2024-12-08 12:05:52

项目表示就是为了这个目的。您可以创建两种不同的表示形式,例如默认的表示形式和替代的表示形式,然后对它们应用编译和路由规则,如下所示:

# 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

Item representations are meant for this purpose. You can create two different representations, e.g. the default one and an alternative one, and then apply compilation and routing rules to them, like this:

# 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文