From 3552c3e6cb666ac3f063652862e3b287cd30c904 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 23 Oct 2023 15:34:14 +0300 Subject: [generate] Reworked to use csg, updated awk scripts with csg in mind and updated info in _header --- .gitmodules | 3 ++ awk-edits/File-type.awk | 1 + awk-edits/Flags.awk | 1 + awk-edits/Group-contents.awk | 1 + awk-edits/Header-description.awk | 52 ------------------ awk-edits/Header-title.awk | 28 ---------- awk-edits/Heading-anchors.awk | 1 + awk-edits/Pagenav.awk | 31 +++-------- awk-edits/Presentation.awk | 9 ++-- awk-edits/Svg-height-attrib.awk | 1 + awk-edits/Syntax-highlighting.awk | 1 + csg | 1 + generate.sh | 109 ++------------------------------------ src/_header.html | 4 +- 14 files changed, 27 insertions(+), 216 deletions(-) create mode 100644 .gitmodules delete mode 100644 awk-edits/Header-description.awk delete mode 100644 awk-edits/Header-title.awk create mode 160000 csg diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c54d06b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "csg"] + path = csg + url = git@gitlab.com:Syndamia/csg.git diff --git a/awk-edits/File-type.awk b/awk-edits/File-type.awk index f283fa0..32e22b9 100644 --- a/awk-edits/File-type.awk +++ b/awk-edits/File-type.awk @@ -1,3 +1,4 @@ +# .*(misc|preserved).*html # # == About == # diff --git a/awk-edits/Flags.awk b/awk-edits/Flags.awk index 719d82c..aad1343 100644 --- a/awk-edits/Flags.awk +++ b/awk-edits/Flags.awk @@ -1,3 +1,4 @@ +# .*html # # == About == # diff --git a/awk-edits/Group-contents.awk b/awk-edits/Group-contents.awk index 7f930b6..43fa460 100644 --- a/awk-edits/Group-contents.awk +++ b/awk-edits/Group-contents.awk @@ -1,3 +1,4 @@ +# .*(blog|slides|teaching|tutorials|misc)/.*/.*html # # == About == # diff --git a/awk-edits/Header-description.awk b/awk-edits/Header-description.awk deleted file mode 100644 index f7c6ff4..0000000 --- a/awk-edits/Header-description.awk +++ /dev/null @@ -1,52 +0,0 @@ -# -# == About == -# -# Every page has a description and og:description meta tags. These descriptions are -# generated from the text inside paragraphs of the current 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) { - l = substr(l, parstar, length(l) - parstar + 1 - parend); - gsub("<[^>]*>", "", l); gsub("’", "'", l); gsub(/&[^;]*;/, "", l); - - if (desc == "") desc = l; - else desc = desc " " l; - - if (length(desc) >= 200) { - desc = substr(desc, 1, 197) "..."; - return 1; - } - return 0; -} - -BEGIN { - parcont = 0; # continue, we have found a

but not a

- parstar = 1; # we found a

- parends = 0; # we found a

- - # 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(getline < ARGV[1]) { - start = index($0, "")) - parstar = 4; - if (index($0, "

")) - parends = 3; - - if (parcont || parstar == 4) { - if (appToDesc($0)) break; - parcont = parends == 0; - parstar = 1; - parends = 0; - } - } - close(ARGV[1]); # FILENAME isn't set during BEGIN -} - -/\[DESCRIPTION\]/ { - sub(/\[DESCRIPTION\]/, desc); -} diff --git a/awk-edits/Header-title.awk b/awk-edits/Header-title.awk deleted file mode 100644 index 42fafa7..0000000 --- a/awk-edits/Header-title.awk +++ /dev/null @@ -1,28 +0,0 @@ -# -# == 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, "]*>/, ""); - # Remove all HTML character codes, since they're in the form "&...;" and the & - # will be treated as the character for replacement in gsub - gsub(/&[^;]*;/, ""); - title = substr($0, h1Index, index($0, " 0) { - if ($1 == fileCheck) { - dateCreate = $2; - dateEdited = $3; - break; - } - } - FS = " " # gawk only? - - start = index(fileCheck, "website") + 8; - elem = ORS \ +nopagenav == 0 && /

" ORS \ -" Created: " dateCreate " || Edited: " dateEdited "" ORS \ -" || GitLab source" ORS \ +" Created: " created " || Edited: " edited "" ORS \ +" || GitLab source" ORS \ "" - } -} -/

/ { +// { presInsideCode = 1 } -nopresentation == 0 && /<\/code>/ { +/<\/code>/ { presInsideCode = 0 } -nopresentation == 0 && presInsideCode == 0 && /^[ \t]*(

)?&&/ { +presInsideCode == 0 && /^[ \t]*(

)?&&/ { for (i = 1; i <= nameslength; i++) { if (index($0, names[i]) != 0) presentationSubstitute(i) diff --git a/awk-edits/Svg-height-attrib.awk b/awk-edits/Svg-height-attrib.awk index e6dc07f..9e49769 100644 --- a/awk-edits/Svg-height-attrib.awk +++ b/awk-edits/Svg-height-attrib.awk @@ -1,3 +1,4 @@ +# .*html # # == About # diff --git a/awk-edits/Syntax-highlighting.awk b/awk-edits/Syntax-highlighting.awk index 08589cf..577ecb3 100644 --- a/awk-edits/Syntax-highlighting.awk +++ b/awk-edits/Syntax-highlighting.awk @@ -1,3 +1,4 @@ +# .*(blog|slides|teaching|tutorials|misc)/.*/.*html # # == About == # diff --git a/csg b/csg new file mode 160000 index 0000000..c250a0b --- /dev/null +++ b/csg @@ -0,0 +1 @@ +Subproject commit c250a0bbbd443ce0982b3de47d1a2768689ad9e5 diff --git a/generate.sh b/generate.sh index b3ef0dd..3da2c1e 100755 --- a/generate.sh +++ b/generate.sh @@ -3,115 +3,17 @@ : ${REPO_FOLDER:=.} : ${GEN_FOLDER:=./website} : ${GEN_TINY_FOLDER:=./website.tiny} -: ${AWK_FILE:=/tmp/syndamiadotcom-awk} +: ${AWK_FOLDER:=./awk-edits} -# 0. Helper functions {{{ - dur=0 - startTimer() { - dur="$(date +%s%N)" - } - - endTimer() { - dur="$(echo "scale=4 ; ($(date +%s%N) - $dur) / 1000000000 - ${2:-0}" | bc -l)" - printf "%.3fs $1\n" $dur - } -# }}} -# 0.5 Fix hardlinks {{{ - startTimer - for folder in $(find "$REPO_FOLDER/src" -maxdepth 1 -type d); do - if [ -f "$folder.md" ] && [ ! "$folder.md" -ef "$folder/index.md" ]; then - rm "$folder/index.md" >/dev/null 2>&1 - ln "$folder.md" "$folder/index.md" - fi - done - endTimer "[Stage 0.5] Fixed folder/index.md hardlinks" -# }}} # 1. Markdown source to HTML {{{ [ $# -eq 0 -a "$(id -u -n)" != "www-data" ] && echo "[Warning] Running in \"production\" by a user that isn't www-root!" [ ! -d "$GEN_FOLDER" ] && mkdir "$GEN_FOLDER" [ $# -eq 0 -a "$(stat -c %U "$GEN_FOLDER")" != "www-data" ] && echo "[Warning] Running in \"production\" while $GEN_FOLDER isn't owned by www-data!" - # Remove record of previously generated files - rm -rf "$GEN_FOLDER" - mkdir "$GEN_FOLDER" - startTimer - ssg "$REPO_FOLDER/src" "$GEN_FOLDER" "Syndamia" "https://syndamia.com" >/dev/null 2>&1 - endTimer "[Stage 1] Converted Markdown to HTML" + /usr/bin/env dash ./csg/csg "$REPO_FOLDER/src" "$GEN_FOLDER" '& \\— Syndamia' 'https://syndamia.com' "$AWK_FOLDER" # }}} -# 1.5 Custom logic - timestamps.txt {{{ - headc=$(git rev-parse HEAD) - if [ ! -f 'timestamps.txt' ] || [ "$headc" != "$(head -1 timestamps.txt)" ]; then - echo "$headc" > timestamps.txt - - startTimer - for file in $(find "$REPO_FOLDER/src" -type f -regex '.*src/[^/]*/[^/]*/.*md'); do - dates=($(git log --follow --pretty=format:%ad --date="format:%d %B %Y" -- $file)) - line="./website${file:5:-2}html\t${dates[@]: -3:3}\t${dates[@]:0:3}" - echo -e $line >> timestamps.txt - done - endTimer "[Stage 1.5] Recreated timestamps.txt" - fi -# }}} -# 2. Editing HTML files with AWK {{{ - createAWKscript() { - # "librarires" - find "$REPO_FOLDER/awk-edits" -type f -name "#*.awk" -exec cat {} + > "$AWK_FILE" - # Scripts - find "$REPO_FOLDER/awk-edits" -type f -name "[A-Z]*.awk" -exec cat {} + >> "$AWK_FILE" - echo '{if ($0 != 0) print}' >> "$AWK_FILE" - } - # $1 - $libs, for devs - runAWKscript() { - [ -z "$1" ] && params="-f $AWK_FILE" \ - || params="$1 -f $AWK_FILE -f /tmp/awk-print $postfile" - for file in $(find "$GEN_FOLDER" -type f -name "*.html"); do - awk --posix $params "$file" > tmp && mv -f tmp "$file" - done - } - - if [ $# -eq 0 ]; then # Run in "production" - createAWKscript - startTimer - runAWKscript - endTimer "[Stage 2] Ran $AWK_FILE" - - - elif [ "$1" == 'dev' ]; then - startTimer - createAWKscript - endTimer "[Stage 2] Created $AWK_FILE" - startTimer - runAWKscript - endTimer "[Stage 2] Ran $AWK_FILE" - - - elif [ "$1" == 'devs' ]; then - echo '{if ($0 != 0) print}' > /tmp/awk-print - libs="" - for l in $(find "$REPO_FOLDER/awk-edits" -type f -name "#*.awk"); do - libs+=" -f $l " - done - - # We only care about how long the script itself was executed, without the time it takes to - # open and close every file, this way we'll subtract this delay - AWK_FILE="$REPO_FOLDER/awk-edits/empty" - startTimer - runAWKscript "$libs" - fileOpenOffset="$(endTimer "[Stage 2] Subtracted time for file open/close")" - printf "$fileOpenOffset\n" - fileOpenOffset="${fileOpenOffset:0:5}" - - for i in $(find "$REPO_FOLDER/awk-edits" -type f -name "[A-Z]*.awk"); do - AWK_FILE="$i" - - startTimer - runAWKscript "$libs" - endTimer "[Stage 2] Ran $i" "$fileOpenOffset" - done - fi -# }}} -# 3. Tiny version, strip away styles and other stuff {{{ +# 2. Tiny version, strip away styles and other stuff {{{ [ ! -d "$GEN_TINY_FOLDER" ] && mkdir "$GEN_TINY_FOLDER" [ $# -eq 0 -a "$(stat -c %U "$GEN_TINY_FOLDER")" != "www-data" ] && echo "[Warning] Running in \"production\" while $GEN_TINY_FOLDER isn't owned by www-data!" @@ -133,13 +35,12 @@ done } + echo "[Stage 3] Tiny website" if [ $# -eq 0 ]; then improveForTINY else - startTimer - improveForTINY - endTimer "[Stage 3] Tiny website improvements" + improveForTINY fi # }}} diff --git a/src/_header.html b/src/_header.html index 02db9ad..6963c12 100644 --- a/src/_header.html +++ b/src/_header.html @@ -21,7 +21,7 @@ - + [TITLE]