这是一个 Jekyll 插件,您可以将其放入_plugins/implicit-layout.rb
,例如:
# By specifying an implicit layout here, you do not need to
# write, for example "layout: default" at the top of each of
# your posts and pages (i.e. in the "YAML Front Matter")
#
# Please note that you should only use this plugin if you
# plan to use the same layout for all your posts and pages.
# To use the plugin, just drop this file in _plugins, calling it
# _plugins/implicit-layout.rb, for example
IMPLICIT_LAYOUT = 'default'
module Jekyll
module Convertible
def read_yaml(base, name)
self.content = File.read(File.join(base, name))
if self.content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
self.content = $POSTMATCH
begin
self.data = YAML.load($1)
self.data["layout"] = IMPLICIT_LAYOUT
rescue => e
puts "YAML Exception reading #{name}: #{e.message}"
end
end
self.data ||= {}
end
end
end
通过在 freenode 上的 #jekyll 上闲逛,我了解到这是一个猴子补丁。
正如 Alan W. Smith 评论的那样,能够将 " layout: default
" 放入_config.yml
将是对这个插件的一个很好的改进。
理想情况下(从我的角度来看),此功能可以合并到 Jekyll 本身中,因此不需要插件。