Summary Files Commits Branches @commit @diff @stats
path: root / awk-edits / Header-description.awk
diff options
context:
space:
mode:
Commitb2c316691aba4000438e26be569870c115bdc0d7 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-09-10 18:57:47 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-09-10 18:57:47 +0300
Files60423233b82b92e9f24db493cf8d5d6a7f3b5340 /awk-edits/Header-description.awk
syndamia.com-b2c316691aba4000438e26be569870c115bdc0d7.tar
syndamia.com-b2c316691aba4000438e26be569870c115bdc0d7.tar.gz
syndamia.com-b2c316691aba4000438e26be569870c115bdc0d7.zip
Parent7ba9878374ab089ac73c4076f9d15ba697d4d515 (diff)
[Header-description] Improved efficiency and capability of paragraph searching
1 files changed, 29 insertions, 14 deletions
-rw-r--r--awk-edits/Header-description.awk43
diff --git a/awk-edits/Header-description.awk b/awk-edits/Header-description.awk
index bb245c6..645a1ac 100644
--- a/awk-edits/Header-description.awk
+++ b/awk-edits/Header-description.awk
@@ -7,30 +7,45 @@
# either all of the text on the page, or only the first 200 characters.
function appToDesc(l) {
- gsub(/<[^>]*>/, "", l) ; gsub("&#8217;", "'", l)
- gsub(/[^а-яА-Яa-zA-Z0-9 '.]/, "", l)
- gsub(/^[ \t]*/, "", l) ; gsub(/[ \t]*$/, "", l)
+ l = substr(l, parstar, length(l) - parstar + 1 - parend);
+ gsub("<[^>]*>", "", l); gsub("&#8217;", "'", l); gsub(/&[^;]*;/, "", l);
+
+ if (desc == "") desc = l;
+ else desc = desc " " l;
- desc = desc l
if (length(desc) >= 200) {
- desc = substr(desc, 1, 197) "..."
- return 1
+ desc = substr(desc, 1, 197) "...";
+ return 1;
}
- return 0
+ return 0;
}
BEGIN {
- stop = 0
+ parcont = 0; # continue, we have found a <p> but not a </p>
+ parstar = 1; # we found a <p>
+ parends = 0; # we found a </p>
# 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, "<p") > 0)
- stop = appToDesc($0)
+ while(getline < ARGV[1]) {
+ if (match($0, /<h[23456]/) && substr($0, RSTART, 17) != "<h2 id=\"contents\"")
+ break;
+
+ if (match($0, /^<p>/))
+ parstar = 4;
+ if (match($0, /<\/p>$/))
+ parends = 3;
+
+ if (parcont || parstar == 4) {
+ if (appToDesc($0)) break;
+ parcont = RSTART == 0;
+ parstar = 1;
+ parends = 0;
+ }
}
- close(ARGV[1]) # FILENAME isn't set during BEGIN
+ close(ARGV[1]); # FILENAME isn't set during BEGIN
}
-"\\[DESCRIPTION\\]" {
- gsub("\\[DESCRIPTION\\]", desc)
+/\[DESCRIPTION\]/ {
+ sub(/\[DESCRIPTION\]/, desc);
}