From daab5443e76fe16642dde1fb2ef32b723fd4037b Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 28 Sep 2022 22:11:47 +0300 Subject: [hooks] Removed bash hook scripts and made awk scripts the way to generate the website --- generate-dev.sh | 25 +++++++------- generate-hooks/README.md | 6 ++-- generate-hooks/create-description.awk | 34 +++++++++++++++---- generate-hooks/create-file-lists.awk | 48 +++++++++++++++++++++++++++ generate-hooks/create-flags.awk | 6 ++++ generate-hooks/create-presentation.awk | 27 +++++++++++++++ generate-hooks/create-title.awk | 27 +++++++++++---- generate-hooks/make-descriptions.sh | 16 --------- generate-hooks/make-file-lists.sh | 60 ---------------------------------- generate-hooks/make-flags.sh | 18 ---------- generate-hooks/make-presentation.sh | 37 --------------------- generate-hooks/make-titles.sh | 16 --------- generate.sh | 7 ++-- 13 files changed, 151 insertions(+), 176 deletions(-) delete mode 100755 generate-hooks/make-descriptions.sh delete mode 100755 generate-hooks/make-file-lists.sh delete mode 100755 generate-hooks/make-flags.sh delete mode 100755 generate-hooks/make-presentation.sh delete mode 100755 generate-hooks/make-titles.sh diff --git a/generate-dev.sh b/generate-dev.sh index 8ed1fb2..ac0b840 100755 --- a/generate-dev.sh +++ b/generate-dev.sh @@ -3,18 +3,21 @@ # Make folder if it doesn't exist if [ ! -d "/var/www/synd" ]; then # User should be www-data (like in generate.sh), but I use Fedora and root is the default one - sudo -u root mkdir /var/www/synd + mkdir /var/www/synd fi # Remove record of previously generated files -sudo rm -f /var/www/synd/.files +rm -f /var/www/synd/.files # Generate files -sudo ssg src /var/www/synd/ "Syndamia" "https://www.syndamia.com" +ssg src /var/www/synd/ "Syndamia" "https://www.syndamia.com" > /dev/null allnormfiles=$(find '/var/www/synd' -type f -name "*.html") -for file in $(find "./generate-hooks" -type f -name "*.sh"); do - sudo "$file" "$allnormfiles" + +for script in $(find "./generate-hooks" -type f -name "*.awk"); do + for file in $allnormfiles; do + awk -f "$script" "$file" > tmp && mv -f tmp "$file" + done done # @@ -23,18 +26,18 @@ done if [ ! -d "/var/www/tiny.synd" ]; then # User should be www-data (like in generate.sh), but I use Fedora and root is the default one - sudo -u root mkdir /var/www/tiny.synd + mkdir /var/www/tiny.synd fi # Just take what is already made, no need to regenerate everything -sudo cp -r /var/www/synd/* /var/www/tiny.synd/ +cp -r /var/www/synd/* /var/www/tiny.synd/ # Remove unnecessary files -sudo rm -f /var/www/tiny.synd/*.css -sudo rm -rf /var/www/tiny.synd/fonts/ -sudo rm -f /var/www/tiny.synd/.files +rm -f /var/www/tiny.synd/*.css +rm -rf /var/www/tiny.synd/fonts/ +rm -f /var/www/tiny.synd/.files # Remove references to stylesheets in all files for file in $(find "/var/www/tiny.synd" -type f -name "*.html"); do - sudo sed -i 's/^.*stylesheet.*//g' $file + sed -i 's/^.*stylesheet.*//g' $file done diff --git a/generate-hooks/README.md b/generate-hooks/README.md index fcb9ba7..52bb4f4 100644 --- a/generate-hooks/README.md +++ b/generate-hooks/README.md @@ -8,8 +8,8 @@ Their purpose is to shorten and abstract certain custom HTML code that I want to |Script|ftags|ftag can be anywhere in text| |---|---|---| -|`make-file-lists.sh`|`&&fos`, `&&fs0`, `&&fs`, `&&fod`|No| -|`make-flags.sh`|`&&gb`|Yes| -|`make-presentation.sh`|`&&slide`, `&&/slide`, `&&flexer`, `&¢ered`, `&&/centered`, `&&fow`, `&&/fow`, `&&fol`, `&&/fol`, `&&font18`, `&&font20`, `&&font27`, `&&font30`, `&&font35`, `&&/font`|No| +|`make-file-lists.awk`|`&&fos`, `&&fs0`, `&&fs`, `&&fod`|No| +|`make-flags.awk`|`&&gb`|Yes| +|`make-presentation.awk`|`&&slide`, `&&/slide`, `&&flexer`, `&¢ered`, `&&/centered`, `&&fow`, `&&/fow`, `&&fol`, `&&/fol`, `&&font18`, `&&font20`, `&&font27`, `&&font30`, `&&font35`, `&&/font`|No| For more information on how to use the different ftags, consult the specified script. diff --git a/generate-hooks/create-description.awk b/generate-hooks/create-description.awk index b4fac0e..ec0bace 100644 --- a/generate-hooks/create-description.awk +++ b/generate-hooks/create-description.awk @@ -1,18 +1,38 @@ -/p>.*/ { +# For every page, the description meta tag is "[DESCRIPTION]", with this we +# generate it. At most, the first 200 characters from all paragraphs are taken. + +function appToDesc(l) { # Removes tags and bad characters - gsub(/<[^>]*>/, "") ; gsub(/[^a-zA-Z0-9 ]/, "") + gsub(/<[^>]*>/, "", l) ; gsub("’", "'", l) ; gsub(/[^a-zA-Z0-9 '.]/, "", l) # Trims leading and trailing spaces and tabs (if any) - gsub(/^[ \t]*/, "") ; gsub(/[ \t]*$/, "") + gsub(/^[ \t]*/, "", l) ; gsub(/[ \t]*$/, "", l) # Concatenates the current record to variable and shortens it, # when it gets too long - desc = desc $0 + desc = desc l if (length(desc) >= 200) { desc = substr(desc, 1, 197) "..." - exit + 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) } -END { - print desc +{ + print } diff --git a/generate-hooks/create-file-lists.awk b/generate-hooks/create-file-lists.awk index c94ad71..4a0f2f6 100644 --- a/generate-hooks/create-file-lists.awk +++ b/generate-hooks/create-file-lists.awk @@ -1,3 +1,51 @@ +# This is a really rudementary way to make making file lists less HTML-y +# I made it so: +# 1) You don't have to write quite as much HTML +# 2) The Data columns for each file get to be formatted as Markdown ( is not recognized as a block-level element, so the stuff inside get formatted https://kristaps.bsd.lv/lowdown/lowdown.5.html#HTML_Blocks) + +# Very roughly, each file list has either this: +#
Folder Info File Data
+# or this: +# File Data
+# structure, the difference being that in the first, all of the files are in a folder. + +# In Markdown you type in something like (without the "# " in front): +# +# &&fos +# Description +# &&fs0 +# Data 1 +# Data 1.1 +# Data 1.2 +# &&fs +# Data 2 +# Data 2.1 +# Data 2.2 +# &&fod +# +# or +# +# &&nos +# Data 1 +# Data 1.1 +# Data 1.2 +# &&fs +# Data 2 +# Data 2.1 +# Data 2.2 +# &&nod + +# +# And the lines starting with && (I'll call them ftags) get replaced by some HTML. The around each file Data is mandatory. +# &&fs0 must only be used on before the very first file data, when files are in a folder. There must be no empty lines, lines mustn't start with spaces, there mustn't be anything around ftags and ftags have to be on their own lines. +# The commands have fairly intuitive abbreviations: +# &&nos no folder start (start file list, without making a folder) +# &&fos folder start +# &&fs0 file start of first file in folder (must only be used when items are in a folder!) +# &&fs file start +# &&nod no folder end (end file list, without having made a folder) +# &&fod folder end + { gsub(/&&nos/, "") gsub(/^

&&fos$/, "

") diff --git a/generate-hooks/create-flags.awk b/generate-hooks/create-flags.awk index 1917798..ad8e1b2 100644 --- a/generate-hooks/create-flags.awk +++ b/generate-hooks/create-flags.awk @@ -1,3 +1,9 @@ +# Adds a way to more simply insert flags into text +# Each flag is represented with an ftag (text that is preceded by &&) + +# Available flags: +# Great Britain - &&gb + BEGIN { flag[1] = "gb" title[1] = "ENG" diff --git a/generate-hooks/create-presentation.awk b/generate-hooks/create-presentation.awk index 04fb6d0..0f32e35 100644 --- a/generate-hooks/create-presentation.awk +++ b/generate-hooks/create-presentation.awk @@ -1,4 +1,31 @@ +# A presentation is just a markdown file, with some added ftags for formatting into a presentation layout. +# This means all presentations will change how they look with changes to the main styles.css. It also means +# that they follow the light/dark mode setting. +# Each slide is the size of a horizontal A4 piece of paper. This makes it easy to print (and there is a dedicated +# print button). +# The whole system is based on flexboxes. The only real way to control how items are aligned is via a row and column +# directed flexboxes. This isn't the most efficient, but it's fine. And if there are performance issues, the +# presentation can always be "printed" to a PDF and consumed that way. + +# Currently you can have normal paragraphs and heading around a presentation, and those won't be printed out. +# But you can have only ONE presentation per page!!! +# All ftags that have a closing tag, and &&presentation, need one line above and below them (but you don't +# need the first and last line of file to be empty). + +# &&presentation Required. Adds the control panel and JavaScript script. Must be the very first one! +# &&slide Starts a slide. Slides are the main pages that hold content and are used for navigation. +# &&/slide Ends (the last started) slide. +# &&flexer An empty container with flex: 1. Use it for spacing out stuff. +# &¢ered Aligns text to the center. +# &&/centered Ends (the last started) centered text. +# &&fow Flexbox, with flex-direction row. +# &&/fow Ends (the last started) fow. +# &&fol Flexbox, with flex-direction column. +# &&/fol Ends (the last started) fol. + BEGIN { + if (substr(FILENAME, "talks") == 0) exit + names[ 1] = "slide" ended[ 1] = 1 names[ 2] = "centered" diff --git a/generate-hooks/create-title.awk b/generate-hooks/create-title.awk index 14d8ec6..f1eaa4f 100644 --- a/generate-hooks/create-title.awk +++ b/generate-hooks/create-title.awk @@ -1,7 +1,22 @@ -/

.+/ { - # Takes everything between

and

in the first - #

occurence. - h = index($0, "

") - print substr($0, h, index($0, "]*>/, "") + title = substr($0, h1Index, index($0, " is not recognized as a block-level element, so the stuff inside get formatted https://kristaps.bsd.lv/lowdown/lowdown.5.html#HTML_Blocks) - -# Very roughly, each file list has either this: -#
Folder Info

File Data
-# or this: -# File Data
-# structure, the difference being that in the first, all of the files are in a folder. - -# In Markdown you type in something like (without the "# " in front): -# -# &&fos -# Description -# &&fs0 -# Data 1 -# Data 1.1 -# Data 1.2 -# &&fs -# Data 2 -# Data 2.1 -# Data 2.2 -# &&fod -# -# or -# -# &&nos -# Data 1 -# Data 1.1 -# Data 1.2 -# &&fs -# Data 2 -# Data 2.1 -# Data 2.2 -# &&nod - -# -# And the lines starting with && (I'll call them ftags) get replaced by some HTML. The around each file Data is mandatory. -# &&fs0 must only be used on before the very first file data, when files are in a folder. There must be no empty lines, lines mustn't start with spaces, there mustn't be anything around ftags and ftags have to be on their own lines. -# The commands have fairly intuitive abbreviations: -# &&nos no folder start (start file list, without making a folder) -# &&fos folder start -# &&fs0 file start of first file in folder (must only be used when items are in a folder!) -# &&fs file start -# &&nod no folder end (end file list, without having made a folder) -# &&fod folder end - -if [ -z "$1" ]; then - echo First parameter must be string with file paths - exit -fi - -awkloc="$(dirname "$0")/create-file-lists.awk" - -for file in $1; do - awk -f "$awkloc" $file > tmp && mv -f tmp $file -done diff --git a/generate-hooks/make-flags.sh b/generate-hooks/make-flags.sh deleted file mode 100755 index 84adfaf..0000000 --- a/generate-hooks/make-flags.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -# Adds a way to more simply insert flags into text -# Each flag is represented with an ftag (text that is preceded by &&) - -# Available flags: -# Great Britain - &&gb - -if [ -z "$1" ]; then - echo First parameter must be string with file paths - exit -fi - -awkloc="$(dirname "$0")/create-flags.awk" - -for file in $1; do - awk -f "$awkloc" $file > tmp && mv -f tmp $file -done diff --git a/generate-hooks/make-presentation.sh b/generate-hooks/make-presentation.sh deleted file mode 100755 index c27fba2..0000000 --- a/generate-hooks/make-presentation.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -# A presentation is just a markdown file, with some added ftags for formatting into a presentation layout. -# This means all presentations will change how they look with changes to the main styles.css. It also means -# that they follow the light/dark mode setting. -# Each slide is the size of a horizontal A4 piece of paper. This makes it easy to print (and there is a dedicated -# print button). -# The whole system is based on flexboxes. The only real way to control how items are aligned is via a row and column -# directed flexboxes. This isn't the most efficient, but it's fine. And if there are performance issues, the -# presentation can always be "printed" to a PDF and consumed that way. - -# Currently you can have normal paragraphs and heading around a presentation, and those won't be printed out. -# But you can have only ONE presentation per page!!! -# All ftags that have a closing tag, and &&presentation, need one line above and below them (but you don't -# need the first and last line of file to be empty). - -# &&presentation Required. Adds the control panel and JavaScript script. Must be the very first one! -# &&slide Starts a slide. Slides are the main pages that hold content and are used for navigation. -# &&/slide Ends (the last started) slide. -# &&flexer An empty container with flex: 1. Use it for spacing out stuff. -# &¢ered Aligns text to the center. -# &&/centered Ends (the last started) centered text. -# &&fow Flexbox, with flex-direction row. -# &&/fow Ends (the last started) fow. -# &&fol Flexbox, with flex-direction column. -# &&/fol Ends (the last started) fol. - -if [ -z "$1" ]; then - echo First parameter must be string with file paths - exit -fi - -awkloc="$(dirname "$0")/create-presentation.awk" - -for file in $(echo $1 | grep 'talks'); do - awk -f "$awkloc" $file > tmp && mv -f tmp $file -done diff --git a/generate-hooks/make-titles.sh b/generate-hooks/make-titles.sh deleted file mode 100755 index 4bb70b9..0000000 --- a/generate-hooks/make-titles.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -if [ -z "$1" ]; then - echo First parameter must be string with file paths - exit -fi - -awkloc="$(dirname "$0")/create-title.awk" - -# Loop through all HTML files in given directory -for file in $1; do - title=$(awk -f "$awkloc" $file) - - # Replace all "[TITLE]" text in current file with title - sed -i "s/\[TITLE\]/$title/g" $file -done diff --git a/generate.sh b/generate.sh index b4535f5..99c1d4b 100755 --- a/generate.sh +++ b/generate.sh @@ -14,8 +14,11 @@ rm -f website/.files ssg src website "Syndamia" "https://syndamia.com" allnormfiles=$(find './website' -type f -name "*.html") -for file in $(find "./generate-hooks" -type f -name "*.sh"); do - "$file" "$allnormfiles" + +for script in $(find "./generate-hooks" -type f -name "*.awk"); do + for file in $allnormfiles; do + awk -f "$script" "$file" > tmp && mv -f tmp "$file" + done done # -- cgit v1.3.1-26-gb76a