Summary Files Commits Branches @commit @diff @stats
path: root / make-titles.sh
diff options
context:
space:
mode:
Commit88bad42c3fc7a9c847f0cfcf5fd4a5355772b90b (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-06-18 16:12:00 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-06-18 16:12:00 +0300
Filesdf15f4d5278f261c8a254fd7e59d4a9e9070127f /make-titles.sh
syndamia.com-88bad42c3fc7a9c847f0cfcf5fd4a5355772b90b.tar
syndamia.com-88bad42c3fc7a9c847f0cfcf5fd4a5355772b90b.tar.gz
syndamia.com-88bad42c3fc7a9c847f0cfcf5fd4a5355772b90b.zip
Parentaf63dfd8b83e10ba9022069c1ac2d9898a5dec7c (diff)
Added a script for generating head element titles
1 files changed, 19 insertions, 0 deletions
-rwxr-xr-xmake-titles.sh19
diff --git a/make-titles.sh b/make-titles.sh
new file mode 100755
index 0000000..bf739ff
--- /dev/null
+++ b/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</h1" from current file
+ # remove the "h1>" and "</h1" from result
+ title=$(egrep -o "h1(.+)>(.+)<\/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