From 967665df56664ea32ad6bd82d006b9c10168563c Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Thu, 24 Dec 2020 15:05:44 -0300 Subject: Move assert-unique-refs check to lint-hook.rb --- _plugins/lint-hook.rb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 _plugins/lint-hook.rb (limited to '_plugins') 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 -- cgit v1.2.3