aboutsummaryrefslogtreecommitdiff
path: root/_plugins/lint-hook.rb
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2020-12-24 15:05:44 -0300
committerEuAndreh <eu@euandre.org>2020-12-24 15:06:31 -0300
commit967665df56664ea32ad6bd82d006b9c10168563c (patch)
tree2bae82b9fad2b54aca2bb3b1cc052edf766cfc30 /_plugins/lint-hook.rb
parentTODOs.org (diff)
downloadeuandre.org-967665df56664ea32ad6bd82d006b9c10168563c.tar.gz
euandre.org-967665df56664ea32ad6bd82d006b9c10168563c.tar.xz
Move assert-unique-refs check to lint-hook.rb
Diffstat (limited to '_plugins/lint-hook.rb')
-rw-r--r--_plugins/lint-hook.rb39
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