From fb658f10b5c0db6ec7d1d3064517ad3cd240ca0b Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 27 Dec 2020 22:19:07 -0300 Subject: linter.rb: Add all_documents iterator --- _plugins/linter.rb | 52 +++++++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 29 deletions(-) (limited to '_plugins/linter.rb') diff --git a/_plugins/linter.rb b/_plugins/linter.rb index 188aede..5d78c17 100644 --- a/_plugins/linter.rb +++ b/_plugins/linter.rb @@ -21,20 +21,8 @@ module Jekyll def assert_unique_ids(site) @known_ids = Set[] - site.collections.each do |name, collection| - collection.docs.each do |document| - unless document.data['generated'] then - insert_id name, document - end - end - end - - site.pages.each do |page| - unless IGNORED_PAGES.include? page.path - unless page.data['generated'] then - insert_id 'page', page - end - end + all_documents(site) do |collection_name, document| + insert_id collection_name, document end end @@ -71,7 +59,7 @@ module Jekyll 'screencasts' => 'cast' } - def assert_frontmatter_fields(site, name, document) + def assert_frontmatter_fields(name, document) title = assert_field document, 'title' lang = assert_field document, 'lang' ref = assert_field document, 'ref' @@ -127,20 +115,8 @@ module Jekyll end def assert_frontmatter(site) - site.collections.each do |name, collection| - collection.docs.each do |document| - unless document.data['generated'] - assert_frontmatter_fields site, name, document - end - end - end - - site.pages.each do |page| - unless IGNORED_PAGES.include? page.path - unless page.data['generated'] - assert_frontmatter_fields site, 'page', page - end - end + all_documents(site) do |collection_name, document| + assert_frontmatter_fields collection_name, document end end @@ -163,5 +139,23 @@ module Jekyll assert_frontmatter(site) assert_git_annex(site) end + + def all_documents(site) + site.collections.each do |name, collection| + collection.docs.each do |document| + unless document.data['generated'] + yield name, document + end + end + end + + site.pages.each do |page| + unless IGNORED_PAGES.include? page.path + unless page.data['generated'] + yield 'page', page + end + end + end + end end end -- cgit v1.2.3