diff options
| Commit | 1fe3d39788cfb0a167ff562fa121c90ea3b445c7 (patch) | |
|---|---|---|
| Author | 2022-07-04 16:41:27 +0300 | |
| Committer | 2022-07-04 16:41:27 +0300 | |
| Files | 548480d4dbd98da7e1d06f1d9c339a871600af21 /generate-hooks | |
| syndamia.com-1fe3d39788cfb0a167ff562fa121c90ea3b445c7.tar syndamia.com-1fe3d39788cfb0a167ff562fa121c90ea3b445c7.tar.gz syndamia.com-1fe3d39788cfb0a167ff562fa121c90ea3b445c7.zip | ||
| Parent | 287748bcd9d17462219699d01bb0d043812a9a8e (diff) | |
Reworked how HTML-editing scripts are handled
5 files changed, 123 insertions, 0 deletions
| -rw-r--r-- | generate-hooks/README.md | 14 | ||||
| -rwxr-xr-x | generate-hooks/make-descriptions.sh | 26 | ||||
| -rwxr-xr-x | generate-hooks/make-file-lists.sh | 47 | ||||
| -rwxr-xr-x | generate-hooks/make-flags.sh | 17 | ||||
| -rwxr-xr-x | generate-hooks/make-titles.sh | 19 |
diff --git a/generate-hooks/README.md b/generate-hooks/README.md new file mode 100644 index 0000000..d3c9210 --- /dev/null +++ b/generate-hooks/README.md @@ -0,0 +1,14 @@ +These scripts are ran by `generate.sh` and `generate-dev.sh` (which just run all .sh files in this folder). They're meant to modify the "compiled" HTML files. + +## ftags + +ftags are strings/words in the Markdown source files, that start with "&&" and continue with any (valid) sequence of characters. The name initially stood for "file tags", since the `make-file-lists.sh` script was the first to utilize them, but I've expanded their usage and their current name means "format tags". + +Their purpose is to shorten and abstract certain custom HTML code that I want to use in my pages (but will have to include as-is in the Markdown files). List of scripts that handle ftags: + +|Script|ftags|ftag can be anywhere in text| +|---|---|---| +|`make-file-lists.sh`|`&&fos`, `&&fs0`, `&&fs`, `&&fod`|No| +|`make-flags.sh`|`&&gb`|Yes| + +For more information on how to use the different ftags, consult the specified script. 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</p" from current file + # remove the "p>" and "</p" from result + # make everything that starts with "<" blank + # take all lines that aren't blank + description=$(egrep -o "p>(.+)<\/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 diff --git a/generate-hooks/make-file-lists.sh b/generate-hooks/make-file-lists.sh new file mode 100755 index 0000000..3952728 --- /dev/null +++ b/generate-hooks/make-file-lists.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# This is a really rudementary way to make making file lists less HTML-y +# I made it so: +# 1) You don't have to write quite as much HTML +# 2) The Data columns for each file get to be formatted as Markdown (<td> is not recognized as a block-level element, so the stuff inside get formatted https://kristaps.bsd.lv/lowdown/lowdown.5.html#HTML_Blocks) + +# Very roughly, each file list has the same structure: +# <details><summary>Folder Info</summary> <table> <tr>File Data</tr> </table> </details> + +# In Markdown you type in something like (without the "# " in front): +# +# &&fos +# Description +# &&fs0 +# <td>Data 1</td> +# <td>Data 1.1</td> +# <td>Data 1.2</td> +# &&fs +# <td>Data 2</td> +# <td>Data 2.1</td> +# <td>Data 2.2</td> +# &&fod +# +# And the lines starting with && (I'll call them ftags) get replaced by some HTML. The <td></td> around each file Data is mandatory. +# &&fs0 must only be used on before the very first file data. There must be no empty lines, lines mustn't start with spaces, there mustn't be anything around ftags and ftags have to be on their own lines. +# The commands have intuitive abbreviations: +# &&fos folder start +# &&fs0 file start of first file +# &&fs file start +# &&fod folder end + +if [ -z "$1" ]; then + echo First parameter must be a path + exit +fi + +for file in $(find "$1" -type f -name "*.html"); do + # Replaces "&&fos" with "<details class="file-wrapper"><summary>" + sed -i 's/^<p>&&fos$/<details class="file-wrapper"><summary>/g' "$file" + # Replaces "&&fs0" with "</summary><table class="file-list"><tr>" + sed -i 's/^&&fs0$/<\/summary><table class="file-list"><tr>/g' "$file" + # Replaces "&&fs" with "</tr><tr>" + sed -i 's/^&&fs$/<\/tr><tr>/g' "$file" + # Replaces "&&fod" with "</tr></table></details>" + sed -i 's/^&&fod<\/p>$/<\/tr><\/table><\/details>/g' "$file" +done diff --git a/generate-hooks/make-flags.sh b/generate-hooks/make-flags.sh new file mode 100755 index 0000000..786671d --- /dev/null +++ b/generate-hooks/make-flags.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Adds a way to more simply insert flags into text +# Each flag is represented with an ftag (text that is preceded by &&) + +# Available flags: +# Great Britain - &&gb + +if [ -z "$1" ]; then + echo First parameter must be a path + exit +fi + +for file in $(find "$1" -type f -name "*.html"); do + # Replaces "&&gb" with "<img src="/img/gb.svg" class="unzoomable" alt="ENG" title="ENG">" + sed -i 's/&&gb/<img src="\/img\/gb.svg" class="unzoomable" alt="ENG" title="ENG">/g' "$file" +done diff --git a/generate-hooks/make-titles.sh b/generate-hooks/make-titles.sh new file mode 100755 index 0000000..bf739ff --- /dev/null +++ b/generate-hooks/make-titles.sh @@ -0,0 +1,19 @@ +#!/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 "h1>any amount of characters</h1" from current file + # remove the "h1>" and "</h1" from result + title=$(egrep -o "h1(.+)>(.+)<\/h1" $file | sed "s/h1[^>]\+>\|<\/h1//g") + + # Escape all non-acceptable characters (thanks https://www.unix.com/302989284-post3.html) + title=$(echo $title | sed 's/[^a-zA-Z 0-9]/\\&/g') + + # Replace all "[TITLE]" text in current file with what we selected (inside title) + sed -i "s/\[TITLE\]/$title/g" $file +done |