diff options
| Commit | daab5443e76fe16642dde1fb2ef32b723fd4037b (patch) | |
|---|---|---|
| Author | 2022-09-28 22:11:47 +0300 | |
| Committer | 2022-09-29 17:40:10 +0300 | |
| Files | a952b79a3d8ed6e3d01cc33a432248eb41e4fdfd | |
| syndamia.com-daab5443e76fe16642dde1fb2ef32b723fd4037b.tar syndamia.com-daab5443e76fe16642dde1fb2ef32b723fd4037b.tar.gz syndamia.com-daab5443e76fe16642dde1fb2ef32b723fd4037b.zip | ||
| Parent | 15094c5da196d0b23f41c6882a397284b2741ab0 (diff) | |
[hooks] Removed bash hook scripts and made awk scripts the way to generate the website
13 files changed, 151 insertions, 176 deletions
| -rwxr-xr-x | generate-dev.sh | 25 | ||||
| -rw-r--r-- | generate-hooks/README.md | 6 | ||||
| -rw-r--r-- | generate-hooks/create-description.awk | 34 | ||||
| -rw-r--r-- | generate-hooks/create-file-lists.awk | 48 | ||||
| -rw-r--r-- | generate-hooks/create-flags.awk | 6 | ||||
| -rw-r--r-- | generate-hooks/create-presentation.awk | 27 | ||||
| -rw-r--r-- | generate-hooks/create-title.awk | 27 | ||||
| -rwxr-xr-x | generate-hooks/make-descriptions.sh | 16 | ||||
| -rwxr-xr-x | generate-hooks/make-file-lists.sh | 60 | ||||
| -rwxr-xr-x | generate-hooks/make-flags.sh | 18 | ||||
| -rwxr-xr-x | generate-hooks/make-presentation.sh | 37 | ||||
| -rwxr-xr-x | generate-hooks/make-titles.sh | 16 | ||||
| -rwxr-xr-x | generate.sh | 7 |
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, "<p") > 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 (<td> 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: +# <details><summary>Folder Info</summary> <table> <tr>File Data</tr> </table> </details> +# or this: +# <table> <tr>File Data</tr> </table> +# 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 +# <td>Data 1</td> +# <td>Data 1.1</td> +# <td>Data 1.2</td> +# &&fs +# <td>Data 2</td> +# <td>Data 2.1</td> +# <td>Data 2.2</td> +# &&fod +# +# or +# +# &&nos +# <td>Data 1</td> +# <td>Data 1.1</td> +# <td>Data 1.2</td> +# &&fs +# <td>Data 2</td> +# <td>Data 2.1</td> +# <td>Data 2.2</td> +# &&nod + +# +# And the lines starting with && (I'll call them ftags) get replaced by some HTML. The <td></td> 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/, "<table class=\"file-list\"><tr>") gsub(/^<p>&&fos$/, "<details class=\"file-wrapper\"><summary>") 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 @@ -/<h1>.+/ { - # Takes everything between <h1> and </h1> in the first - # <h1> occurence. - h = index($0, "<h1>") - print substr($0, h, index($0, "</h1") - h) - exit +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 and substrings everything that is normally + # inside the heading tag + gsub(/<h1[^>]*>/, "") + title = substr($0, h1Index, index($0, "</h1") - h1Index) +} + +"\\[TITLE\\]" { + gsub("\\[TITLE\\]", title) +} + +{ + print } diff --git a/generate-hooks/make-descriptions.sh b/generate-hooks/make-descriptions.sh deleted file mode 100755 index 9895f2e..0000000 --- a/generate-hooks/make-descriptions.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-description.awk" - -# Loop through all HTML files in given directory -for file in $1; do - description=$(awk -f "$awkloc" $file) - - # Replace all "[DESCRIPTION]" text in current file with what we selected (inside description) - sed -i "s/\[DESCRIPTION\]/$description/g" $file -done diff --git a/generate-hooks/make-file-lists.sh b/generate-hooks/make-file-lists.sh deleted file mode 100755 index 87d8e61..0000000 --- a/generate-hooks/make-file-lists.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash - -# 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 (<td> 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: -# <details><summary>Folder Info</summary> <table> <tr>File Data</tr> </table> </details> -# or this: -# <table> <tr>File Data</tr> </table> -# 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 -# <td>Data 1</td> -# <td>Data 1.1</td> -# <td>Data 1.2</td> -# &&fs -# <td>Data 2</td> -# <td>Data 2.1</td> -# <td>Data 2.2</td> -# &&fod -# -# or -# -# &&nos -# <td>Data 1</td> -# <td>Data 1.1</td> -# <td>Data 1.2</td> -# &&fs -# <td>Data 2</td> -# <td>Data 2.1</td> -# <td>Data 2.2</td> -# &&nod - -# -# And the lines starting with && (I'll call them ftags) get replaced by some HTML. The <td></td> 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 # |