LoginSignup
1
1

More than 5 years have passed since last update.

`_` がついたフォルダを build に含ませたい時にやること

Posted at

こんにちは、 UNIBA の MJ です。今日は 静的サイトジェネレーターの Middleman について少し tips

Middleman の ビルドファイル

Middleman は予め一定のルールでビルド時に余分なファイルをビルドしないようになっています。

例えば layouts フォルダだったり, _ がついたフォルダだったり . が先頭についた隠しファイルだったりします。
これらは非常に便利な機能でもある一方、特殊な条件においては邪魔になったりします。

この設定は、記事を書いたあたりでは ここに 記述されています。

middleman/middleman-core/lib/middleman-core/application.rb
  # Files starting with an underscore, but not a double-underscore
  partials: proc do |file|
    ignored = false

    file[:relative_path].ascend do |f|
      if f.basename.to_s =~ %r{^_[^_]}
        ignored = true
        break
      end
    end

    ignored
  end,

  layout: proc do |file, app|
    file[:relative_path].to_s.start_with?('layout.', app.config[:layouts_dir] + '/')
  end

. ファイルに関する記述は別にあるんでしょうかね?
さておいて、これを config.rb で以下で上書きすればおkです。

config.rb

config.ignored_sitemap_matchers[:partials] = proc { |file|
  ignored = false

  file[:relative_path].ascend do |f|
    if f.to_s.start_with?("/_folder/")
      ignored = false
      break
    elsif f.basename.to_s =~ %r{^_[^_]}
      ignored = true
      break
    end
  end

  ignored
}

これで build フォルダに _folder が追加されているはずでしょう。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1