From 0187e255a811bebb0dad3624f2c6d78b829d15c5 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 17 Jan 2023 16:15:28 +0200 Subject: [awk] Reworked generation to happen via a combined script, updated scripts and added info in scripts readme --- awk-edits/Header-description.awk | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 awk-edits/Header-description.awk (limited to 'awk-edits/Header-description.awk') diff --git a/awk-edits/Header-description.awk b/awk-edits/Header-description.awk new file mode 100644 index 0000000..028c14c --- /dev/null +++ b/awk-edits/Header-description.awk @@ -0,0 +1,36 @@ +# +# == About == +# +# Every page has a description and og:description meta tags. These descriptions +# are generated from the paragraphs, inside the given page. +# The value for those meta tags is "[DESCRIPTION]" and it gets replaced with +# either all of the text on the page, or only the first 200 characters. + +function appToDesc(l) { + gsub(/<[^>]*>/, "", l) ; gsub("’", "'", l) + gsub(/[^a-zA-Z0-9 '.]/, "", l) + gsub(/^[ \t]*/, "", l) ; gsub(/[ \t]*$/, "", l) + + desc = desc l + if (length(desc) >= 200) { + desc = substr(desc, 1, 197) "..." + return 1 + } + return 0 +} + +BEGIN { + stop = 0 + + # Loop over the whole file, extract all text in first couple of paragraphs, + # store it in desc (but no more than 200 characters will be saved) + while(stop == 0 && getline < ARGV[1]) { + if (index($0, " 0) + stop = appToDesc($0) + } + close(ARGV[1]) # FILENAME isn't set during BEGIN +} + +"\\[DESCRIPTION\\]" { + gsub("\\[DESCRIPTION\\]", desc) +} -- cgit v1.3.1-26-gb76a