diff options
| Commit | 62daf522a1e51c4a1d9d8b31d2a0093da86ebc5d (patch) | |
|---|---|---|
| Author | 2022-09-28 17:15:36 +0300 | |
| Committer | 2022-09-29 17:40:09 +0300 | |
| Files | 7474bc314afde18b6e53bb6702f54a04c5a87ed1 | |
| syndamia.com-62daf522a1e51c4a1d9d8b31d2a0093da86ebc5d.tar syndamia.com-62daf522a1e51c4a1d9d8b31d2a0093da86ebc5d.tar.gz syndamia.com-62daf522a1e51c4a1d9d8b31d2a0093da86ebc5d.zip | ||
| Parent | a8b5c3c03b37ebf90e7ee8c9cb7c8f913f50c79a (diff) | |
[hooks] Reworked all hooks to use awk for their logic
10 files changed, 110 insertions, 46 deletions
| -rw-r--r-- | generate-hooks/create-description.awk | 18 | ||||
| -rw-r--r-- | generate-hooks/create-file-lists.awk | 9 | ||||
| -rw-r--r-- | generate-hooks/create-flags.awk | 16 | ||||
| -rw-r--r-- | generate-hooks/create-presentation.awk | 45 | ||||
| -rw-r--r-- | generate-hooks/create-title.awk | 7 | ||||
| -rwxr-xr-x | generate-hooks/make-descriptions.sh | 16 | ||||
| -rwxr-xr-x | generate-hooks/make-file-lists.sh | 10 | ||||
| -rwxr-xr-x | generate-hooks/make-flags.sh | 5 | ||||
| -rwxr-xr-x | generate-hooks/make-presentation.sh | 19 | ||||
| -rwxr-xr-x | generate-hooks/make-titles.sh | 11 |
diff --git a/generate-hooks/create-description.awk b/generate-hooks/create-description.awk new file mode 100644 index 0000000..b4fac0e --- /dev/null +++ b/generate-hooks/create-description.awk @@ -0,0 +1,18 @@ +/p>.*/ { + # Removes tags and bad characters + gsub(/<[^>]*>/, "") ; gsub(/[^a-zA-Z0-9 ]/, "") + # Trims leading and trailing spaces and tabs (if any) + gsub(/^[ \t]*/, "") ; gsub(/[ \t]*$/, "") + + # Concatenates the current record to variable and shortens it, + # when it gets too long + desc = desc $0 + if (length(desc) >= 200) { + desc = substr(desc, 1, 197) "..." + exit + } +} + +END { + print desc +} diff --git a/generate-hooks/create-file-lists.awk b/generate-hooks/create-file-lists.awk new file mode 100644 index 0000000..c94ad71 --- /dev/null +++ b/generate-hooks/create-file-lists.awk @@ -0,0 +1,9 @@ +{ + gsub(/&&nos/, "<table class=\"file-list\"><tr>") + gsub(/^<p>&&fos$/, "<details class=\"file-wrapper\"><summary>") + gsub(/^&&fs0$/, "</summary><table class=\"file-list\"><tr>") + gsub(/^&&fs$/, "</tr><tr>") + gsub(/^&&nod<\/p>$/, "</tr></table>") + gsub(/^&&fod<\/p>$/, "</tr></table></details>") + print +} diff --git a/generate-hooks/create-flags.awk b/generate-hooks/create-flags.awk new file mode 100644 index 0000000..1917798 --- /dev/null +++ b/generate-hooks/create-flags.awk @@ -0,0 +1,16 @@ +BEGIN { + flag[1] = "gb" + title[1] = "ENG" + + for (i = 1; i <= length(flag); i++) { + flagExp[i] = "&&" flag[i] + flagTag[i] = "<img src=\"/img/" flag[i] ".svg\" class=\"unzoomable\" alt=\"" title[i] "\" title=\"" title[i] "\">" + } +} + +{ + for (i = 1; i <= length(flagExp); i++) { + gsub(flagExp[i], flagTag[i]) + } + print +} diff --git a/generate-hooks/create-presentation.awk b/generate-hooks/create-presentation.awk new file mode 100644 index 0000000..fe10d0b --- /dev/null +++ b/generate-hooks/create-presentation.awk @@ -0,0 +1,45 @@ +BEGIN { + pres = ORS \ +"<nav id=\"presentCont\">" ORS \ +" <img id=\"prevSlideBtn\" class=\"unzoomable btn setting-btn icon nodisplay\" src=\"/img/arrow-left-tabler.svg\" alt=\"Previous\">" ORS \ +" <img id=\"nextSlideBtn\" class=\"unzoomable btn setting-btn icon nodisplay\" src=\"/img/arrow-right-tabler.svg\" alt=\"Next\">" ORS \ +" <img id=\"presentBtn\" class=\"unzoomable btn setting-btn icon\" src=\"/img/presentation-tabler.svg\" alt=\"Present\">" ORS \ +" <img id=\"printBtn\" class=\"unzoomable btn setting-btn icon\" src=\"/img/printer-tabler.svg\" alt=\"Print\">" ORS \ +" </nav>" ORS \ +" <script type=\"text/javascript\" src=\"/scripts/presentation.js\" integrity=\"sha512-79MwfB0EQJMdVjVnd3PA0Cn9fo4JaMUmNuyZNEGSbaMEGcqdE8sWWAbMLheaoptDyb/KuYgNw0pKwvR5Dw+lJw==\" crossorigin=\"anonymous\"></script>" + + names[1] = "slide" + ended[1] = 1 + names[2] = "centered" + ended[2] = 1 + names[3] = "flexer" + ended[3] = 0 + names[4] = "fow" + ended[4] = 1 + names[5] = "fol" + ended[5] = 1 + names[6] = "font18" + ended[6] = 1 +} + +function substitute(ind) { + if (ended[ind] == 1) { + gsub("<p>&&" names[ind] "</p>", "<div class=\"" names[ind] "\">") + gsub("<p>&&/" names[ind] "</p>", "</div>") + } + else { + gsub("<p>&&" names[ind] "</p>", "<div class=\"" names[ind] "\"></div>") + } +} + +{ + gsub("<p>&&presentation</p>", pres) + gsub("<p>&&/font</p>", "</div>") + + for (i = 1; i <= length(names); i++) { + if (index($0, names[i] "<") != 0) + substitute(i) + } + + print +} diff --git a/generate-hooks/create-title.awk b/generate-hooks/create-title.awk new file mode 100644 index 0000000..14d8ec6 --- /dev/null +++ b/generate-hooks/create-title.awk @@ -0,0 +1,7 @@ +/<h1>.+/ { + # Takes everything between <h1> and </h1> in the first + # <h1> occurence. + h = index($0, "<h1>") + print substr($0, h, index($0, "</h1") - h) + exit +} diff --git a/generate-hooks/make-descriptions.sh b/generate-hooks/make-descriptions.sh index 1ea7a9f..9895f2e 100755 --- a/generate-hooks/make-descriptions.sh +++ b/generate-hooks/make-descriptions.sh @@ -5,21 +5,11 @@ if [ -z "$1" ]; then exit fi -# Loop through all HTML files in given directory - # 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;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 +awkloc="$(dirname "$0")/create-description.awk" - # Escape all non-acceptable characters (thanks https://www.unix.com/302989284-post3.html) - description=$(echo $description | sed 's/[^a-zA-Z 0-9]/\\&/g') +# Loop through all HTML files in given directory for file in $1; do + description=$(awk -f "$awkloc" $file) # Replace all "[DESCRIPTION]" text in current file with what we selected (inside description) sed -i "s/\[DESCRIPTION\]/$description/g" $file diff --git a/generate-hooks/make-file-lists.sh b/generate-hooks/make-file-lists.sh index e407e19..87d8e61 100755 --- a/generate-hooks/make-file-lists.sh +++ b/generate-hooks/make-file-lists.sh @@ -53,12 +53,8 @@ if [ -z "$1" ]; then exit fi +awkloc="$(dirname "$0")/create-file-lists.awk" + for file in $1; do - sed -i 's/&&nos$/<table class="file-list"><tr>/g; - s/^<p>&&fos$/<details class="file-wrapper"><summary>/g; - s/^&&fs0$/<\/summary><table class="file-list"><tr>/g; - s/^&&fs$/<\/tr><tr>/g; - s/^&&nod<\/p>$/<\/tr><\/table>/g; - s/^&&fod<\/p>$/<\/tr><\/table><\/details>/g' \ - "$file" + awk -f "$awkloc" $file > tmp && mv -f tmp $file done diff --git a/generate-hooks/make-flags.sh b/generate-hooks/make-flags.sh index 69d8952..84adfaf 100755 --- a/generate-hooks/make-flags.sh +++ b/generate-hooks/make-flags.sh @@ -11,7 +11,8 @@ if [ -z "$1" ]; then exit fi +awkloc="$(dirname "$0")/create-flags.awk" + for file in $1; 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" + awk -f "$awkloc" $file > tmp && mv -f tmp $file done diff --git a/generate-hooks/make-presentation.sh b/generate-hooks/make-presentation.sh index dab3243..c27fba2 100755 --- a/generate-hooks/make-presentation.sh +++ b/generate-hooks/make-presentation.sh @@ -30,23 +30,8 @@ if [ -z "$1" ]; then exit fi -presentation=' - <nav id="presentCont"> - <img id="prevSlideBtn" class="unzoomable btn setting-btn icon nodisplay" src="/img/arrow-left-tabler.svg" alt="Previous"> - <img id="nextSlideBtn" class="unzoomable btn setting-btn icon nodisplay" src="/img/arrow-right-tabler.svg" alt="Next"> - <img id="presentBtn" class="unzoomable btn setting-btn icon" src="/img/presentation-tabler.svg" alt="Present"> - <img id="printBtn" class="unzoomable btn setting-btn icon" src="/img/printer-tabler.svg" alt="Print"> - </nav> - <script type="text/javascript" src="/scripts/presentation.js" integrity="sha512-79MwfB0EQJMdVjVnd3PA0Cn9fo4JaMUmNuyZNEGSbaMEGcqdE8sWWAbMLheaoptDyb/KuYgNw0pKwvR5Dw+lJw==" crossorigin="anonymous"></script>' -presentation=$(echo $presentation | sed 's/\//\\\//g') +awkloc="$(dirname "$0")/create-presentation.awk" -# Loop through all HTML files in given directory for file in $(echo $1 | grep 'talks'); do - sed -i "s/<p>&&presentation<\/p>/$presentation/g; - s/<p>&&slide<\/p>/<div class=\"slide\">/g;s/<p>&&/slide<\/p>/<\/div>/g; - s/<p>&&centered<\/p>/<div class=\"centered\">/g;s/<p>&&/centered<\/p>/<\/div>/g; - s/<p>&&flexer<\/p>/<div class=\"flexer\"><\/div>/g;s/&&flexer/<div class=\"flexer\"><\/div>/g; - s/<p>&&fow<\/p>/<div class=\"fow\">/g;s/<p>&&/fow<\/p>/<\/div>/g; - s/<p>&&fol<\/p>/<div class=\"fol\">/g;s/<p>&&/fol<\/p>/<\/div>/g" \ - "$file" + awk -f "$awkloc" $file > tmp && mv -f tmp $file done diff --git a/generate-hooks/make-titles.sh b/generate-hooks/make-titles.sh index 1c9ebef..4bb70b9 100755 --- a/generate-hooks/make-titles.sh +++ b/generate-hooks/make-titles.sh @@ -5,15 +5,12 @@ if [ -z "$1" ]; then exit fi -# Loop through all HTML files in given directory - # 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") +awkloc="$(dirname "$0")/create-title.awk" - # Escape all non-acceptable characters (thanks https://www.unix.com/302989284-post3.html) - title=$(echo $title | sed 's/[^a-zA-Z 0-9]/\\&/g') +# Loop through all HTML files in given directory for file in $1; do + title=$(awk -f "$awkloc" $file) - # Replace all "[TITLE]" text in current file with what we selected (inside title) + # Replace all "[TITLE]" text in current file with title sed -i "s/\[TITLE\]/$title/g" $file done |