aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2020-10-23 06:18:03 -0300
committerEuAndreh <eu@euandre.org>2020-10-23 06:19:10 -0300
commit5b141847bd01de0c0fa7c160c6443bc6c0d4f9f7 (patch)
tree30833fade5fb513a0c9ceec4eeacbdcc70468788 /scripts
parentInterview article: Fix link to match title (diff)
downloadeuandre.org-5b141847bd01de0c0fa7c160c6443bc6c0d4f9f7.tar.gz
euandre.org-5b141847bd01de0c0fa7c160c6443bc6c0d4f9f7.tar.xz
assert-content.sh: Enforce "ref" is the slug of the "title" for pages in en
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/assert-content.sh37
1 files changed, 29 insertions, 8 deletions
diff --git a/scripts/assert-content.sh b/scripts/assert-content.sh
index 626353c..2fcf1a9 100755
--- a/scripts/assert-content.sh
+++ b/scripts/assert-content.sh
@@ -14,9 +14,20 @@ JSON='_site/site.json'
LANGS=(en pt fr)
IGNORED_PAGES=(site.json sitemap.xml *.atom)
+export LC_ALL=en_US.UTF-8
## Helper function definitions
+slugify() {
+ echo "${1}" | \
+ tr '[:upper:]' '[:lower:]' | \
+ perl -ne 'tr/\000-\177//cd;
+ s/[^\w\s-]//g;
+ s/^\s+|\s+$//g;
+ s/[-\s]+/-/g;
+ print;'
+}
+
contains-element() {
local e match="$1"
shift
@@ -45,7 +56,7 @@ get-url() {
}
get-date() {
- echo "${1}" | base64 --decode | jq -r .date
+ echo "${1}" | base64 --decode | jq -r .date | awk '{print $1}'
}
get-title() {
@@ -88,21 +99,31 @@ assert-frontmatter() {
exit 1
fi
- if [[ -n "${PREFIX}" ]]; then
- DATE="$(get-date "$F" | awk '{print $1}')"
+ if [[ "$DESIRED_LAYOUT" != 'page' ]]; then
+ DATE="$(get-date "$F")"
URL_BASENAME="$(basename "$(get-url "$F")")"
- FILE="${PREFIX}/${DATE}-${URL_BASENAME%.html}.${EXTENSION}"
+ FILE="${PREFIX}${DATE}-${URL_BASENAME%.html}.${EXTENSION}"
[[ -f "${FILE}" ]] || {
red "date/filename mismatch: '${FILE}' does not exist."
exit 1
}
+
+ if [[ "$DESIRED_LAYOUT" != 'pastebin' ]] && [[ "$LANG" = 'en' ]]; then
+ TITLE_SLUG="$(slugify "$TITLE")"
+ if [[ "$TITLE_SLUG" != "$REF" ]]; then
+ red "ref isn't the slug of the title."
+ red "ref: '$REF'"
+ red "title slug: '$TITLE_SLUG'"
+ exit 1
+ fi
+ fi
fi
}
echo Linting articles... >&2
for article in $(jq -r '.articles[] | @base64' "${JSON}"); do
- assert-frontmatter "$article" 'post' '_articles'
+ assert-frontmatter "$article" 'post' '_articles/'
done
echo Linting pages... >&2
@@ -115,17 +136,17 @@ done
echo Linting pastebins... >&2
for pastebin in $(jq -r '.pastebins[] | @base64' "${JSON}"); do
- assert-frontmatter "$pastebin" 'pastebin' '_pastebins'
+ assert-frontmatter "$pastebin" 'pastebin' '_pastebins/'
done
echo Linting tils... >&2
for til in $(jq -r '.tils[] | @base64' "${JSON}"); do
- assert-frontmatter "$til" 'post' '_tils'
+ assert-frontmatter "$til" 'post' '_tils/'
done
echo Linting slides... >&2
for slide in $(jq -r '.slides[] | @base64' "${JSON}"); do
- assert-frontmatter "$slide" 'slides' '_slides' 'slides'
+ assert-frontmatter "$slide" 'slides' '_slides/' 'slides'
done
echo Asserting unique refs... >&2