annabunches.net/_plugins/auto_categories.rb

10 lines
288 B
Ruby
Raw Normal View History

# Very simple plugin that adds a subdirectory under _posts as a category
def get_category_from_subdir(path)
path.sub(/^.*_posts\/(.*?)\/.*$/, "\\1")
end
Jekyll::Hooks.register :posts, :pre_render do |post, payload|
post.data['categories'] << get_category_from_subdir(post.path)
end