diff options
Diffstat (limited to 'v2/src')
-rwxr-xr-x | v2/src/bin/html | 34 |
1 files changed, 19 insertions, 15 deletions
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 |