diff options
Diffstat (limited to '')
-rw-r--r-- | _plugins/lint-hook.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/_plugins/lint-hook.rb b/_plugins/lint-hook.rb new file mode 100644 index 0000000..6d883cd --- /dev/null +++ b/_plugins/lint-hook.rb @@ -0,0 +1,39 @@ +require 'set' + +IGNORED_PAGES = Set['site.json', 'sitemap.xml'] + +module Jekyll + class Linter < Generator + safe true + @@known_ids = Set[] + + def insert_id(name, document) + lang = document.data['lang'] + ref = document.data['ref'] + id = "#{name}:#{lang}:#{ref}" + if @@known_ids.include? id then + raise "Duplicate ID found: '#{id}'" + else + @@known_ids.add id + end + end + + def assert_unique_ids(site) + site.collections.each do |name, collection| + collection.docs.each do |document| + insert_id name, document + end + end + + site.pages.each do |page| + unless IGNORED_PAGES.include? page.path + insert_id 'page', page + end + end + end + + def generate(site) + assert_unique_ids(site) + end + end +end |