Summary Files Commits Branches @commit @diff @stats
path: root / awk-edits / Header-title.awk
diff options
context:
space:
mode:
Commitaf9e4cc59e90585f2f5309a6d160949cfd5b2fa3 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-01-24 12:09:41 +0200
Committer
 Syndamia <kamen@syndamia.com>
2023-01-24 12:09:41 +0200
Files8f33491afc04388176c341dc460057b1ca5e9ca8 /awk-edits/Header-title.awk
syndamia.com-af9e4cc59e90585f2f5309a6d160949cfd5b2fa3.tar
syndamia.com-af9e4cc59e90585f2f5309a6d160949cfd5b2fa3.tar.gz
syndamia.com-af9e4cc59e90585f2f5309a6d160949cfd5b2fa3.zip
Parentb583530159235b087fa6d68a74373ae915edb065 (diff)
[Header-title] Renamed to Header-title
1 files changed, 26 insertions, 0 deletions
-rw-r--r--awk-edits/Header-title.awk26
diff --git a/awk-edits/Header-title.awk b/awk-edits/Header-title.awk
new file mode 100644
index 0000000..16247e8
--- /dev/null
+++ b/awk-edits/Header-title.awk
@@ -0,0 +1,26 @@
+#
+# == About ==
+#
+# Every page has a og:title meta tag, which has to be generated from the page
+# itself. The title tag is automatically filled in by ssg.
+# The value for the meta tag is "[TITLE]" and it gets replaced with all text
+# inside first h1 header tag.
+
+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)
+}