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() --- TODOs.md | 4 ++-- v2/src/bin/html | 34 +++++++++++++++++++--------------- 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
 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.*|\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