Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit0187e255a811bebb0dad3624f2c6d78b829d15c5 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-01-17 16:15:28 +0200
Committer
 Syndamia <kamen@syndamia.com>
2023-01-17 16:15:28 +0200
Files68efd3520e72c8c8c553fdda7b9391d9ec4e9feb
syndamia.com-0187e255a811bebb0dad3624f2c6d78b829d15c5.tar
syndamia.com-0187e255a811bebb0dad3624f2c6d78b829d15c5.tar.gz
syndamia.com-0187e255a811bebb0dad3624f2c6d78b829d15c5.zip
Parentda000c477625bb533688df84bd95ba3a3aff3246 (diff)
[awk] Reworked generation to happen via a combined script, updated scripts and added info in scripts readme
14 files changed, 90 insertions, 96 deletions
-rw-r--r--awk-edits/File-lists.awk (renamed from generate-hooks/create-file-lists.awk)62
-rw-r--r--awk-edits/Flags.awk (renamed from generate-hooks/create-flags.awk)5
-rw-r--r--awk-edits/Group-contents.awk (renamed from generate-hooks/group-contents.awk)4
-rw-r--r--awk-edits/Header-Title.awk (renamed from generate-hooks/create-title.awk)4
-rw-r--r--awk-edits/Header-description.awk (renamed from generate-hooks/create-description.awk)4
-rw-r--r--awk-edits/Heading-anchors.awk (renamed from generate-hooks/create-header-anchors.awk)4
-rw-r--r--awk-edits/Pagenav.awk (renamed from generate-hooks/create-pagenav.awk)9
-rw-r--r--awk-edits/Presentation.awk (renamed from generate-hooks/create-presentation.awk)12
-rw-r--r--awk-edits/README.md25
-rw-r--r--awk-edits/_print.awk3
-rw-r--r--awk-edits/post-pagenav.awk4
-rwxr-xr-xgenerate-dev.sh25
-rw-r--r--generate-hooks/README.md15
-rwxr-xr-xgenerate.sh10
diff --git a/generate-hooks/create-file-lists.awk b/awk-edits/File-lists.awk
index 7d18bdd..8903b95 100644
--- a/generate-hooks/create-file-lists.awk
+++ b/awk-edits/File-lists.awk
@@ -27,14 +27,14 @@
#
# &&file Everything that follows this tag is the data for a file. You should
# use &&fd to specify columns of information! Depending on the context,
-# it might be replaced with the start of a table, closing the summary
+# it might be flrepllaced with the start of a table, closing the summary
# and starting table, or closing and opening a table row.
#
# &&/files This tag must exist at the bottom of a file list, no matter if it was
# started with or without a &&folder.
#
# &&fd Defines a column of information for a file (row). Practically, it is
-# replaced with <td>, and </td> is added to the end of the line.
+# flrepllaced with <td>, and </td> is added to the end of the line.
# If you don't use it, make sure to have the leading and trailing td tags!
#
# &&ft-TYPE Depending on TYPE, it inserts an image tag that contains the file "icon"
@@ -90,34 +90,34 @@ BEGIN {
searchEndP = 0 # Used to remove trailing </p> in file row
# Special formatting
- nam[1] = "folder"
- rep[1] = "<details class=\"file-wrapper\"><summary>"
- nam[2] = "file"
- rep[2] = "</tr><tr>"
- nam[3] = "&#47;files" # /files
- rep[3] = "</tr></table></details>"
- nam[4] = "fd"
- rep[4] = "" # Not used, refer to substitute function
+ flname[1] = "folder"
+ flrepl[1] = "<details class=\"file-wrapper\"><summary>"
+ flname[2] = "file"
+ flrepl[2] = "</tr><tr>"
+ flname[3] = "&#47;files" # /files
+ flrepl[3] = "</tr></table></details>"
+ flname[4] = "fd"
+ flrepl[4] = "" # Not used, refer to fileSubstitute function
- nam[5] = "ft-photo"
- rep[5] = "photo-tabler.svg"
- nam[6] = "ft-text"
- rep[6] = "file-text-tabler.svg"
- nam[7] = "ft-zip"
- rep[7] = "file-zip-tabler.svg"
- nam[8] = "ft-movie"
- rep[8] = "movie-tabler.svg"
- nam[9] = "ft-markdown"
- rep[9] = "markdown-tabler.svg"
+ flname[5] = "ft-photo"
+ flrepl[5] = "photo-tabler.svg"
+ flname[6] = "ft-text"
+ flrepl[6] = "file-text-tabler.svg"
+ flname[7] = "ft-zip"
+ flrepl[7] = "file-zip-tabler.svg"
+ flname[8] = "ft-movie"
+ flrepl[8] = "movie-tabler.svg"
+ flname[9] = "ft-markdown"
+ flrepl[9] = "markdown-tabler.svg"
- for (i = 1; i <= length(nam); i++) {
- pat[i] = "&#38;&#38;" nam[i]
- if (index(nam[i], "ft") == 1)
- rep[i] = "<td><img class=\"file-icon unzoomable\" src=\"/img/" rep[i] "\"></td>"
+ for (i = 1; i <= length(flname); i++) {
+ flpat[i] = "&#38;&#38;" flname[i]
+ if (index(flname[i], "ft") == 1)
+ flrepl[i] = "<td><img class=\"file-icon unzoomable\" src=\"/img/" flrepl[i] "\"></td>"
}
}
-function substitute(ind) {
+function fileSubstitute(ind) {
gsub(/(<p>|<\/p>)/, "")
# &&file
@@ -138,7 +138,7 @@ function substitute(ind) {
gsub(/$/, "</td>")
}
else
- gsub(pat[ind], rep[ind])
+ gsub(flpat[ind], flrepl[ind])
# &&folder
if (ind == 1) {
@@ -153,9 +153,9 @@ function substitute(ind) {
}
/^[ \t]*(<p>|)&#38;&#38;/ {
- for (i = 1; i <= length(nam); i++) {
- if (index($0, pat[i]) != 0)
- substitute(i)
+ for (i = 1; i <= length(flname); i++) {
+ if (index($0, flpat[i]) != 0)
+ fileSubstitute(i)
}
}
@@ -163,7 +163,3 @@ searchEndP == 1 && /<\/p>/ {
gsub(/<\/p>/, "")
searchEndP = 0
}
-
-{
- print
-}
diff --git a/generate-hooks/create-flags.awk b/awk-edits/Flags.awk
index d07901d..6f62916 100644
--- a/generate-hooks/create-flags.awk
+++ b/awk-edits/Flags.awk
@@ -15,11 +15,11 @@
BEGIN {
flag[1] = "gb"
- title[1] = "ENG"
+ flagTitle[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 svg\" alt=\"" title[i] "\" title=\"" title[i] "\">"
+ flagTag[i] = "<img src=\"/img/" flag[i] ".svg\" class=\"unzoomable svg\" alt=\"" flagTitle[i] "\" flagTitle=\"" flagTitle[i] "\">"
}
}
@@ -27,5 +27,4 @@ BEGIN {
for (i = 1; i <= length(flagExp); i++) {
gsub(flagExp[i], flagTag[i])
}
- print
}
diff --git a/generate-hooks/group-contents.awk b/awk-edits/Group-contents.awk
index f71e93d..d984eef 100644
--- a/generate-hooks/group-contents.awk
+++ b/awk-edits/Group-contents.awk
@@ -18,7 +18,3 @@ started == 1 && /<p>/ {
print "</div>"
started = 0
}
-
-{
- print
-}
diff --git a/generate-hooks/create-title.awk b/awk-edits/Header-Title.awk
index 24d5f7d..16247e8 100644
--- a/generate-hooks/create-title.awk
+++ b/awk-edits/Header-Title.awk
@@ -24,7 +24,3 @@ BEGIN {
"\\[TITLE\\]" {
gsub("\\[TITLE\\]", title)
}
-
-{
- print
-}
diff --git a/generate-hooks/create-description.awk b/awk-edits/Header-description.awk
index 8c0d753..028c14c 100644
--- a/generate-hooks/create-description.awk
+++ b/awk-edits/Header-description.awk
@@ -34,7 +34,3 @@ BEGIN {
"\\[DESCRIPTION\\]" {
gsub("\\[DESCRIPTION\\]", desc)
}
-
-{
- print
-}
diff --git a/generate-hooks/create-header-anchors.awk b/awk-edits/Heading-anchors.awk
index f6d2815..e4367c7 100644
--- a/generate-hooks/create-header-anchors.awk
+++ b/awk-edits/Heading-anchors.awk
@@ -10,7 +10,3 @@
id = substr(id, 0, index(id, "\"") - 1)
gsub(/$/, ORS "<a class=\"h-anchor\" href=\"#" id "\"><img src=\"/img/link-tabler.svg\" alt=\"🔗\" loading=\"lazy\"></a>")
}
-
-{
- print
-}
diff --git a/generate-hooks/create-pagenav.awk b/awk-edits/Pagenav.awk
index d539837..46589fb 100644
--- a/generate-hooks/create-pagenav.awk
+++ b/awk-edits/Pagenav.awk
@@ -37,12 +37,3 @@ BEGIN {
"</div>"
}
}
-
-{
- print
-}
-
-found == 0 && /<h1.*/ {
- print elem
- found = 1
-}
diff --git a/generate-hooks/create-presentation.awk b/awk-edits/Presentation.awk
index 3912b34..f0bbb4a 100644
--- a/generate-hooks/create-presentation.awk
+++ b/awk-edits/Presentation.awk
@@ -67,7 +67,7 @@
# Refer to src/talks/demo.md
BEGIN {
- if (substr(ARGV[1], "talks") == 0) exit # FILENAME isn't available yet
+ nopresentation=substr(ARGV[1], "talks") == 0 # FILENAME isn't available yet
# Exceptions to the normal format
names[ 1] = "presentation"
@@ -126,20 +126,16 @@ BEGIN {
}
}
-function substitute(ind) {
+function presentationSubstitute(ind) {
gsub(/(<p>|<\/p>)/, "")
gsub(pat[ind], rep[ind])
if (ended[ind] == 1)
gsub(cpat[ind], crep[ind])
}
-/^[ \t]*(<p>|)&#38;&#38;/ {
+nopresentation == 0 && /^[ \t]*(<p>|)&#38;&#38;/ {
for (i = 1; i <= length(names); i++) {
if (index($0, names[i]) != 0)
- substitute(i)
+ presentationSubstitute(i)
}
}
-
-{
- print
-}
diff --git a/awk-edits/README.md b/awk-edits/README.md
new file mode 100644
index 0000000..a9d1c77
--- /dev/null
+++ b/awk-edits/README.md
@@ -0,0 +1,25 @@
+All `.awk` files in this folder are ran by `generate.sh` and `generate-dev.sh`, after ssg and lowdown have created all HTML pages. These files are meant to work on the resultant HTML.
+
+For improved efficiency, rather than running every script seperately, they are meant to be concatinated into one script (`generate.sh` and `generate-dev.sh` combine them in `/tmp/syndamiadotcom-awk`), which is ran for each HTML file.
+This forces us to work with the following constraints:
+
+- NO awk script should print the current line (print should only be used to add new lines)
+ The script that starts with '\_' contains the print of the current line, all scripts that start with a capital letter are ran before it and all with small letter - after.
+ + If we print the current line in every script, the concatenated will print the current line multiple times
+- Variable names between scripts must be unique
+- `exit` mustn't be used!
+ Instead, use a variable and then add a check to every relevant rule.
+
+## 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 I got the idea while making the file lists functionality. Now I like to think of them as "format tags", since they are used for so much more.
+
+On the "backend", they just get replaced with specific HTML. List of scripts that handle ftags:
+
+|Script|ftags|
+|---|---|
+|`File-lists.awk`|`&&folder`, `&&file`, `&&/files`, `&&ft-TYPE` *(TYPE is one of `photo`, `text`, `zip`, `movie`, `markdown`)*|
+|`Flags.awk`|`&&gb`|
+|`Presentation.awk`|`&&presentation`, `&&slide`, `&&/slide`, `&&flexer`, `&&centered`, `&&/centered`, `&&fow`, `&&/fow`, `&&fcol`, `&&/fcol`, `&&fontSIZE` *(SIZE is one of `18`, `20`, `27`, `30`, `37`)*, `&&/font`|
+
+Information regarding their usage can be found at the top of their respective script file.
diff --git a/awk-edits/_print.awk b/awk-edits/_print.awk
new file mode 100644
index 0000000..fcf69c6
--- /dev/null
+++ b/awk-edits/_print.awk
@@ -0,0 +1,3 @@
+{
+ print
+}
diff --git a/awk-edits/post-pagenav.awk b/awk-edits/post-pagenav.awk
new file mode 100644
index 0000000..4587cae
--- /dev/null
+++ b/awk-edits/post-pagenav.awk
@@ -0,0 +1,4 @@
+found == 0 && /<h1.*/ {
+ print elem
+ found = 1
+}
diff --git a/generate-dev.sh b/generate-dev.sh
index 1e1c2ed..0fa8593 100755
--- a/generate-dev.sh
+++ b/generate-dev.sh
@@ -12,17 +12,26 @@ rm -f /var/www/synd/.files
# Generate files
ssg src /var/www/synd/ "Syndamia" "https://syndamia.com" > /dev/null
-allnormfiles=$(find '/var/www/synd' -type f -name "*.html")
dur=0
-
-for script in $(find "./generate-hooks" -type f -name "*.awk"); do
+startTimer () {
dur="$(date +%s%N)"
- for file in $allnormfiles; do
- awk -f "$script" "$file" > tmp && mv -f tmp "$file"
- done
+}
+endTimer () {
dur="$(echo "scale=4 ; ($(date +%s%N) - $dur) / 1000000000" | bc -l)"
- printf "%.3fs $script\n" $dur
-done
+ printf "%.3fs $1\n" $dur
+}
+
+startTimer
+ find './awk-edits' -type f -name "[A-Z]*.awk" -exec cat {} + > /tmp/syndamiadotcom-awk
+ find './awk-edits' -type f -name "_*.awk" -exec cat {} + >> /tmp/syndamiadotcom-awk
+ find './awk-edits' -type f -name "[a-z]*.awk" -exec cat {} + >> /tmp/syndamiadotcom-awk
+endTimer "generation of /tmp/syndamiadotcom-awk"
+
+startTimer
+ for file in $(find '/var/www/synd' -type f -name "*.html"); do
+ awk -f '/tmp/syndamiadotcom-awk' "$file" > tmp && mv -f tmp "$file"
+ done
+endTimer "/tmp/syndamiadotcom-awk"
#
# Tiny version
diff --git a/generate-hooks/README.md b/generate-hooks/README.md
deleted file mode 100644
index 3371de2..0000000
--- a/generate-hooks/README.md
+++ /dev/null
@@ -1,15 +0,0 @@
-All `.awk` files in this folder are ran by `generate.sh` and `generate-dev.sh`, after ssg and lowdown have created all HTML pages. These files are meant to work on the resultant HTML.
-
-## 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 I got the idea while making the file lists functionality. Now I like to think of them as "format tags", since they are used for so much more.
-
-On the "backend", they just get replaced with specific HTML. List of scripts that handle ftags:
-
-|Script|ftags|
-|---|---|
-|`make-file-lists.awk`|`&&folder`, `&&file`, `&&/files`, `&&ft-TYPE` *(TYPE is one of `photo`, `text`, `zip`, `movie`, `markdown`)*|
-|`make-flags.awk`|`&&gb`|
-|`make-presentation.awk`|`&&presentation`, `&&slide`, `&&/slide`, `&&flexer`, `&&centered`, `&&/centered`, `&&fow`, `&&/fow`, `&&fcol`, `&&/fcol`, `&&fontSIZE` *(SIZE is one of `18`, `20`, `27`, `30`, `37`)*, `&&/font`|
-
-Information regarding their usage can be found at the top of their respective script file.
diff --git a/generate.sh b/generate.sh
index 3481f23..902bcc5 100755
--- a/generate.sh
+++ b/generate.sh
@@ -15,10 +15,12 @@ ssg src website "Syndamia" "https://syndamia.com"
allnormfiles=$(find './website' -type f -name "*.html")
-for script in $(find "./generate-hooks" -type f -name "*.awk"); do
- for file in $allnormfiles; do
- awk -f "$script" "$file" > tmp && mv -f tmp "$file"
- done
+find './awk-edits' -type f -name "[A-Z]*.awk" -exec cat {} + > /tmp/syndamiadotcom-awk
+find './awk-edits' -type f -name "_*.awk" -exec cat {} + >> /tmp/syndamiadotcom-awk
+find './awk-edits' -type f -name "[a-z]*.awk" -exec cat {} + >> /tmp/syndamiadotcom-awk
+
+for file in $(find './website' -type f -name "*.html"); do
+ awk -f '/tmp/syndamiadotcom-awk' "$file" > tmp && mv -f tmp "$file"
done
#