diff options
author | EuAndreh <eu@euandre.org> | 2020-02-05 23:37:38 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2020-02-05 23:37:38 -0300 |
commit | 97b809d4c0fe6e4b36c96ac4530266c40f0e0777 (patch) | |
tree | 264d2ca90871cfe22d85c1d09c7f778f31d51ab0 | |
parent | Point to language-specific home (diff) | |
download | euandre.org-97b809d4c0fe6e4b36c96ac4530266c40f0e0777.tar.gz euandre.org-97b809d4c0fe6e4b36c96ac4530266c40f0e0777.tar.xz |
Test: assert date in filename matches date in frontmatter
-rw-r--r-- | TODOs.org | 2 | ||||
-rwxr-xr-x | scripts/assert-content.sh | 42 | ||||
-rw-r--r-- | site.json | 1 |
3 files changed, 35 insertions, 10 deletions
@@ -1,7 +1,6 @@ * Tasks ** Spelling ** config.yml -** https://github.com/planetjekyll/awesome-jekyll-plugins/ ** change file naming strategy use subfolders? ** Fix date formatting @@ -9,3 +8,4 @@ use subfolders? https://www.sylvaindurand.org/making-jekyll-multilingual/ ** Indent XML and HTML ** Drafts in feed +** Fix markdown of posts and pastebins 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 @@ -5,6 +5,7 @@ {% for post in site.posts %} { "title": "{{ post.title | smartify }}", + "date": "{{ post.date }}", "url": "{{ post.url }}", "lang": "{{ post.lang }}", "ref": "{{ post.ref }}", |