diff options
14 files changed, 26 insertions, 216 deletions
| -rw-r--r-- | .gitmodules | 3 | ||||
| -rw-r--r-- | awk-edits/File-type.awk | 1 | ||||
| -rw-r--r-- | awk-edits/Flags.awk | 1 | ||||
| -rw-r--r-- | awk-edits/Group-contents.awk | 1 | ||||
| -rw-r--r-- | awk-edits/Header-description.awk | 52 | ||||
| -rw-r--r-- | awk-edits/Header-title.awk | 28 | ||||
| -rw-r--r-- | awk-edits/Heading-anchors.awk | 1 | ||||
| -rw-r--r-- | awk-edits/Pagenav.awk | 31 | ||||
| -rw-r--r-- | awk-edits/Presentation.awk | 9 | ||||
| -rw-r--r-- | awk-edits/Svg-height-attrib.awk | 1 | ||||
| -rw-r--r-- | awk-edits/Syntax-highlighting.awk | 1 | ||||
| m--------- | csg | 0 | ||||
| -rwxr-xr-x | generate.sh | 109 | ||||
| -rw-r--r-- | src/_header.html | 4 |
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 <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(getline < ARGV[1]) { - start = index($0, "<h2") - if (start && substr($0, start, 16) != "<h2 id=\"contents") - break; - - if (index($0, "<p>")) - parstar = 4; - if (index($0, "</p>")) - 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, "<h1"); - close(ARGV[1]); # FILENAME isn't set during BEGIN - - # Removes the opening tag - gsub(/<h1[^>]*>/, ""); - # 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, "</h1") - h1Index); -} - -/\[TITLE\]/ { - gsub(/\[TITLE\]/, title); -} diff --git a/awk-edits/Heading-anchors.awk b/awk-edits/Heading-anchors.awk index 29c35fe..e3846f9 100644 --- a/awk-edits/Heading-anchors.awk +++ b/awk-edits/Heading-anchors.awk @@ -1,3 +1,4 @@ +# .*html # # == About == # diff --git a/awk-edits/Pagenav.awk b/awk-edits/Pagenav.awk index 13c3fee..1d523be 100644 --- a/awk-edits/Pagenav.awk +++ b/awk-edits/Pagenav.awk @@ -1,3 +1,4 @@ +# .*(blog|slides|teaching|tutorials|misc)/.*/.*html # # == About == # @@ -13,33 +14,13 @@ # # Split into Pagenav.awk and post-pagenav.awk -BEGIN { - fileCheck = ARGV[1]; # FILENAME isn't available in BEGIN - - elem = ""; - if (match(fileCheck, /(blog|slides|teaching|tutorials|misc)\/.*\//)) { - dateCreate = ""; - dateEdited = ""; - FS = "\t" - while ((getline < "./timestamps.txt") > 0) { - if ($1 == fileCheck) { - dateCreate = $2; - dateEdited = $3; - break; - } - } - FS = " " # gawk only? - - start = index(fileCheck, "website") + 8; - elem = ORS \ +nopagenav == 0 && /<h1/ { + match(FILENAME, /(blog|slides|teaching|tutorials|misc)\/.*\//) + $0 = $0 ORS \ "<div id=\"pagenav\">" ORS \ -" <strong>Created: " dateCreate "</strong> || <strong>Edited: " dateEdited "</strong>" ORS \ -" || <a href=\"https://gitlab.com/Syndamia/syndamiadotcom/-/blob/master/src/" substr(fileCheck, start, length(fileCheck) - start - 3) "md\"><strong>GitLab source</strong></a>" ORS \ +" <strong>Created: " created "</strong> || <strong>Edited: " edited "</strong>" ORS \ +" || <a href=\"https://gitlab.com/Syndamia/syndamiadotcom/-/blob/master/src/" substr(FILENAME, start, length(FILENAME) - start - 3) "md\"><strong>GitLab source</strong></a>" ORS \ "</div>" - } -} -/<h1/ && nopagenav == 0 { - $0 = $0 elem nopagenav = 1 } diff --git a/awk-edits/Presentation.awk b/awk-edits/Presentation.awk index 9fd64e3..4d3826a 100644 --- a/awk-edits/Presentation.awk +++ b/awk-edits/Presentation.awk @@ -1,3 +1,4 @@ +# .*(slides|teaching)/.*html # # == About == # @@ -87,8 +88,6 @@ # Refer to src/talks/demo/index.md BEGIN { - nopresentation=!(substr(ARGV[1], "slides") || substr(ARGV[1], "teaching")) # FILENAME isn't available yet - # names is name of ftag, meaning if `names[i] = "examp"` the ftag will be &&examp # ended specifies how the HTML tag is ended # `ended[i] = 0` means no closing ftag (so no &&/examp) @@ -218,15 +217,15 @@ function presentationSubstitute(ind) { gsub(cpat[ind], crep[ind]) } -nopresentation == 0 && /<code>/ { +/<code>/ { presInsideCode = 1 } -nopresentation == 0 && /<\/code>/ { +/<\/code>/ { presInsideCode = 0 } -nopresentation == 0 && presInsideCode == 0 && /^[ \t]*(<p>)?&&/ { +presInsideCode == 0 && /^[ \t]*(<p>)?&&/ { 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 +Subproject c250a0bbbd443ce0982b3de47d1a2768689ad9e 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 @@ <meta prefix="og: http://ogp.me/ns#" property="og:description" content="[DESCRIPTION]"> <meta prefix="og: http://ogp.me/ns#" property="og:image" content="https://syndamia.com/img/meta-banner.png"> <meta prefix="og: http://ogp.me/ns#" property="og:url" content="https://syndamia.com"> - <title></title> + <title>[TITLE]</title> </head> <body id="content-wrapper" text="black" bgcolor="white" link="#336700" vlink="#336700"> <nav id="sidebar"> @@ -98,7 +98,7 @@ <span class="nocss-aid">||</span><span class="brt"></span> <a href="https://gitlab.com/Syndamia/syndamiadotcom" target="_blank" class="link-tab">Powered with:</a><span class="br"></span> - <a href="https://www.romanzolotarev.com/ssg.html" target="_blank" class="link-tab">ssg by Roman Zolotarev</a><span class="br"></span><span class="nocss-aid">, </span> + <a href="https://gitlab.com/Syndamia/csg" target="_blank" class="link-tab">csg by me</a><span class="br"></span><span class="nocss-aid">, </span> <a href="https://kristaps.bsd.lv/lowdown/" target="_blank" class="link-tab">lowdown by Kristaps Dzonsons</a><span class="br"></span><span class="nocss-aid">, </span> <a href="https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html" target="_blank" class="link-tab">awk</a> and <a href="https://www.gnu.org/software/bash/" target="_blank" class="link-tab">GNU bash</a> |