From 24e24b49fb6375189cfa527a113eb965087a293a Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Wed, 5 Apr 2023 16:14:00 -0300 Subject: v2: Support Atom feeds and collection translations --- v2/src/development/genhtml.sh | 224 ------------------------------------------ 1 file changed, 224 deletions(-) delete mode 100755 v2/src/development/genhtml.sh (limited to 'v2/src/development/genhtml.sh') diff --git a/v2/src/development/genhtml.sh b/v2/src/development/genhtml.sh deleted file mode 100755 index 1b2718a..0000000 --- a/v2/src/development/genhtml.sh +++ /dev/null @@ -1,224 +0,0 @@ -#!/bin/sh -set -eu - -usage() { - cat <<-'EOF' - Usage: - genhtml.sh FILENAME - genhtml.sh -h - EOF -} - -help() { - cat <<-'EOF' - - Options: - -h, --help show this message - - FILENAME the name of the input file, to also be used as - URL - - - Process the FILENAME, and generate a full HTML page. - - The FILENAME is used to infer the output URL, by removing the - `src/content/` prefix, and replacing the trailing `.md` with - `.html`. This URL is used to build the self-referencing - "canonical" link, extracting plaintext snippets, etc. - - - Examples: - - Generate the HTML for a pastebin: - - $ sh genhtml.sh src/content/a-paste.md > src/content/a-paste.html - EOF -} - - -for f in "$@"; do - case "$f" 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')" - - -# shellcheck source=/dev/null -. "${FILENAME%.md}.conf" - -# -# Utility functions -# - -SEEN_SLUGS="$(mkstemp)" -slugify_once() { - SLUG="$(printf '%s' "$1" | slugify)${2:+-$2}" - if grep -q "^$SLUG$" "$SEEN_SLUGS"; then - N="${2:-0}" - N=$((N + 1)) - slugify_once "$1" "$N" - else - printf '%s\n' "$SLUG" >> "$SEEN_SLUGS" - printf '%s' "$SLUG" - fi -} - -INDENT=' ' -markdown_to_html() { - md2html | awk -vINDENT="$INDENT" ' - BEGIN { - in_block = 0 - } - - { - if (in_block == 0) { - printf "%s", INDENT - } - print - } - - /^<\/code><\/pre>$/ { - in_block = 0 - } - - /^
 "$F"
-	(
-		IFS=''
-		BLOCK_NUMBER=0
-		IN_BLOCK=
-		while read -r line; do
-			if [ "$line" = '
' ]; then - IN_BLOCK= - fi - - if [ -n "$IN_BLOCK" ]; then - printf '%s\n' "$line" | htmlesc -d >> "$OUT" - fi - - if printf '%s' "$line" | grep -q "^$INDENT
\)\(.*\)$|\2|" |
-					htmlesc -d > "$OUT"
-				printf '%s\n' "$OUT" >> "$SNIPPETS"
-			fi
-		done < "$F"
-
-		BLOCK_NUMBER=0
-		while read -r line; do
-			printf '%s\n' "$line"
-
-			if [ "$line" = '
' ]; then - printf '%s\n' \ - "$INDENT" \ - "$(basename "${url_part:?}").$BLOCK_NUMBER.txt" - BLOCK_NUMBER=$((BLOCK_NUMBER + 1)) - fi - done < "$F" - ) - -} - -add_line_numbers() { - awk ' - /^<\/code><\/pre>$/ { - in_block = 0 - printf "%s\n", $0 - next - } - - match($0, /^( +
)(.*)$/, a) {
-			printf "%s", a[1]
-
-			n = 1
-			block_count++
-			printf "\n", block_count, n, block_count, n, n, a[2]
-			in_block = 1
-			next
-		}
-
-		in_block == 1 {
-			n++
-			printf "\n", block_count, n, block_count, n, n, $0
-			next
-		}
-
-		{ print }
-	'
-}
-
-add_headings_anchors() {
-	(
-		IFS=''
-		while read -r line; do
-			if ! printf '%s' "$line" | grep -q "^$INDENT"; then
-				printf '%s\n' "$line"
-				continue
-			fi
-			LVL="$(printf '%s' "$line" | sed "s|^$INDENT.*|\1|")"
-			HEADING="$(printf '%s' "$line" | sed "s|^$INDENT\(.*\)$|\1|")"
-			SLUG="$(slugify_once "$HEADING")"
-			printf '%s%s\n' \
-				"$INDENT"  \
-				"$LVL"     \
-				"$SLUG"    \
-				"$HEADING" \
-				"$SLUG"    \
-				"${icon_link_url:?}" \
-				"$LVL"
-		done
-	)
-}
-
-emit_body() {
-	< "${FILENAME%.md}.content" \
-		markdown_to_html           |
-		extract_plaintext_snippets |
-		add_line_numbers           |
-		add_headings_anchors
-}
-
-envsubst < src/lib/preamble.html
-emit_body
-envsubst < src/lib/postamble.html
-- 
cgit v1.2.3

%s%s
%s%s