aboutsummaryrefslogtreecommitdiff
path: root/v2/src/development
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2023-04-04 17:24:12 -0300
committerEuAndreh <eu@euandre.org>2023-04-04 17:24:12 -0300
commit419cd721024f5ebc364cdd9014222e0a48221ac7 (patch)
tree6de46c7c89853514f5b5be30a392bb7570767354 /v2/src/development
parentv2: WIP genhtml via envsubst (diff)
downloadeuandre.org-419cd721024f5ebc364cdd9014222e0a48221ac7.tar.gz
euandre.org-419cd721024f5ebc364cdd9014222e0a48221ac7.tar.xz
v2/: HTML! Handle pages, multiple languages, and snippets
Diffstat (limited to 'v2/src/development')
-rwxr-xr-xv2/src/development/genhtml.sh36
-rwxr-xr-xv2/src/development/getconf.sh116
2 files changed, 99 insertions, 53 deletions
diff --git a/v2/src/development/genhtml.sh b/v2/src/development/genhtml.sh
index 8950b1d..f3a6e3a 100755
--- a/v2/src/development/genhtml.sh
+++ b/v2/src/development/genhtml.sh
@@ -92,11 +92,33 @@ slugify_once() {
fi
}
+INDENT=' '
markdown_to_html() {
- md2html
+ md2html | awk -vINDENT="$INDENT" '
+ BEGIN {
+ in_block = 0
+ }
+
+ {
+ if (in_block == 0) {
+ printf "%s", INDENT
+ }
+ print
+ }
+
+ /^<\/code><\/pre>$/ {
+ in_block = 0
+ }
+
+ /^<pre><code/ {
+ in_block = 1
+ }
+ '
}
extract_plaintext_snippets() {
+ SNIPPETS="${FILENAME%.md}.snippets"
+ rm -f "$SNIPPETS"
F="$(mkstemp)"
cat > "$F"
(
@@ -112,13 +134,14 @@ extract_plaintext_snippets() {
printf '%s\n' "$line" | htmlesc -d >> "$OUT"
fi
- if printf '%s' "$line" | grep -q '^<pre><code.*>'; then
+ if printf '%s' "$line" | grep -q "^$INDENT<pre><code"; then
IN_BLOCK=1
OUT="${FILENAME%.md}.html.$BLOCK_NUMBER.txt"
BLOCK_NUMBER=$((BLOCK_NUMBER + 1))
printf '%s\n' "$line" |
- sed 's|^\(<pre><code.*>\)\(.*\)$|\2|' |
+ sed "s|^\($INDENT<pre><code.*>\)\(.*\)$|\2|" |
htmlesc -d > "$OUT"
+ printf '%s\n' "$OUT" >> "$SNIPPETS"
fi
done < "$F"
@@ -127,7 +150,9 @@ extract_plaintext_snippets() {
printf '%s\n' "$line"
if [ "$line" = '</code></pre>' ]; then
- printf '<p class="plaintext-link"><a href="%s.%s.txt">plaintext</a></p>\n' "$(url-for "$URL")" "$BLOCK_NUMBER"
+ printf '%s<p class="plaintext-link"><a href="%s">plaintext</a></p>\n' \
+ "$INDENT" \
+ "$(basename "${url_part:?}").$BLOCK_NUMBER.txt"
BLOCK_NUMBER=$((BLOCK_NUMBER + 1))
fi
done < "$F"
@@ -143,7 +168,7 @@ add_line_numbers() {
next
}
- match($0, /^(<pre><code.*>)(.*)$/, a) {
+ match($0, /^( +<pre><code.*>)(.*)$/, a) {
printf "%s<table rules=columns class=\"code-block\"><tbody>", a[1]
n = 1
@@ -194,4 +219,5 @@ emit_body() {
}
envsubst < src/lib/preamble.html
+emit_body
envsubst < src/lib/postamble.html
diff --git a/v2/src/development/getconf.sh b/v2/src/development/getconf.sh
index aa90706..3f7ccd2 100755
--- a/v2/src/development/getconf.sh
+++ b/v2/src/development/getconf.sh
@@ -73,58 +73,78 @@ escape() {
sed 's|\([`"$]\)|\\\1|g'
}
-{
- tee "$FILENAME".tmp < src/lib/base-conf
- 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
- # shellcheck source=/dev/null
- . "$FILENAME".tmp
-
- cat src/lib/base."${lang:?}".conf
- # shellcheck source=/dev/null
- . src/lib/base."$lang".conf
-
- if [ -z "${title:-}" ]; then
- title="${site_name:?}"
- printf 'title="%s"\n' "$(printf '%s' "$title" | escape)"
+tee "$FILENAME".tmp < src/lib/base-conf
+DELIMITER=0
+while read -r line; do
+ if [ "$line" = '---' ]; then
+ DELIMITER=$((DELIMITER + 1))
+ continue
fi
-
- if [ -z "${date:-}" ]; then
- printf 'date_formatted="%s"\n' "$(LANG="$lang" date -d "${date:?}" +"${date_fmt:?}" | escape)"
+ if [ "$DELIMITER" = 2 ]; then
+ break
+ fi
+ if [ -z "$line" ]; then
+ continue
fi
- url_part="$(printf '%s' "${FILENAME%.md}.html" | sed 's|^src/content/||')"
+ KEY="$( printf '%s' "$line" | cut -d: -f1)"
+ VALUE="$(printf '%s' "$line" | cut -d: -f2- | sed 's|^ ||' | escape)"
+ printf 'export %s="%s"\n' "$KEY" "$VALUE"
+done < "$FILENAME" | tee -a "$FILENAME".tmp
+# shellcheck source=/dev/null
+. "$FILENAME".tmp
+rm -f "$FILENAME".tmp
+
+cat src/lib/base."${lang:?}".conf
+# shellcheck source=/dev/null
+. src/lib/base."$lang".conf
+if [ -z "${title:-}" ]; then
+ title="${site_name:?}"
+ printf 'export title="%s"\n' "$(printf '%s' "$title" | escape)"
+fi
+
+if [ -n "${date:-}" ]; then
+ formatted_date="$(LANG="$lang" date -d "${date:?}" +"${date_fmt:?}")"
+ export formatted_date
+ printf 'export date_html="%s"\n' "$(envsubst < src/lib/date."$lang".html | escape)"
+fi
+
+if [ -n "${update:-}" ]; then
+ formatted_update="$(LANG="$lang" date -d "${update:?}" +"${date_fmt:?}")"
+ export formatted_update
+ printf 'export update_html="%s"\n' "$(envsubst < src/lib/update."$lang".html | escape)"
+fi
+
+
+url_part="$(printf '%s' "${FILENAME%.md}.html" | sed 's|^src/content/||')"
+title_uri="$(uri "$title")"
+
+printf 'export title_html="%s"\n' "$(printf '%s' "$title" | htmlesc | escape)"
+printf 'export filename="%s"\n' "$FILENAME"
+printf 'export url_part="%s"\n' "$url_part"
+printf 'export url="%s"\n' "$(url-for "$url_part" | absolute)"
+printf 'export mailto_uri="%s%s"\n' "${mailto_uri_prefix:?}" "$title_uri"
+printf 'export discussions_url="%s%s"\n' "${discussions_url_prefix:?}" "$title_uri"
+printf 'export sourcecode_url="%s%s"\n' "${sourcecode_url_prefix:?}" "$FILENAME"
+
+printf 'export style_url="%s"\n' "$(url-for -g 'style.css')"
+printf 'export favicon_url="%s"\n' "$(url-for -g 'favicon.svg')"
+printf 'export pubkey_url="%s"\n' "$(url-for -g 'public.asc.txt')"
+
+for f in src/content/img/*.svg; do
+ name="$(basename "$f" .svg | sed 's|-|_|g')"
+ printf 'export icon_%s_url="%s"\n' "$name" "$(url-for -g "img/$(basename "$f")")"
+done
- 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 '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"
+# FIXME: special treatment of root
+printf 'export homepage_url="%s"\n' "$(url-for '/')"
- printf 'style_url="%s"\n' "$(url-for -g 'style.css')"
- printf 'favicon_url="%s"\n' "$(url-for -g 'favicon.svg')"
+printf 'export about_url="%s"\n' "$(url-for "${about_url_name:?}")"
- # FIXME: special treatment of root
- printf 'homepage_url="%s"\n' "$(url-for '/')"
-
- printf 'about_url="%s"\n' "$(url-for "${about_url_name:?}")"
- rm -f "$FILENAME".tmp
-} | grep . | sed 's|^|export |'
+if [ "${layout:-}" = 'post' ]; then
+ export mailto_uri="$mailto_uri_prefix$title_uri"
+ export discussions_url="$discussions_url_prefix$title_uri"
+ export sourcecode_url="$sourcecode_url_prefix$FILENAME"
+ printf 'export comment_html="%s"\n' "$(envsubst < src/lib/comment."$lang".html | escape)"
+fi