From 37109100c380814e21e5d7cc244f1d17e5b8b638 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Mon, 17 Aug 2020 15:39:08 -0300 Subject: assert-content.sh: Check that declared layout matches the folder --- scripts/assert-content.sh | 22 ++++++++++++++++++++++ site.json | 8 ++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/scripts/assert-content.sh b/scripts/assert-content.sh index ee028a6..da73e65 100755 --- a/scripts/assert-content.sh +++ b/scripts/assert-content.sh @@ -58,6 +58,10 @@ get-title() { echo "${1}" | base64 --decode | jq -r .title } +get-layout() { + echo "${1}" | base64 --decode | jq -r .layout +} + LANGS=(en pt fr) IGNORED_PAGES=(site.json sitemap.xml *.atom) @@ -144,4 +148,22 @@ assert-unique-ref "$(jq -r '.pages[] | @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" + echo Done. >&2 diff --git a/site.json b/site.json index 3e544ac..2a27e8d 100644 --- a/site.json +++ b/site.json @@ -15,7 +15,7 @@ "url": "{{ post.url }}", "lang": "{{ post.lang }}", "ref": "{{ post.ref }}", - "layout": "post", + "layout": "{{ post.layout }}", "content": {{ post.content | strip_html | jsonify }} }{% unless forloop.last %},{% endunless %} {% endfor %} @@ -34,7 +34,7 @@ "lang": "{{ page.lang }}", "ref": "{{ page.ref }}", "plaintext": "{{ page.plaintext }}", - "layout": "page", + "layout": "{{ page.layout }}", "content": {{ page.content | strip_html | jsonify }} }{% unless forloop.last %},{% endunless %} {% endfor %} @@ -53,7 +53,7 @@ "url": "{{ pastebin.url }}", "lang": "{{ pastebin.lang }}", "ref": "pastebin-ref", - "layout": "pastebin", + "layout": "{{ pastebin.layout }}", "content": {{ pastebin.content | strip_html | jsonify }} }{% unless forloop.last %},{% endunless %} {% endfor %} @@ -72,7 +72,7 @@ "url": "{{ til.url }}", "lang": "{{ til.lang }}", "ref": "{{ til.ref }}", - "layout": "til", + "layout": "{{ til.layout }}", "content": {{ til.content | strip_html | jsonify }} }{% unless forloop.last %},{% endunless %} {% endfor %} -- cgit v1.2.3