Summary Files Commits Branches @commit @diff @stats
path: root / generate-hooks / create-title.awk
diff options
context:
space:
mode:
Commitdaab5443e76fe16642dde1fb2ef32b723fd4037b (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-09-28 22:11:47 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-09-29 17:40:10 +0300
Filesa952b79a3d8ed6e3d01cc33a432248eb41e4fdfd /generate-hooks/create-title.awk
syndamia.com-daab5443e76fe16642dde1fb2ef32b723fd4037b.tar
syndamia.com-daab5443e76fe16642dde1fb2ef32b723fd4037b.tar.gz
syndamia.com-daab5443e76fe16642dde1fb2ef32b723fd4037b.zip
Parent15094c5da196d0b23f41c6882a397284b2741ab0 (diff)
[hooks] Removed bash hook scripts and made awk scripts the way to generate the website
1 files changed, 21 insertions, 6 deletions
-rw-r--r--generate-hooks/create-title.awk27
diff --git a/generate-hooks/create-title.awk b/generate-hooks/create-title.awk
index 14d8ec6..f1eaa4f 100644
--- a/generate-hooks/create-title.awk
+++ b/generate-hooks/create-title.awk
@@ -1,7 +1,22 @@
-/<h1>.+/ {
- # Takes everything between <h1> and </h1> in the first
- # <h1> occurence.
- h = index($0, "<h1>")
- print substr($0, h, index($0, "</h1") - h)
- exit
+BEGIN {
+ h1Index = 0
+
+ # When this loop finishes, $0 will have the first line containing an h1 header
+ # tag, and h1Index will have it's starting position
+ while (h1Index == 0 && getline < ARGV[1])
+ h1Index = index($0, "<h1")
+ close(ARGV[1]) # FILENAME isn't set during BEGIN
+
+ # Removes the opening tag and substrings everything that is normally
+ # inside the heading tag
+ gsub(/<h1[^>]*>/, "")
+ title = substr($0, h1Index, index($0, "</h1") - h1Index)
+}
+
+"\\[TITLE\\]" {
+ gsub("\\[TITLE\\]", title)
+}
+
+{
+ print
}