From 438014583ba2c244675d0f8d7f7f8bf9d568a7c8 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 1 Sep 2024 09:14:28 -0300 Subject: Initial version --- src/html | 307 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 149 insertions(+), 158 deletions(-) (limited to 'src/html') diff --git a/src/html b/src/html index 007fcc2..3e100cb 100755 --- a/src/html +++ b/src/html @@ -1,174 +1,165 @@ #!/bin/sh -set -eu +set -euo pipefail + usage() { - echo 'Usage: html FILENAME' + echo 'Usage: html FILENAME.htmlbody' } FILENAME="${1:-}" -eval "$(assert-arg -- "$FILENAME" 'FILENAME')" - -. "${FILENAME%.*}.conf" - -# -# Utility functions -# - -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 - } - - /^

+          

+ Posted on +

+EOF + + if [ -n "$updatedat_formatted" ]; then + cat < + Updated on " +

+EOF + fi + + cat < +EOF } -extract_plaintext_snippets() ( - SNIPPETS="${FILENAME%.*}.snippets" - printf '' > "$SNIPPETS" - F="$(mkstemp)" - cat > "$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 }
-	'
-}
+h1() {
+	if [ "${custom_body:-}" = true ]; then
+		return
+	fi
 
-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 "$HEADING")"
-		printf '%s%s\n' \
-			"$INDENT"  \
-			"$LVL"     \
-			"$SLUG"    \
-			"$HEADING" \
-			"$SLUG"    \
-			"${icon_link_url:?}" \
-			"$LVL"
-	done
-)
-
-
-warn_duplicate_ids() {
-	F="$(mkstemp)"
-	tee "$F"
-	{
-		grep "^$INDENT.*&2 < "$F"
-	rm "$F"
+	cat <
+          $title_html
+        
+EOF
 }
 
-emit_body() {
-	< "${FILENAME%.*}.content" \
-		markdown_to_html           |
-		extract_plaintext_snippets |
-		add_line_numbers           |
-		add_headings_anchors       |
-		warn_duplicate_ids
+comments() {
+	if [ "${custom_body:-}" = true ]; then
+		return
+	fi
+
+	cat <
+          
+
+ +EOF } -if [ -r "$FILENAME".prev ]; then - collection_head_prev_html="$( - printf ' ' \ - "$(url-for < "$FILENAME".prev)" - )" - export collection_head_prev_html -fi -if [ -r "$FILENAME".next ]; then - collection_head_next_html="$( - printf ' ' \ - "$(url-for < "$FILENAME".next)" - )" - export collection_head_next_html +head_meta_author_html= +if [ -n "${author:-}" ]; then + head_meta_author_html=" " fi -envsubst < lib/preamble.html | sed '/^$/d' -emit_body | tee "${FILENAME%.*}.htmlbody" -envsubst < lib/postamble.html | sed '/^$/d' + +headlinks() { + if [ -z "${header_links:-}" ]; then + return + fi + + echo '
    ' + + while read -r line; do + link="$(printf '%s\n' "$line" | cut -d' ' -f1)" + name="$(printf '%s\n' "$line" | cut -d' ' -f2)" + cat < + $name + +EOF + done < "$header_links" + + echo '
' +} + + +collection_head_prev_html= +collection_head_post_html= +cat < + + + + +$head_meta_author_html + + + + +$collection_head_prev_html +$collection_head_post_html + $titlefull_html + + +
+ +
+
+
+
+EOF + +h1 +dates + +cat "$FILENAME" + +comments + +cat < +
+ + + +EOF -- cgit v1.2.3
%s%s
%s%s