Summary Files Commits Branches @commit @diff @stats
path: root / make-descriptions.sh
diff options
context:
space:
mode:
Commit0bde2265b87c23f8c261c9b313cf657e93a57c93 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-06-18 15:42:42 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-06-18 15:42:42 +0300
Files5c9e1ef7bae21d478db4c29e63de18c63fd326e1 /make-descriptions.sh
syndamia.com-0bde2265b87c23f8c261c9b313cf657e93a57c93.tar
syndamia.com-0bde2265b87c23f8c261c9b313cf657e93a57c93.tar.gz
syndamia.com-0bde2265b87c23f8c261c9b313cf657e93a57c93.zip
Parent01de1741204ff86d989e1a61764a6ee15d795103 (diff)
Created a script that generates the head element descriptions
1 files changed, 24 insertions, 0 deletions
-rwxr-xr-xmake-descriptions.sh24
diff --git a/make-descriptions.sh b/make-descriptions.sh
new file mode 100755
index 0000000..44fcdcf
--- /dev/null
+++ b/make-descriptions.sh
@@ -0,0 +1,24 @@
+#!/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</p" from current file
+ # remove the "p>" and "</p" from result
+ # make lines that start with "<" blank
+ # take all lines that aren't blank
+ description=$(egrep -o "p>(.+)<\/p" $file | sed "s/p>\|<\/p//g" | sed "s/^<.*//g" | grep .)
+
+ # Get the first 200 characters
+ description=${description::200}
+
+ # 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