Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit62daf522a1e51c4a1d9d8b31d2a0093da86ebc5d (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-09-28 17:15:36 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-09-29 17:40:09 +0300
Files7474bc314afde18b6e53bb6702f54a04c5a87ed1
syndamia.com-62daf522a1e51c4a1d9d8b31d2a0093da86ebc5d.tar
syndamia.com-62daf522a1e51c4a1d9d8b31d2a0093da86ebc5d.tar.gz
syndamia.com-62daf522a1e51c4a1d9d8b31d2a0093da86ebc5d.zip
Parenta8b5c3c03b37ebf90e7ee8c9cb7c8f913f50c79a (diff)
[hooks] Reworked all hooks to use awk for their logic
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(/&#38;&#38;nos/, "<table class=\"file-list\"><tr>")
+ gsub(/^<p>&#38;&#38;fos$/, "<details class=\"file-wrapper\"><summary>")
+ gsub(/^&#38;&#38;fs0$/, "</summary><table class=\"file-list\"><tr>")
+ gsub(/^&#38;&#38;fs$/, "</tr><tr>")
+ gsub(/^&#38;&#38;nod<\/p>$/, "</tr></table>")
+ gsub(/^&#38;&#38;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] = "&#38;&#38;" 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>&#38;&#38;" names[ind] "</p>", "<div class=\"" names[ind] "\">")
+ gsub("<p>&#38;&#38;&#47;" names[ind] "</p>", "</div>")
+ }
+ else {
+ gsub("<p>&#38;&#38;" names[ind] "</p>", "<div class=\"" names[ind] "\"></div>")
+ }
+}
+
+{
+ gsub("<p>&#38;&#38;presentation</p>", pres)
+ gsub("<p>&#38;&#38;&#47;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/&#38;&#38;nos$/<table class="file-list"><tr>/g;
- s/^<p>&#38;&#38;fos$/<details class="file-wrapper"><summary>/g;
- s/^&#38;&#38;fs0$/<\/summary><table class="file-list"><tr>/g;
- s/^&#38;&#38;fs$/<\/tr><tr>/g;
- s/^&#38;&#38;nod<\/p>$/<\/tr><\/table>/g;
- s/^&#38;&#38;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/&#38;&#38;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>&#38;&#38;presentation<\/p>/$presentation/g;
- s/<p>&#38;&#38;slide<\/p>/<div class=\"slide\">/g;s/<p>&#38;&#38;&#47;slide<\/p>/<\/div>/g;
- s/<p>&#38;&#38;centered<\/p>/<div class=\"centered\">/g;s/<p>&#38;&#38;&#47;centered<\/p>/<\/div>/g;
- s/<p>&#38;&#38;flexer<\/p>/<div class=\"flexer\"><\/div>/g;s/&#38;&#38;flexer/<div class=\"flexer\"><\/div>/g;
- s/<p>&#38;&#38;fow<\/p>/<div class=\"fow\">/g;s/<p>&#38;&#38;&#47;fow<\/p>/<\/div>/g;
- s/<p>&#38;&#38;fol<\/p>/<div class=\"fol\">/g;s/<p>&#38;&#38;&#47;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