From 381ac1fc3d98ecd0b6f5215c54f907eac6d2b873 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Wed, 12 Feb 2020 09:26:16 -0300 Subject: html tidy wip --- _layouts/default.html | 2 +- _layouts/index.html | 20 +++++++++++--------- default.nix | 4 +++- scripts/tidy-content.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 11 deletions(-) create mode 100755 scripts/tidy-content.sh diff --git a/_layouts/default.html b/_layouts/default.html index 1ff8c1d..6416f57 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -57,7 +57,7 @@
-

{{ page.title }}

+ {% if page.title %}

{{ page.title }}

{% endif %} {{ content }}
diff --git a/_layouts/index.html b/_layouts/index.html index 3c145d0..73b97ef 100644 --- a/_layouts/index.html +++ b/_layouts/index.html @@ -2,12 +2,14 @@ layout: default ---

{{ site.t.recent_posts[page.lang] }}

- +{% if site.posts.size > 0 %} + +{% endif %} diff --git a/default.nix b/default.nix index c664429..0f98063 100644 --- a/default.nix +++ b/default.nix @@ -33,9 +33,10 @@ in rec { }); docs = utils.baseTask.overrideAttrs (baseAttrs: { name = "${baseAttrs.name}-docs"; - buildInputs = [ jekyllEnv ]; + buildInputs = [ jekyllEnv pkgs.html-tidy ]; buildPhase = '' jekyll build -d $out + find $out -type f -name '*.html' | xargs -I{} tidy -errors -utf8 -indent -modify {} ''; }); }; @@ -51,6 +52,7 @@ in rec { buildInputs = [ jekyllEnv (pkgs.hunspellWithDicts (with pkgs.hunspellDicts; [ en-us ])) + pkgs.html-tidy ]; }; publishScript = utils.overwritingPublishScript { diff --git a/scripts/tidy-content.sh b/scripts/tidy-content.sh new file mode 100755 index 0000000..53533a1 --- /dev/null +++ b/scripts/tidy-content.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +end="\033[0m" +red="\033[0;31m" +red() { echo -e "${red}${1}${end}"; } + +usage() { + red "Missing argument <${1}>.\n" + cat < + + Arguments: + INPUT_DIR Input directory with the static HTML to be tidy-ed + +Examples: + $0 _site/ +EOF +} + +INPUT_DIR="${1:-}" +[[ -z "${INPUT_DIR}" ]] && { + usage 'INPUT_DIR' + exit 2 +} + +format() { + FILE="${1}" + # mktemp + if ! tidy -utf8 -indent -modify "${FILE}" 2>> tmp-error.txt; then + cat <(echo "${FILE}") tmp-error.txt >> errors.txt + echo "Error in formatting '${FILE}'. See errors.txt for more detail." + exit 1 + fi +} +export -f format + +find "${INPUT_DIR}" -type f -name '*.html' -print0 | \ + xargs -0 -I{} bash -c "format {}" -- cgit v1.2.3