From 84131a6ca68b79f94b0a49bd2d67a2e033f5572d Mon Sep 17 00:00:00 2001 From: welpo Date: Fri, 2 Aug 2024 17:59:34 +0200 Subject: [PATCH] add HTML minification step --- content/blog/updating-site-with-webhook/index.ca.md | 7 ++++++- content/blog/updating-site-with-webhook/index.es.md | 11 ++++++++--- content/blog/updating-site-with-webhook/index.md | 11 ++++++++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/content/blog/updating-site-with-webhook/index.ca.md b/content/blog/updating-site-with-webhook/index.ca.md index 22435bb..d1f3efe 100644 --- a/content/blog/updating-site-with-webhook/index.ca.md +++ b/content/blog/updating-site-with-webhook/index.ca.md @@ -1,7 +1,7 @@ +++ title = "Automatitzant l'actualització de la meva web amb un webhook" date = 2023-08-28 -updated = 2023-12-02 +updated = 2024-08-02 description= "Com que els fitxers d'aquesta web estan a GitHub, vaig pensar que seria bona idea actualitzar-la automàticament amb cada canvi al repositori." [taxonomies] @@ -314,6 +314,11 @@ git submodule update || notify_failure "Git submodule update ha fallat" echo "Construint el lloc…" zola build --output-dir "$temp_dir" --force || notify_failure "Zola build ha fallat" +# Minifica l'HTML amb https://github.com/terser/html-minifier-terser +# La minificació nativa de Zola elimina les cometes necessàries perquè les targetes de xarxes socials funcionin de forma consistent a WhatsApp. +echo "Minificant HTML…" +find "$temp_dir" -name '*.html' -exec html-minifier-terser --collapse-whitespace --conservative-collapse --remove-comments --remove-optional-tags --use-short-doctype -o {} {} \; || notify_failure "Minification failed" + # Sincronitza els arxius al directori final. echo "Sincronitzant els arxius…" rsync -a --delete "$temp_dir/" "$live_dir/" || notify_failure "rsync ha fallat" diff --git a/content/blog/updating-site-with-webhook/index.es.md b/content/blog/updating-site-with-webhook/index.es.md index 3f9812f..2dd930e 100644 --- a/content/blog/updating-site-with-webhook/index.es.md +++ b/content/blog/updating-site-with-webhook/index.es.md @@ -1,7 +1,7 @@ +++ title = "Automatizando la actualización de mi web con un webhook" date = 2023-08-28 -updated = 2023-12-02 +updated = 2024-08-02 description = "Como los archivos de esta web están en GitHub, pensé que sería buena idea actualizarla automáticamente con cada cambio en el repositorio." [taxonomies] @@ -306,14 +306,19 @@ trap 'trap_cleanup' EXIT echo "Actualizando el repositorio…" cd "$repo" git fetch || notify_failure "Git fetch ha fallado" -git reset --hard origin || notify_failure "Git reset ha fallado" -git pull || notify_failure "Git pull ha fallado" +git reset --hard origin || notify_failure "Git reset ha fallado" +git pull || notify_failure "Git pull ha fallado" git submodule update || notify_failure "Git submodule update ha fallado" # Build site in temporary directory. echo "Construyendo el sitio…" zola build --output-dir "$temp_dir" --force || notify_failure "Zola build ha fallado" +# Minifica el HTML con https://github.com/terser/html-minifier-terser +# La minificación nativa de Zola elimina las comillas necesarias para que las tarjetas de redes sociales funcionen de forma consistente en WhatsApp. +echo "Minificando HTML…" +find "$temp_dir" -name '*.html' -exec html-minifier-terser --collapse-whitespace --conservative-collapse --remove-comments --remove-optional-tags --use-short-doctype -o {} {} \; || notify_failure "Minification failed" + # Sincroniza los archivos al directorio final. echo "Sincronizando los archivos…" rsync -a --delete "$temp_dir/" "$live_dir/" || notify_failure "rsync ha fallado" diff --git a/content/blog/updating-site-with-webhook/index.md b/content/blog/updating-site-with-webhook/index.md index 8311d8e..49b9cf1 100644 --- a/content/blog/updating-site-with-webhook/index.md +++ b/content/blog/updating-site-with-webhook/index.md @@ -1,7 +1,7 @@ +++ title = "Automatically Updating My Zola Site Using a Webhook" date = 2023-08-28 -updated = 2023-12-02 +updated = 2024-08-02 description = "Since this site's files are on GitHub, I thought it would be a nice idea to automatically update it whenever the repository is modified." [taxonomies] @@ -306,14 +306,19 @@ trap 'trap_cleanup' EXIT echo "Updating repository…" cd "$repo" git fetch || notify_failure "Git fetch failed" -git reset --hard origin || notify_failure "Git reset failed" -git pull || notify_failure "Git pull failed" +git reset --hard origin || notify_failure "Git reset failed" +git pull || notify_failure "Git pull failed" git submodule update || notify_failure "Git submodule update failed" # Build site in temporary directory. echo "Running Zola build…" zola build --output-dir "$temp_dir" --force || notify_failure "Zola build failed" +# Minify HTML with https://github.com/terser/html-minifier-terser +# Native Zola minification strips quotes needed for social media cards to work consistently on WhatsApp. +echo "Minifying HTML…" +find "$temp_dir" -name '*.html' -exec html-minifier-terser --collapse-whitespace --conservative-collapse --remove-comments --remove-optional-tags --use-short-doctype -o {} {} \; || notify_failure "Minification failed" + # Sync files to the live directory. echo "Syncing files…" rsync -a --delete "$temp_dir/" "$live_dir/" || notify_failure "rsync failed"