From 1fe3d39788cfb0a167ff562fa121c90ea3b445c7 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 4 Jul 2022 16:41:27 +0300 Subject: Reworked how HTML-editing scripts are handled --- generate-hooks/make-descriptions.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 generate-hooks/make-descriptions.sh (limited to 'generate-hooks/make-descriptions.sh') diff --git a/generate-hooks/make-descriptions.sh b/generate-hooks/make-descriptions.sh new file mode 100755 index 0000000..49417f5 --- /dev/null +++ b/generate-hooks/make-descriptions.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +if [ -z "$1" ]; then + echo First parameter must be a path + exit +fi + +# Loop through all HTML files in given directory +for file in $(find "$1" -type f -name "*.html"); do + # Get text that matches "p>any amount of characters" and "(.+)<\/p" $file | sed "s/p>\|<\/p//g" | sed "s/<.*//g" | grep .) + + # Get the first 200 characters only when it's longer than 200 characters + if [ ${#description} -gt 200 ]; then + description="${description::200}..." + fi + + # Escape all non-acceptable characters (thanks https://www.unix.com/302989284-post3.html) + description=$(echo $description | sed 's/[^a-zA-Z 0-9]/\\&/g') + + # Replace all "[DESCRIPTION]" text in current file with what we selected (inside description) + sed -i "s/\[DESCRIPTION\]/$description/g" $file +done -- cgit v1.3.1-26-gb76a