【问题标题】:Nanoc rules to process markdown filesNanoc 处理降价文件的规则
【发布时间】:2018-07-29 18:30:00
【问题描述】:

我当前的规则文件如下:

#!/usr/bin/env ruby

### COMPILATION RULES

# Don’t filter or layout assets
compile %r{^/(favicon|robots|crypto/.*|stylesheets/.*|javascript/.*|plugins/.*|fonts/.*|images/.*|photos/.*|keybase.txt)/$} do
end

# compile '/' do
#   filter :erb
#   layout 'default'
# end

compile '*' do
  if item.binary?
    # don’t filter binary items
  else
    layout item[:layout] || 'default'
  end
end



# Sitemap, RSS feed, and htaccess get filtered with erb, but get no layout.
compile %r{^/(sitemap|htaccess|feed|card|identity)/$} do
  filter :erb
end

# Songs get rendered in the music player
compile %r{^/music/.*/$} do
  filter :erb
  layout 'player'
end


compile '*' do
  case item[:extension]
    when 'md'
      filter :kramdown
    when 'html'
      filter :erb
  end
  layout 'default'
end

route '/photos/*/', :rep => :thumbnail do
  item.identifier.chop + '-thumbnail.' + item[:extension]
end

route %r{^/(favicon|robots|sitemap|crypto/.*|stylesheets/.*|javascript/.*|plugins/.*|fonts/.*|images/.*|photos/.*)/$} do
  ext = item[:extension]
  item.identifier.chop + '.' + ext
end

route '*' do
  item.identifier + 'index.html'
end

layout '*', :erb

我想用 markdown 而不是 html 来编写未来的文件。但是,似乎规则文件没有正确的规则来处理它。用 markdown 编写的所有内容看起来都像是文本转储。

我错过了什么?

【问题讨论】:

    标签: html ruby markdown nanoc


    【解决方案1】:

    看起来你有两个 compile 相同模式的规则 ('*')。只有第一个会被执行,另一个会被忽略。

    您应该重新组织您的规则,以便与特定项目匹配的第一个 compile 规则是您要为其执行的规则。

    以我自己的Rules文件为例,我有这样的安排:

    编译 '/**/*.md' 做 过滤器:kramdown 结尾 编译 '/**/*' 做 写 item.identifier.to_s 结尾

    换句话说,从一开始的更具体的规则到最后的更一般的规则。

    【讨论】:

    • 确实,Nanoc 会默默地忽略未使用的规则。虽然没有问题,但它可能会产生误导;我为此创建了一个 GitHub 问题 (github.com/nanoc/features/issues/37),以使此类情况更易于检测和解决。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-23
    • 2014-11-05
    • 2010-10-27
    • 1970-01-01
    • 1970-01-01
    • 2011-02-27
    • 1970-01-01
    相关资源
    最近更新 更多