From 08588f9907299b1a927e281d5c65b46b7cefa427 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Tue, 4 Apr 2023 08:33:41 -0300 Subject: Revamp v2/ --- v2/src/development/config.env.in | 6 -- v2/src/development/dynmake.sh | 79 ---------------------- v2/src/development/genhtml.sh | 68 ++++++++++--------- v2/src/development/getconf.sh | 119 ++++++++++++++++++++++++++++++++++ v2/src/development/lib.sh | 33 ++++++++++ v2/src/development/security-txt.sh.in | 82 +++++++++++++++++++++++ 6 files changed, 273 insertions(+), 114 deletions(-) delete mode 100644 v2/src/development/config.env.in delete mode 100755 v2/src/development/dynmake.sh create mode 100755 v2/src/development/getconf.sh create mode 100644 v2/src/development/lib.sh create mode 100755 v2/src/development/security-txt.sh.in (limited to 'v2/src/development') diff --git a/v2/src/development/config.env.in b/v2/src/development/config.env.in deleted file mode 100644 index ca2afe7..0000000 --- a/v2/src/development/config.env.in +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -SITE_NAME="EuAndreh's website" -FQDN='@FQDN@' -BASE_URL='@BASE_URL@' -DATE_FMT='+%B %-d, %Y' diff --git a/v2/src/development/dynmake.sh b/v2/src/development/dynmake.sh deleted file mode 100755 index 126c211..0000000 --- a/v2/src/development/dynmake.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/sh -set -eu - - -usage() { - cat <<-'EOF' - Usage: - dynmake.sh - dynmake.sh -h - EOF -} - -help() { - cat <<-'EOF' - - Options: - -h, --help show this message - - - Generate make(1) code for later evaluation by make(1). What - this scripts does is fill the gap where make(1) can't handle - globs and dynamic dependencies, and uses some ad-hoc scripts - to generate those. - EOF -} - -for flag in "$@"; do - case "$flag" in - --) - break - ;; - --help) - usage - help - exit - ;; - *) - ;; - esac -done - -while getopts 'h' flag; do - case "$flag" in - h) - usage - help - exit - ;; - *) - usage >&2 - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) - - - -varlist() { - sed -e 's/^/ /' \ - -e 's/$/ \\/' -} - - -# -# Pastebins -# - -pastebins() { - find src/content/pastebins/ -name '*.md' -} - -printf 'pastebins.md = \\\n' -pastebins | varlist -printf '\n' - -pastebins | sed 's/^\(.*\)\.md$/\1.html: \1.entry-env/' -pastebins | sed 's/^\(.*\)\.md$/\1.html: \1.entry-content/' -pastebins | sed 's/^\(.*\)\.md$/\1.entry-content: \1.entry-env/' diff --git a/v2/src/development/genhtml.sh b/v2/src/development/genhtml.sh index a1e8afb..cb8fd73 100755 --- a/v2/src/development/genhtml.sh +++ b/v2/src/development/genhtml.sh @@ -1,21 +1,6 @@ #!/bin/sh set -eu -# FIXMEs: -# - feeds -# - link to next and/or previous in -# - translation support -# - validate input variables: regex for date (same as _plugins/linter.rb) -# - `date -d` isn't POSIX -# - parse commonmark and use a custom HTML emitter over
 regex
-# - handle mixture of personal scripts
-# - sitemap?  How does it even work?
-# - dark mode
-# - generate security.txt dynamically
-# - config.env should depend on dynamic.mk?
-
-
-
 usage() {
 	cat <<-'EOF'
 		Usage:
@@ -81,12 +66,13 @@ while getopts 'h' flag; do
 done
 shift $((OPTIND - 1))
 
+. src/development/lib.sh
 
 FILENAME="${1:-}"
-eval "$(assert-arg "$FILENAME" 'FILENAME')"
+eval "$(assert_arg "$FILENAME" 'FILENAME')"
 
-. "${FILENAME%.md}.entry-env"
 
+. "${FILENAME%.md}.conf"
 
 #
 # Utility functions
@@ -216,28 +202,28 @@ emit_body() {
 
 cat <<-EOF
 	
-	
+	
 	  
 	    
 	    
-	    
-	    
+	    
+	    
 
-	    $TITLE
+	    $$title_html
 
 	    
-	    
-	    
-	    
+	    
+	    
+	    
 
-	    
-	    
+	    
+	    
 	  
 	  
 	    
@@ -245,8 +231,19 @@ cat <<-EOF
- $(emit_body) + \$(emit_body)
+EOF +exit + + +.md.rehtml: + F="$<"; . "$${F%.md}.conf"; envsubst < src/lib/reamble."$$lang".html > $@ + +.md.osthtml: + F="$<"; . "$${F%.md}.conf"; envsubst < src/lib/ostamble."$$lang".html > $@ + +
  • a envelope icon representing an email address - eu@euandre.org + $email
  • a lock icon representing a GPG public key @@ -275,3 +272,16 @@ cat <<-EOF EOF + +# FIXMEs: +# - feeds +# - link to next and/or previous in +# - translation support +# - validate input variables: regex for date (same as _plugins/linter.rb) +# - `date -d` isn't POSIX +# - parse commonmark and use a custom HTML emitter over
     regex
    +# - handle mixture of personal scripts
    +# - sitemap?  How does it even work?
    +# - dark mode
    +# - generate security.txt dynamically
    +# - config.env should depend on dynamic.mk?
    diff --git a/v2/src/development/getconf.sh b/v2/src/development/getconf.sh
    new file mode 100755
    index 0000000..dd623f7
    --- /dev/null
    +++ b/v2/src/development/getconf.sh
    @@ -0,0 +1,119 @@
    +#!/bin/sh
    +set -eu
    +
    +
    +usage() {
    +	cat <<-'EOF'
    +		Usage:
    +		  src/development/getconf.sh FILENAME
    +		  src/development/getconf.sh -h
    +	EOF
    +}
    +
    +help() {
    +	cat <<-'EOF'
    +
    +		Options:
    +		  -h, --help    show this message
    +
    +		  FILENAME      the name of the input file, also to be used as
    +		                URL.
    +
    +
    +		Separate the content from the "frontmatter", and emit the
    +		selected one, given the FILENAME.
    +
    +
    +		Examples:
    +
    +		  Get the "frontmatter" of src/f.conf:
    +
    +		    $ src/development/getconf.sh src/f.md > src/f.conf
    +	EOF
    +}
    +
    +
    +for flag in "$@"; do
    +	case "$flag" in
    +		--)
    +			break
    +			;;
    +		--help)
    +			usage
    +			help
    +			exit
    +			;;
    +		*)
    +			;;
    +	esac
    +done
    +
    +while getopts 'h' flag; do
    +	case "$flag" in
    +		h)
    +			usage
    +			help
    +			exit
    +			;;
    +		*)
    +			usage >&2
    +			exit 2
    +			;;
    +	esac
    +done
    +shift $((OPTIND - 1))
    +
    +. src/development/lib.sh
    +
    +FILENAME="${1:-}"
    +eval "$(assert_arg "$FILENAME" 'FILENAME')"
    +
    +
    +escape() {
    +	sed 's|\([`"$]\)|\\\1|g'
    +}
    +
    +{
    +	cat src/lib/base-conf | tee "$FILENAME".tmp
    +	DELIMITER=0
    +	while read -r line; do
    +		if [ "$line" = '---' ]; then
    +			DELIMITER=$((DELIMITER + 1))
    +			continue
    +		fi
    +		if [ "$DELIMITER" = 2 ]; then
    +			break
    +		fi
    +		if [ -z "$line" ]; then
    +			continue
    +		fi
    +
    +		KEY="$(  printf '%s' "$line" | cut -d: -f1)"
    +		VALUE="$(printf '%s' "$line" | cut -d: -f2- | sed 's|^ ||' | escape)"
    +		printf '%s="%s"\n' "$KEY" "$VALUE"
    +	done < "$FILENAME" | tee -a "$FILENAME".tmp
    +	. "$FILENAME".tmp
    +
    +	cat src/lib/base."$lang".conf
    +	. src/lib/base."$lang".conf
    +
    +	title="${title:-"$site_name"}"
    +	url_part="$(printf '%s' "${FILENAME%.md}.html" | sed 's|^src/content/||')"
    +
    +	printf 'title="%s"\n' "$(printf '%s' "$title" | escape)"
    +	printf 'title_html="%s"\n' "$(printf '%s' "$title" | htmlesc | escape)"
    +	printf 'filename="%s"\n' "$FILENAME"
    +	printf 'url_part="%s"\n' "$url_part"
    +	printf 'url="%s"\n' "$(url-for "$url_part" | absolute)"
    +	printf 'date_formatted="%s"\n' "$(LANG="$lang" date -d "$date" +"$date_fmt" | escape)"
    +	printf 'mailto_uri="%s%s"\n' "$mailto_uri_prefix" "$(uri "$title")"
    +	printf 'discussions_url="%s%s"\n' "$discussions_url_prefix" "$(uri "$title")"
    +	printf 'sourcecode_url="%s%s"\n' "$sourcecode_url_prefix" "$FILENAME"
    +
    +	printf 'lang_url="%s"\n' "$(url-for "$lang"/)"
    +
    +	printf 'style_url="%s"\n' "$(url-for 'style.css')"
    +	printf 'favicon_url="%s"\n' "$(url-for 'favicon.svg')"
    +
    +	rm -f "$FILENAME".tmp
    +} | grep . | sed 's|^|export |'
    diff --git a/v2/src/development/lib.sh b/v2/src/development/lib.sh
    new file mode 100644
    index 0000000..9d183f9
    --- /dev/null
    +++ b/v2/src/development/lib.sh
    @@ -0,0 +1,33 @@
    +#!/bin/sh
    +
    +assert_arg() {
    +	if [ -z "$1" ]; then
    +		printf 'Missing %s.\n\n' "$2" >&2
    +		cat <<-'EOF'
    +			usage >&2
    +			exit 2
    +		EOF
    +	fi
    +}
    +
    +uuid() {
    +        od -xN20 /dev/urandom |
    +                head -n1 |
    +                awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}'
    +}
    +
    +tmpname() {
    +        echo "${TMPDIR:-/tmp}/uuid-tmpname with spaces.$(uuid)"
    +}
    +
    +mkstemp() {
    +	name="$(tmpname)"
    +	touch "$name"
    +	echo "$name"
    +}
    +
    +mkdtemp() {
    +        name="$(tmpname)"
    +	mkdir "$name"
    +        echo "$name"
    +}
    diff --git a/v2/src/development/security-txt.sh.in b/v2/src/development/security-txt.sh.in
    new file mode 100755
    index 0000000..8f6613f
    --- /dev/null
    +++ b/v2/src/development/security-txt.sh.in
    @@ -0,0 +1,82 @@
    +#!/bin/sh
    +set -eu
    +
    +usage() {
    +	cat <<-'EOF'
    +		Usage:
    +		  src/development/security-txt.sh
    +		  src/development/security-txt.sh -h
    +	EOF
    +}
    +
    +help() {
    +	cat <<-'EOF'
    +
    +
    +		Options:
    +		  -h, --help    show this message
    +
    +
    +		Generate the RFC 9116 "security.txt" file from data in the
    +		repository.
    +
    +
    +		Examples:
    +
    +		  Just run it:
    +
    +		    $ sh src/development/security-txt.sh > .well-known/security.txt
    +	EOF
    +}
    +
    +
    +for flag in "$@"; do
    +	case "$flag" in
    +		--)
    +			break
    +			;;
    +		--help)
    +			usage
    +			help
    +			exit
    +			;;
    +		*)
    +			;;
    +	esac
    +done
    +
    +while getopts 'h' flag; do
    +	case "$flag" in
    +		h)
    +			usage
    +			help
    +			exit
    +			;;
    +		*)
    +			usage >&2
    +			exit 2
    +	esac
    +done
    +shift $((OPTIND - 1))
    +
    +
    +
    +EXPIRES="$(
    +	LANG=C.UTF-8 gpg --list-key eu@euandre.org |
    +		awk '/^pub/ { print substr($(NF), 1, 10) }'
    +)T00:00:00z"
    +
    +LANGS="en$(
    +	echo po/??.po |
    +		sed 's|\.po$||'  |
    +		sed 's|^po/|, |' |
    +		paste -sd,
    +)"
    +
    +
    +cat <<-EOF
    +	Contact: mailto:@EMAIL@
    +	Encryption: https://@DOMAIN@/public.asc.txt
    +	Expires: $EXPIRES
    +	Preferred-Languages: $LANGS
    +EOF
    -- 
    cgit v1.2.3