diff options
author | Preston Pan <preston@nullring.xyz> | 2023-02-05 11:59:49 -0800 |
---|---|---|
committer | Preston Pan <preston@nullring.xyz> | 2023-02-05 11:59:49 -0800 |
commit | 66df42ef5fee7614171e2ddff4d62e1ac718ce05 (patch) | |
tree | d8c1e303e92a351bf00343b8d23919d4bfa2f9c8 | |
parent | 8cc4983e38e3a35f6aa71d59ba377e9bce0dfeea (diff) |
updated?
-rwxr-xr-x | .lmao | 101 | ||||
-rw-r--r-- | build/website/index.html | 1 | ||||
-rwxr-xr-x | process_file | 8 | ||||
-rw-r--r-- | website/index.html | 1 |
4 files changed, 107 insertions, 4 deletions
@@ -0,0 +1,101 @@ +#!/bin/sh + +# Author: Preston Pan +# Date: 05/10/2022 +# Description: Script called from `find` in build.sh. $1 is the file that `find` is currently on. + +if [ $# -eq 0 ]; then + printf "Error: This script must be ran from a find command or build.sh!\n" + exit 1 +fi + +# This function recursively resolves the $$INCLUDE calls +template_replacement() +{ + r_templates="$(< "$TEMPLATE_BUILD_DIR/$(basename "$1")" grep "\$\$INCLUDE")" # this is the future built version of our template. + # We are finding the $$INCLUDE lines. + if [ -z "$r_templates" ] # Base case of recursion: there are no more $$INCLUDE calls. + then + return 0 + fi + + echo "$r_templates" | while read -r i + do + # Escapes special characters from line containing $$INCLUDE call + keyword_regexp="$(printf '%s' "$i" | tr '\n' ' '| sed 's/[^\^]/&/g; s/[\^]/\\&/g;' | sed 's/[&/\]/\\&/g')" + r_tname="$TEMPLATE_DIR/$(echo "$i" | cut -d ' ' -f 2).html" + # Get contents of file then escapes special characters + f_contents="$(cat "$r_tname")" + replacement_regexp="$(printf '%s' "$f_contents" | tr '\n' ' ' | sed 's/[^\^]/&/g; s/[\^]/\\&/g;' | sed 's/[&/\]/\\&/g')" + #Finally do the sed replace to replace the $$INCLUDE line with the contents of the included template file + sed -i "s/$keyword_regexp/$replacement_regexp/g" "$TEMPLATE_BUILD_DIR/$(basename "$1")" # BUG: This shit does not work + # Then we do it all again on the same file. + template_replacement "$1" + done +} + +fname="$(basename "$1")" # gets the name of file in question +if [ "${fname##*.}" != "html" ] # If it is not an html file, just copy it over to the build directory, the script does nothing. +then + cp "$1" "$BUILD_DIR/$1" + exit 0 +fi + +# We want the first specified template to be the template +template_name="$(< "$1" grep "\$\$TEMPLATE" | head -1)" + + +# Location of the template that is to be built from template_replacement + +if [ -n "$template_name" ] # We get the path of the template and if no template is specified it uses the default. +then + template="$TEMPLATE_DIR/$(echo "$template_name" | cut -d ' ' -f 2 | tr -d '\n').html" +else + template="$DEFAULT_TEMPLATE" +fi + +built_template="$TEMPLATE_BUILD_DIR/$(basename "$template")" +template_replacement "$template" # replace all the $$TEMPLATE calls. + +vars="$(< "$1" grep "\$\$START")" + +# now we prepare to do the variable substitutions. +cp "$built_template" "$BUILD_DIR/$1" + +echo "$vars" | while read -r var; +do + # Get the name of the variable + name="$(echo "$var" | cut -d ' ' -f 2 | tr -d '\n')" + keyword_regexp="$(printf '%s' "$var" | tr '\n' ' ' | sed 's/[^\^]/&/g; s/[\^]/\\&/g;' | sed 's/[&/\]/\\&/g')" + # Get the endpoint of the variable + var_end="\$\$END $name" + end_regexp="$(printf '%s' "$var_end" | tr '\n' ' ' | sed 's/[^\^]/&/g; s/[\^]/\\&/g;' | sed 's/[&/\]/\\&/g')" + # Get the value of the variable + value="$(< "$BUILD_DIR/$1" gsed -n "/$keyword_regexp/,/$end_regexp/p" "$1")" + value_regexp="$(printf '%s' "$value" | tr '\n' ' ' | sed 's/[^\^]/&/g; s/[\^]/\\&/g;' | sed 's/[&/\]/\\&/g')" + # Get the string to replace + replacement="\$\$VAR $name" + replacement_regexp="$(printf '%s' "$replacement" | sed 's/[^\^]/&/g; s/[\^]/\\&/g;' | sed 's/[&/\]/\\&/g')" + # Then do the replacement + sed -i "s/$replacement_regexp/$value_regexp/g" "$BUILD_DIR/$1" # BUG: Doesn't work on openBSD +done + +# For some reason I can't trim these inside the loop (i tried) so this works. +sed -i '/\$\$START/d' "$BUILD_DIR/$1" +sed -i '/\$\$END/d' "$BUILD_DIR/$1" + +debug="$(< "$BUILD_DIR/$1" grep "\$\$SCRIPT")" +printf "$debug\n" + +if [ -n "$debug" ] +then + echo "$debug" | while read -r line; + do + name="$(echo "$line" | cut -d ' ' -f 2 | tr -d '\n')" + output="$(./"$PLUG_DIR/$name" "$1" "$template")" + keyword_regexp="$(printf '%s' "$line" | tr '\n' ' ' | sed 's/[^\^]/&/g; s/[\^]/\\&/g;' | sed 's/[&/\]/\\&/g')" + replacement_regexp="$(printf '%s' "$output" | tr '\n' ' ' | sed 's/[^\^]/&/g; s/[\^]/\\&/g;' | sed 's/[&/\]/\\&/g')" + + sed -i "s/$keyword_regexp/$replacement_regexp/g" "$BUILD_DIR/$1" # BUG: doesn't work with openBSD + done +fi diff --git a/build/website/index.html b/build/website/index.html index a4eb11c..d8b23d6 100644 --- a/build/website/index.html +++ b/build/website/index.html @@ -85,6 +85,7 @@ Preston Pan <li><a href="https://nullring.xyz">The null webring</a> -- a webring that I made (apparently there is another one by this name but ignore that).</li> <li><a href="https://society.nullring.xyz">The Null Identity </a> -- it's a <b>ahem</b> tightly knit community located in victoria. Yeah, that's the term.</li> <li>IRC server: ircs://prestonpan.tech:6697, no verification of tls (self signed).</li> + <li>I2P website: http://5ziug5tklfrep5gy3gv52xsoujq3nuxstqcj7a2s4jz4psveek4q.b32.i2p, if you are on i2p and want to see my clearnet website, it is at https://prestonpan.tech.</li> </ul> <h2>Webrings</h2> diff --git a/process_file b/process_file index a96f9e8..0aa9ea4 100755 --- a/process_file +++ b/process_file @@ -27,7 +27,7 @@ template_replacement() # Get contents of file then escapes special characters f_contents="$(cat "$r_tname")" replacement_regexp="$(printf '%s' "$f_contents" | gsed -e 's/[\/&]/\\&/g' | gsed ':a;N;$!ba;s,\n,\\n,g')" - #Finally do the gsed replace to replace the $$INCLUDE line with the contents of the included template file + #Finally do the sed replace to replace the $$INCLUDE line with the contents of the included template file gsed -i "s/$keyword_regexp/$replacement_regexp/g" "$TEMPLATE_BUILD_DIR/$(basename "$1")" # BUG: This shit does not work # Then we do it all again on the same file. template_replacement "$1" @@ -81,8 +81,8 @@ do done # For some reason I can't trim these inside the loop (i tried) so this works. -gsed -i '/\$\$START/d' "$BUILD_DIR/$1" -gsed -i '/\$\$END/d' "$BUILD_DIR/$1" +sed -i '/\$\$START/d' "$BUILD_DIR/$1" +sed -i '/\$\$END/d' "$BUILD_DIR/$1" debug="$(< "$BUILD_DIR/$1" grep "\$\$SCRIPT")" printf "$debug\n" @@ -96,6 +96,6 @@ then keyword_regexp="$(printf '%s' "$line" | gsed -e 's/[]\/$*.^|[]/\\&/g' | gsed ':a;N;$!ba;s,\n,\\n,g')" replacement_regexp="$(printf '%s' "$output" | gsed -e 's/[\/&]/\\&/g' | gsed ':a;N;$!ba;s,\n,\\n,g')" - gsed -i "s/$keyword_regexp/$replacement_regexp/g" "$BUILD_DIR/$1" # BUG: doesn't work with openBSD + sed -i "s/$keyword_regexp/$replacement_regexp/g" "$BUILD_DIR/$1" # BUG: doesn't work with openBSD done fi diff --git a/website/index.html b/website/index.html index ab265c3..dfa592b 100644 --- a/website/index.html +++ b/website/index.html @@ -65,6 +65,7 @@ $$START CONTENT <li><a href="https://nullring.xyz">The null webring</a> -- a webring that I made (apparently there is another one by this name but ignore that).</li> <li><a href="https://society.nullring.xyz">The Null Identity </a> -- it's a <b>ahem</b> tightly knit community located in victoria. Yeah, that's the term.</li> <li>IRC server: ircs://prestonpan.tech:6697, no verification of tls (self signed).</li> + <li>I2P website: http://5ziug5tklfrep5gy3gv52xsoujq3nuxstqcj7a2s4jz4psveek4q.b32.i2p, if you are on i2p and want to see my clearnet website, it is at https://prestonpan.tech.</li> </ul> <h2>Webrings</h2> |