aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2020-02-06 03:58:52 -0300
committerEuAndreh <eu@euandre.org>2020-02-06 03:58:52 -0300
commitccadc0bdf0436cefe76318567d358f27a46bf3e5 (patch)
tree58d52309b1ea2b6b7c3a08feed04deb5d64b83d2 /scripts
parentAdd code metadata annotation (diff)
parentSetup publish environment variables (diff)
downloadeuandre.org-ccadc0bdf0436cefe76318567d358f27a46bf3e5.tar.gz
euandre.org-ccadc0bdf0436cefe76318567d358f27a46bf3e5.tar.xz
Merge branch 'jekyll'
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/assert-content.sh99
-rwxr-xr-xscripts/bundix-gen.sh5
-rw-r--r--scripts/publish-env.sh4
3 files changed, 108 insertions, 0 deletions
diff --git a/scripts/assert-content.sh b/scripts/assert-content.sh
new file mode 100755
index 0000000..f9ea345
--- /dev/null
+++ b/scripts/assert-content.sh
@@ -0,0 +1,99 @@
+#!/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}"
+ if ! contains-element "${LANG}" "${LANGS[@]}"; then
+ 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."
+ exit 1
+ }
+done
+
+echo Linting pages... >&2
+IGNORED_PAGES=(/site.json /sitemap.xml /rss.xml /atom.xml /feed.atom /feed.xml /feed.all.atom /feed.en.atom /feed.pt.atom)
+for page in $(jq -r '.pages[] | @base64' "${JSON}"); do
+ URL="$(get-url "$page")"
+ if ! contains-element "${URL}" "${IGNORED_PAGES[@]}"; then
+ assert-frontmatter "${page}"
+ fi
+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")"
+ if ! contains-element "${URL}" "${IGNORED_PAGES[@]}"; then
+ LANG="$(get-lang "$page")"
+ REF="$(get-ref "$page")"
+ ID="${LANG}:${REF}"
+
+ if contains-element "${ID}" "${KNOWN_IDS[@]}"; then
+ red "Duplicated lang:ref match: '${ID}'." >&2
+ exit 1
+ fi
+
+ KNOWN_IDS+=("${ID}") # printf '%s\n' "${KNOWN_IDS[@]}"
+ fi
+done
+
+echo Done. >&2
diff --git a/scripts/bundix-gen.sh b/scripts/bundix-gen.sh
new file mode 100755
index 0000000..1dd303e
--- /dev/null
+++ b/scripts/bundix-gen.sh
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+set -Eeuo pipefail
+
+bundler package --no-install --path vendor
+bundix
diff --git a/scripts/publish-env.sh b/scripts/publish-env.sh
new file mode 100644
index 0000000..d5e8be2
--- /dev/null
+++ b/scripts/publish-env.sh
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+
+export SERVER_URL=root@euandre.org
+export DOCS_SERVER_PATH="/home/user-data/www/default/"