diff options
Diffstat (limited to 'scripts/assert-content.sh')
-rwxr-xr-x | scripts/assert-content.sh | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/scripts/assert-content.sh b/scripts/assert-content.sh index a55e9b0..3c3f0ba 100755 --- a/scripts/assert-content.sh +++ b/scripts/assert-content.sh @@ -21,12 +21,28 @@ fail-attr() { 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="$(echo "$F" | base64 --decode | jq -r .lang)" - REF="$(echo "$F" | base64 --decode | jq -r .ref)" - URL="$(echo "$F" | base64 --decode | jq -r .url)" + 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 @@ -41,13 +57,21 @@ assert-frontmatter() { echo Linting posts... >&2 for post in $(jq -r '.posts[] | @base64' "${JSON}"); do - assert-frontmatter "${post}" + 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) +IGNORED_PAGES=(/site.json /sitemap.xml /feed.en.atom /feed.pt.atom) for page in $(jq -r '.pages[] | @base64' "${JSON}"); do - URL="$(echo "$page" | base64 --decode | jq -r .url)" + URL="$(get-url "$page")" set +e contains-element "${URL}" "${IGNORED_PAGES[@]}" if [[ $? != 0 ]]; then @@ -60,13 +84,13 @@ done echo Asserting unique refs... >&2 KNOWN_IDS=() for page in $(jq -r '.pages[] | @base64' "${JSON}"); do - URL="$(echo "$page" | base64 --decode | jq -r .url)" + URL="$(get-url "$page")" set +e contains-element "${URL}" "${IGNORED_PAGES[@]}" if [[ $? != 0 ]]; then set -e - LANG="$(echo "$page" | base64 --decode | jq -r .lang)" - REF="$(echo "$page" | base64 --decode | jq -r .ref)" + LANG="$(get-lang "$page")" + REF="$(get-ref "$page")" ID="${LANG}:${REF}" set +e |