From 1fe3d39788cfb0a167ff562fa121c90ea3b445c7 Mon Sep 17 00:00:00 2001
From: Syndamia
Date: Mon, 4 Jul 2022 16:41:27 +0300
Subject: Reworked how HTML-editing scripts are handled
---
generate-dev.sh | 7 +++---
generate-hooks/README.md | 14 +++++++++++
generate-hooks/make-descriptions.sh | 26 ++++++++++++++++++++
generate-hooks/make-file-lists.sh | 47 +++++++++++++++++++++++++++++++++++++
generate-hooks/make-flags.sh | 17 ++++++++++++++
generate-hooks/make-titles.sh | 19 +++++++++++++++
generate.sh | 7 +++---
make-descriptions.sh | 26 --------------------
make-file-lists.sh | 47 -------------------------------------
make-flags.sh | 17 --------------
make-titles.sh | 19 ---------------
11 files changed, 129 insertions(+), 117 deletions(-)
create mode 100644 generate-hooks/README.md
create mode 100755 generate-hooks/make-descriptions.sh
create mode 100755 generate-hooks/make-file-lists.sh
create mode 100755 generate-hooks/make-flags.sh
create mode 100755 generate-hooks/make-titles.sh
delete mode 100755 make-descriptions.sh
delete mode 100755 make-file-lists.sh
delete mode 100755 make-flags.sh
delete mode 100755 make-titles.sh
diff --git a/generate-dev.sh b/generate-dev.sh
index 4596873..4e37a37 100755
--- a/generate-dev.sh
+++ b/generate-dev.sh
@@ -12,10 +12,9 @@ sudo rm -f /var/www/synd/.files
# Generate files
sudo ssg6 src /var/www/synd/ "Syndamia" "https://www.syndamia.com"
-sudo ./make-titles.sh /var/www/synd
-sudo ./make-descriptions.sh /var/www/synd
-sudo ./make-file-lists.sh /var/www/synd
-sudo ./make-flags.sh /var/www/synd
+for file in $(find "./generate-hooks" -type f -name "*.sh"); do
+ sudo "$file" /var/www/synd
+done
#
# Tiny version
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
" and "(.+)<\/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 ( 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:
+# Folder Info
+
+# In Markdown you type in something like (without the "# " in front):
+#
+# &&fos
+# Description
+# &&fs0
+# | Data 1 |
+# Data 1.1 |
+# Data 1.2 |
+# &&fs
+# Data 2 |
+# Data 2.1 |
+# Data 2.2 |
+# &&fod
+#
+# And the lines starting with && (I'll call them ftags) get replaced by some HTML. The | 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 ""
+ sed -i 's/^&&fos$//g' "$file"
+ # Replaces "&&fs0" with "
"
+ sed -i 's/^&&fs0$/<\/summary>/g' "$file"
+ # Replaces "&&fs" with "
"
+ sed -i 's/^&&fs$/<\/tr>
/g' "$file"
+ # Replaces "&&fod" with "
"
+ 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 "
"
+ sed -i 's/&&gb/
/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" and "(.+)<\/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
diff --git a/generate.sh b/generate.sh
index 7e9b620..105cde3 100755
--- a/generate.sh
+++ b/generate.sh
@@ -11,10 +11,9 @@ sudo rm -f website/.files
# Generate files
sudo ssg6 src website "Syndamia" "https://www.syndamia.com"
-sudo ./make-titles.sh website
-sudo ./make-descriptions.sh website
-sudo ./make-file-lists.sh website
-sudo ./make-flags.sh website
+for file in $(find "./generate-hooks" -type f -name "*.sh"); do
+ sudo "$file" website
+done
#
# Tiny version
diff --git a/make-descriptions.sh b/make-descriptions.sh
deleted file mode 100755
index 49417f5..0000000
--- a/make-descriptions.sh
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/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" and "(.+)<\/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/make-file-lists.sh b/make-file-lists.sh
deleted file mode 100755
index 3952728..0000000
--- a/make-file-lists.sh
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/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 ( 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:
-# Folder Info
-
-# In Markdown you type in something like (without the "# " in front):
-#
-# &&fos
-# Description
-# &&fs0
-# | Data 1 |
-# Data 1.1 |
-# Data 1.2 |
-# &&fs
-# Data 2 |
-# Data 2.1 |
-# Data 2.2 |
-# &&fod
-#
-# And the lines starting with && (I'll call them ftags) get replaced by some HTML. The | 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 ""
- sed -i 's/^&&fos$//g' "$file"
- # Replaces "&&fs0" with "
"
- sed -i 's/^&&fs0$/<\/summary>/g' "$file"
- # Replaces "&&fs" with "
"
- sed -i 's/^&&fs$/<\/tr>
/g' "$file"
- # Replaces "&&fod" with "
"
- sed -i 's/^&&fod<\/p>$/<\/tr><\/table><\/details>/g' "$file"
-done
diff --git a/make-flags.sh b/make-flags.sh
deleted file mode 100755
index 786671d..0000000
--- a/make-flags.sh
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/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 "
"
- sed -i 's/&&gb/
/g' "$file"
-done
diff --git a/make-titles.sh b/make-titles.sh
deleted file mode 100755
index bf739ff..0000000
--- a/make-titles.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/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" and "(.+)<\/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
--
cgit v1.3.1-26-gb76a