From faf0171f3381585a4357cadb89129a6bbec6a4ca Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Wed, 5 Apr 2023 19:49:34 -0300 Subject: v2: src/bin/html: Remove slugify_once() --- v2/src/bin/html | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'v2') 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.*|\1|")" HEADING="$(printf '%s' "$line" | sed "s|^$INDENT\(.*\)$|\1|")" - SLUG="$(slugify_once "$HEADING")" + SLUG="$(slugify "$HEADING")" printf '%s%s\n' \ "$INDENT" \ "$LVL" \ @@ -206,12 +193,29 @@ add_headings_anchors() { ) } + +warn_duplicate_ids() { + F="$(mkstemp)" + tee "$F" + { + grep "^$INDENT.*&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 -- cgit v1.2.3