Summary Files Commits Branches @commit @diff @stats
path: root / awk-edits / File-lists.awk
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 /awk-edits/File-lists.awk
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
1 files changed, 165 insertions, 0 deletions
-rw-r--r--awk-edits/File-lists.awk165
diff --git a/awk-edits/File-lists.awk b/awk-edits/File-lists.awk
new file mode 100644
index 0000000..8903b95
--- /dev/null
+++ b/awk-edits/File-lists.awk
@@ -0,0 +1,165 @@
+#
+# == About ==
+#
+# Each file list is a "details" element, that contains a table, each row being a different file
+# or alternatively, just the table on it's own.
+#
+# -- Result HTML --
+#
+# <details>
+# <summary>Folder Info</summary>
+# <table>
+# <tr>File Data</tr>
+# </table>
+# </details>
+# or
+# <table>
+# <tr>File Data</tr>
+# </table>
+
+#
+# == ftags ==
+#
+# &&folder The text right afterwards is the title of the folder. All files
+# are hidden inside the collapsed details tag (click to show).
+# The file table is indented. You cannot have a folder inside a folder.
+# It can be omitted, and the files table will be shown as-is.
+#
+# &&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 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
+# 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"
+# for the corresponding type.
+# Available values for TYPE: photo, text, zip, movie, markdown
+#
+# -- Placement/Flow --
+#
+# All ftags, except &&fd, can be placed on their own line (empty line above and below)
+# or before/after another ftag.
+# Folder title must be inside the same paragraph as the ftag itself. This means that,
+# after
+# every &&folder ftag, the text can continue directly next to it and/or on new lines,
+# without there being any empty lines (you can add those with <br> or two spaces at
+# line end).
+#
+# -- Example Usage --
+#
+# (I like to indent a bit &&fd ftags, for readability's sake, but you don't have to)
+#
+# &&file
+# &&ft-text
+# &&fd Notes
+# &&fd 10 KB
+# &&/files
+#
+# &&folder Math
+# &&file
+# &&ft-text
+# &&fd Homework 1
+# &&file
+# &&ft-text
+# &&fd Homework 2
+# &&/files
+#
+# &&folder Art Project<br>
+# Status: 70% complete<br>
+# Note: Reserach Van Gogh paintings
+#
+# &&file
+# &&fd Painting 1
+# &&fd 100% Complete
+#
+# &&file
+# &&fd Painting 2
+# &&fd 40% Complete
+#
+# &&/files
+
+BEGIN {
+ fileStarted = 0
+ noFolder = 1
+ searchEndP = 0 # Used to remove trailing </p> in file row
+
+ # Special formatting
+ 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
+
+ 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(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 fileSubstitute(ind) {
+ gsub(/(<p>|<\/p>)/, "")
+
+ # &&file
+ if (ind == 2 && fileStarted == 0) {
+ if (noFolder == 1)
+ gsub("&#38;&#38;file", "<table class=\"file-list\"><tr>")
+ else
+ gsub("&#38;&#38;file", "</summary><table class=\"file-list\"><tr>")
+ fileStarted = 1
+ }
+ # &&/files
+ else if (ind == 3 && noFolder == 1) {
+ gsub("&#38;&#38;&#47;files", "</tr></table>")
+ }
+ # &&fd
+ else if (ind == 4) {
+ gsub(/&#38;&#38;fd[ \t]*/, "<td>")
+ gsub(/$/, "</td>")
+ }
+ else
+ gsub(flpat[ind], flrepl[ind])
+
+ # &&folder
+ if (ind == 1) {
+ noFolder = 0
+ searchEndP = 1
+ }
+ # &&/files
+ else if (ind == 3) {
+ fileStarted = 0
+ noFolder = 1
+ }
+}
+
+/^[ \t]*(<p>|)&#38;&#38;/ {
+ for (i = 1; i <= length(flname); i++) {
+ if (index($0, flpat[i]) != 0)
+ fileSubstitute(i)
+ }
+}
+
+searchEndP == 1 && /<\/p>/ {
+ gsub(/<\/p>/, "")
+ searchEndP = 0
+}