Summary Files Commits Branches @commit @diff @stats
path: root / md-meta.awk
diff options
context:
space:
mode:
Commit03a882950ead37f74ab4953dbd1199ddbc3d7f6c (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-01-01 15:50:49 +0200
Committer
 Syndamia <kamen@syndamia.com>
2025-01-01 15:50:49 +0200
Files3d47af86ba6694ae60867d308368b932d8b29596 /md-meta.awk
csg-03a882950ead37f74ab4953dbd1199ddbc3d7f6c.tar
csg-03a882950ead37f74ab4953dbd1199ddbc3d7f6c.tar.gz
csg-03a882950ead37f74ab4953dbd1199ddbc3d7f6c.zip
Parent7f30e62573396b85eb9558faaf943d76ec4750ab (diff)
chore: Rename and reorganize files
1 files changed, 60 insertions, 0 deletions
-rw-r--r--md-meta.awk60
diff --git a/md-meta.awk b/md-meta.awk
new file mode 100644
index 0000000..fea34c3
--- /dev/null
+++ b/md-meta.awk
@@ -0,0 +1,60 @@
+# No character classes, since they aren't supported on every system
+function emit(ind, val) {
+ print "meta[\"" FILENAME "\", \"" ind "\"]=\"" val "\""
+}
+function erit(id, href, title) {
+ print "reference[\"" id "\", \"href\"]=\"" href "\""
+ print "reference[\"" id "\", \"title\"]=\"\\\"" title "\\\"\""
+}
+
+title != "" && stopdesc == 0 && /^[A-Za-z]/ {
+ startedGathering = 1
+ # Take only anchor text
+ gsub(/\]\([^)]*\)/, "")
+ gsub(/\[/, "")
+ # Append line
+ if (desc == "") desc = $0
+ else desc = desc " " $0
+ # Trim line to 200 characters
+ if (length(desc) > 200) {
+ desc = substr(desc, 1, 197) "..."
+ stopdesc = 1
+ }
+}
+stopdesc == 0 && startedGathering == 1 && /^[ \t]*$/ { stopdesc = 1 }
+
+{
+ words += NF
+}
+
+title == "" && /^# / {
+ sub(/^#[ \t]*/, "")
+ sub(/[ \t#]*$/, "")
+ # sub(/.*/, titlef)
+ title = $0
+}
+
+/^\[[^^].*\]:/ {
+ match($0, /^\[.+\]:/)
+ id = substr($0, 2, RLENGTH - 3)
+
+ href = substr($0, RLENGTH + 1)
+ reftitle = ""
+ if (match(href, /[ \t]+["'(].*[)'"]$/)) {
+ reftitle = substr(href, RSTART)
+ href = substr(href, 1, RSTART - 1)
+
+ sub(/^[ \t]["'(]*/, "", reftitle)
+ sub(/[)'"][ \t]*$/, "", reftitle)
+ }
+ sub(/^[ \t]*<?/, "", href)
+ sub(/>?[ \t]*$/, "", href)
+
+ erit(id, href, reftitle)
+}
+
+END {
+ emit("title", title)
+ emit("description", desc)
+ emit("words", words)
+}