blob: 14fa688f296ab8ac6e425a7963b8c8655543878a (
about) (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
#!/usr/bin/env bash
set -Eeuo pipefail
JSON="${1:-}"
[[ -z "${JSON}" ]] && {
echo 'Missing input JSON file.'
exit 2
}
contains-element() {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
fail-attr() {
ATTRIBUTE="${1}"
URL="${2}"
red "Undefined '${ATTRIBUTE}' for ${URL}." >&2
exit 1
}
get-lang() {
echo "${1}" | base64 --decode | jq -r .lang
}
get-ref() {
echo "${1}" | base64 --decode | jq -r .ref
}
get-url() {
echo "${1}" | base64 --decode | jq -r .url
}
get-date() {
echo "${1}" | base64 --decode | jq -r .date
}
LANGS=(en pt)
assert-frontmatter() {
F="${1}"
LANG="$(get-lang "$F")"
REF="$(get-ref "$F")"
URL="$(get-url "$F")"
[[ -z "${LANG}" ]] && fail-attr 'lang' "${URL}"
[[ -z "${REF}" ]] && fail-attr 'ref' "${URL}"
set +e
contains-element "${LANG}" "${LANGS[@]}"
[[ $? != 0 ]] && {
red "Invalid lang '${LANG}' in ${URL}." >&2
exit 1
}
set -e
:
}
echo Linting posts... >&2
for post in $(jq -r '.posts[] | @base64' "${JSON}"); do
assert-frontmatter "$post"
DATE="$(get-date "$post" | awk '{print $1}')"
URL="$(basename $(get-url "$post"))"
FILE="_posts/${DATE}-${URL%.html}.md"
[[ -f "${FILE}" ]] || {
red "date/filename mismatch: '${FILE}' does not exist."
exit 1
}
done
echo Linting pages... >&2
IGNORED_PAGES=(/site.json /sitemap.xml /feed.all.atom /feed.en.atom /feed.pt.atom)
for page in $(jq -r '.pages[] | @base64' "${JSON}"); do
URL="$(get-url "$page")"
set +e
contains-element "${URL}" "${IGNORED_PAGES[@]}"
if [[ $? != 0 ]]; then
set -e
assert-frontmatter "${page}"
fi
set -e
done
echo Linting pastebins... >&2
for pastebin in $(jq -r '.pastebins[] | @base64' "${JSON}"); do
assert-frontmatter "$pastebin"
done
echo Asserting unique refs... >&2
KNOWN_IDS=()
for page in $(jq -r '.pages[] | @base64' "${JSON}"); do
URL="$(get-url "$page")"
set +e
contains-element "${URL}" "${IGNORED_PAGES[@]}"
if [[ $? != 0 ]]; then
set -e
LANG="$(get-lang "$page")"
REF="$(get-ref "$page")"
ID="${LANG}:${REF}"
set +e
contains-element "${ID}" "${KNOWN_IDS[@]}"
[[ $? == 0 ]] && {
red "Duplicated lang:ref match: '${ID}'." >&2
exit 1
}
set -e
KNOWN_IDS+=("${ID}") # printf '%s\n' "${KNOWN_IDS[@]}"
fi
set -e
done
echo Done. >&2
|