aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2020-10-10 14:51:52 -0300
committerEuAndreh <eu@euandre.org>2020-10-10 14:57:40 -0300
commitd8e400c40c970996599c801974fadb6d49e60fdd (patch)
tree1920204911c4931635f569ad629b9dea73dfbec8 /scripts
parentRefactor i18n structure, remove layouts, add slides (diff)
downloadeuandre.org-d8e400c40c970996599c801974fadb6d49e60fdd.tar.gz
euandre.org-d8e400c40c970996599c801974fadb6d49e60fdd.tar.xz
Enforce all "post" and "pastebin" layouts have dates in filenames
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/assert-content.sh92
1 files changed, 33 insertions, 59 deletions
diff --git a/scripts/assert-content.sh b/scripts/assert-content.sh
index 8e30aca..a0d661f 100755
--- a/scripts/assert-content.sh
+++ b/scripts/assert-content.sh
@@ -75,12 +75,17 @@ get-layout() {
## Assertions
assert-frontmatter() {
- F="${1}"
+ F="$1"
+ DESIRED_LAYOUT="$2"
+ PREFIX="${3:-}"
LANG="$(get-lang "$F")"
REF="$(get-ref "$F")"
URL="$(get-url "$F")"
+ LAYOUT="$(get-layout "$F")"
+
[[ -z "${LANG}" ]] && fail-attr 'lang' "${URL}"
[[ -z "${REF}" ]] && fail-attr 'ref' "${URL}"
+
if ! contains-element "${URL}" "${IGNORED_PAGES[@]}"; then
TITLE="$(get-title "$F")"
[[ -z "${TITLE}" ]] && fail-attr 'title' "${URL}"
@@ -90,58 +95,47 @@ assert-frontmatter() {
red "Invalid lang '${LANG}' in ${URL}." >&2
exit 1
fi
-}
-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."
+ if [[ "${DESIRED_LAYOUT}" != "${LAYOUT}" ]]; then
+ red "Layout mismatch: expected '${DESIRED_LAYOUT}', got '${LAYOUT}'."
+ red "Page: ${URL}."
exit 1
- }
+ fi
+
+ if [[ -n "${PREFIX}" ]]; then
+ DATE="$(get-date "$F" | awk '{print $1}')"
+ URL_BASENAME="$(basename "$(get-url "$F")")"
+ FILE="${PREFIX}/${DATE}-${URL_BASENAME%.html}.md"
+
+ [[ -f "${FILE}" ]] || {
+ red "date/filename mismatch: '${FILE}' does not exist. To fix, run:"
+ echo " mv '${PREFIX}/${URL_BASENAME%.html}.md' '${FILE}'"
+ exit 1
+ }
+ fi
+}
+
+echo Linting articles... >&2
+for article in $(jq -r '.articles[] | @base64' "${JSON}"); do
+ assert-frontmatter "$article" 'post' '_articles'
done
echo Linting pages... >&2
for page in $(jq -r '.pages[] | @base64' "${JSON}"); do
URL="$(get-url "$page")"
if ! contains-element "${URL}" "${IGNORED_PAGES[@]}"; then
- assert-frontmatter "${page}"
+ assert-frontmatter "${page}" 'page'
fi
done
echo Linting pastebins... >&2
for pastebin in $(jq -r '.pastebins[] | @base64' "${JSON}"); do
- assert-frontmatter "$pastebin"
+ assert-frontmatter "$pastebin" 'pastebin' '_pastebins'
done
echo Linting tils... >&2
for til in $(jq -r '.tils[] | @base64' "${JSON}"); do
- assert-frontmatter "$til"
- DATE="$(get-date "$til" | awk '{print $1}')"
- URL="$(basename "$(get-url "$til")")"
- FILE="_tils/${DATE}-${URL%.html}.md"
-
- [[ -f "${FILE}" ]] || {
- red "date/filename mismatch: '${FILE}' does not exist."
- exit 1
- }
-done
-
-echo Lintins slides... >&2
-for slide in $(jq -r '.slides[] | @base64' "${JSON}"); do
- assert-frontmatter "$slide"
- DATE="$(get-date "$slide" | awk '{print $1}')"
- URL="$(basename "$(get-url "$slide")")"
- FILE="_slides/${DATE}-${URL%.html}.html"
-
- [[ -f "${FILE}" ]] || {
- red "date/filename mismatch: '${FILE}' does not exist."
- exit 1
- }
+ assert-frontmatter "$til" 'post' '_tils'
done
echo Asserting unique refs... >&2
@@ -166,28 +160,8 @@ assert-unique-ref() {
done
}
-assert-unique-ref "$(jq -r '.pages[] | @base64' "${JSON}")"
-assert-unique-ref "$(jq -r '.pastebins[] | @base64' "${JSON}")"
-assert-unique-ref "$(jq -r '.posts[] | @base64' "${JSON}")"
-assert-unique-ref "$(jq -r '.tils[] | @base64' "${JSON}")"
-
-echo Asserting layouts... >&2
-assert-layout() {
- DESIRED=$2
- for p in $1; do
- LAYOUT="$(get-layout "$p")"
- URL="$(get-url "$p")"
- if [[ "${DESIRED}" != "${LAYOUT}" ]]; then
- red "Layout mismatch: expected '${DESIRED}', got '${LAYOUT}'."
- red "Page: ${URL}."
- exit 1
- fi
- done
-}
-
-assert-layout "$(jq -r '.posts[] | @base64' "${JSON}")" "post"
-assert-layout "$(jq -r '.pastebins[] | @base64' "${JSON}")" "pastebin"
-assert-layout "$(jq -r '.tils[] | @base64' "${JSON}")" "til"
-assert-layout "$(jq -r '.slides[] | @base64' "${JSON}")" "slide"
+assert-unique-ref "$(jq -r '.pages[] | @base64' "${JSON}")"
+assert-unique-ref "$(jq -r '.articles[] | @base64' "${JSON}")"
+assert-unique-ref "$(jq -r '.tils[] | @base64' "${JSON}")"
echo Done. >&2