aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2023-04-05 19:49:34 -0300
committerEuAndreh <eu@euandre.org>2023-04-05 19:49:34 -0300
commitfaf0171f3381585a4357cadb89129a6bbec6a4ca (patch)
treef449388ecc58d0127d7d82aa9a51461c55770529
parentTODOs.md: feeds by category, now (diff)
downloadeuandre.org-faf0171f3381585a4357cadb89129a6bbec6a4ca.tar.gz
euandre.org-faf0171f3381585a4357cadb89129a6bbec6a4ca.tar.xz
v2: src/bin/html: Remove slugify_once()
-rw-r--r--TODOs.md4
-rwxr-xr-xv2/src/bin/html34
2 files changed, 21 insertions, 17 deletions
diff --git a/TODOs.md b/TODOs.md
index f6fe4b9..adb7ed6 100644
--- a/TODOs.md
+++ b/TODOs.md
@@ -538,10 +538,10 @@ sitemap
# - parse commonmark and use a custom HTML emitter over <pre><code> regex
# - handle mixture of personal scripts
-remove slugify once?
-
po4a for markdown...
article in root????
render slides
+
+how to use tmp fd over tmpfile?
diff --git a/v2/src/bin/html b/v2/src/bin/html
index 7e6809c..922b56e 100755
--- a/v2/src/bin/html
+++ b/v2/src/bin/html
@@ -74,19 +74,6 @@ eval "$(assert_arg "$FILENAME" 'FILENAME')"
# 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" '
@@ -193,7 +180,7 @@ add_headings_anchors() {
fi
LVL="$(printf '%s' "$line" | sed "s|^$INDENT<h\(.\)>.*|\1|")"
HEADING="$(printf '%s' "$line" | sed "s|^$INDENT<h.>\(.*\)</h.>$|\1|")"
- SLUG="$(slugify_once "$HEADING")"
+ SLUG="$(slugify "$HEADING")"
printf '%s<h%s class="header-anchor" id="%s">%s<a href="#%s" aria-hidden="true"><img class="svg-icon" src="%s" /></a></h%s>\n' \
"$INDENT" \
"$LVL" \
@@ -206,12 +193,29 @@ add_headings_anchors() {
)
}
+
+warn_duplicate_ids() {
+ F="$(mkstemp)"
+ tee "$F"
+ {
+ grep "^$INDENT<h[2-6] class=\"header-anchor\" id=\"" |
+ sed "s|^$INDENT<h[2-6] class=\"header-anchor\" id=\"\(.*\)\">.*<a href=.*$|\1|" |
+ sort |
+ uniq -c |
+ awk -v F="$FILENAME" '$1 != 1 {
+ printf "WARNING: duplicate header id: %s: %s\n", F, $2
+ }'
+ } >&2 < "$F"
+ rm "$F"
+}
+
emit_body() {
< "${FILENAME%.md}.content" \
markdown_to_html |
extract_plaintext_snippets |
add_line_numbers |
- add_headings_anchors
+ add_headings_anchors |
+ warn_duplicate_ids
}
envsubst < src/lib/preamble.html