aboutsummaryrefslogtreecommitdiff
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
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 '')
-rw-r--r--_plugins/lint-hook.rb39
-rwxr-xr-xscripts/assert-content.sh31
2 files changed, 39 insertions, 31 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
diff --git a/scripts/assert-content.sh b/scripts/assert-content.sh
index 1e0170d..d42bdfb 100755
--- a/scripts/assert-content.sh
+++ b/scripts/assert-content.sh
@@ -266,35 +266,4 @@ for screencast in $(jq -r '.screencasts[] | @base64' "${JSON}"); do
assert-frontmatter "$screencast" 'cast' '_screencasts/'
done
-echo Asserting unique refs... >&2
-KNOWN_IDS=()
-assert-unique-ref() {
- TYPE="$2"
- for page in $1; do
- URL="$(get-url "$page")"
- if ! is-ignored "${URL}"; then
- LLANG="$(get-lang "$page")"
- REF="$(get-x ref "$page")"
- ID="${TYPE}:${LLANG}:${REF}"
-
- if contains-element "${ID}" "${KNOWN_IDS[@]}"; then
- printf '%s\n' "${KNOWN_IDS[@]}"
- red "Duplicated lang:ref match: '${ID}'." >&2
- red "Page: ${URL}." >&2
- exit 1
- fi
-
- KNOWN_IDS+=("${ID}") # printf '%s\n' "${KNOWN_IDS[@]}"
- fi
- done
-}
-
-assert-unique-ref "$(jq -r '.pages[] | @base64' "${JSON}")" 'page'
-assert-unique-ref "$(jq -r '.articles[] | @base64' "${JSON}")" 'article'
-assert-unique-ref "$(jq -r '.tils[] | @base64' "${JSON}")" 'til'
-assert-unique-ref "$(jq -r '.pastebins[] | @base64' "${JSON}")" 'pastebin'
-assert-unique-ref "$(jq -r '.slides[] | @base64' "${JSON}")" 'slides'
-assert-unique-ref "$(jq -r '.podcasts[] | @base64' "${JSON}")" 'podcasts'
-assert-unique-ref "$(jq -r '.screencasts[] | @base64' "${JSON}")" 'screencasts'
-
echo Done. >&2