From cc7fee573fad79be09fae4792ec8186c2338fb12 Mon Sep 17 00:00:00 2001 From: "N0\\A" Date: Fri, 20 Mar 2026 08:31:58 +0100 Subject: [PATCH] feat: custom admonitions --- awk/blockquote_to_admonition.awk | 14 +++++++++++++- kewt.sh | 17 ++++++++++------- markdown.sh | 2 +- site/index.md | 2 ++ site/site.conf | 1 + 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/awk/blockquote_to_admonition.awk b/awk/blockquote_to_admonition.awk index 36bde00..a90945d 100644 --- a/awk/blockquote_to_admonition.awk +++ b/awk/blockquote_to_admonition.awk @@ -22,7 +22,19 @@ END { sub(/^\[!/, "", kind) sub(/\]$/, "", kind) lkind = tolower(kind) - if (lkind == "note" || lkind == "tip" || lkind == "important" || lkind == "warning" || lkind == "caution") { + is_valid = 0 + if (custom_admonitions != "") { + n = split(tolower(custom_admonitions), adms, ",") + for (idx = 1; idx <= n; idx++) { + adm = adms[idx] + sub(/^[ \t]+/, "", adm) + sub(/[ \t]+$/, "", adm) + if (lkind == adm) { is_valid = 1; break } + } + } else if (lkind == "note" || lkind == "tip" || lkind == "important" || lkind == "warning" || lkind == "caution") { + is_valid = 1 + } + if (is_valid) { print "
" print "

" cap(lkind) "

" has_body = 0 diff --git a/kewt.sh b/kewt.sh index c3ac31d..5692799 100755 --- a/kewt.sh +++ b/kewt.sh @@ -68,8 +68,8 @@ base_url = "" generate_feed = false feed_file = "rss.xml" posts_dir = "" +custom_admonitions = "" EOF - fi cat > "$new_dir/template.html" <<'EOF' @@ -166,6 +166,7 @@ base_url = "" generate_feed = false feed_file = "rss.xml" posts_dir = "" +custom_admonitions = "" CONFEOF # Update site.conf @@ -447,6 +448,7 @@ base_url="" generate_feed="false" feed_file="rss.xml" posts_dir="" +custom_admonitions="" load_config() { [ -f "$1" ] || return @@ -498,6 +500,7 @@ load_config() { generate_feed) generate_feed="$val" ;; feed_file) feed_file="${val#/}" ;; posts_dir) posts_dir="${val#/}" ;; + custom_admonitions) custom_admonitions="$val" ;; esac done < "$1" } @@ -760,11 +763,11 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while if [ -f "$dir/styles.css" ]; then if needs_rebuild "$dir/styles.css" "$out_dir/styles.css"; then - copy_style_with_resolved_vars "$dir/styles.css" "$out_dir/styles.css" + copy_style_with_resolved_vars "$dir/styles.css" "$out_dir/styles.css" fi elif [ -f "$dir/style.css" ]; then if needs_rebuild "$dir/style.css" "$out_dir/styles.css"; then - copy_style_with_resolved_vars "$dir/style.css" "$out_dir/styles.css" + copy_style_with_resolved_vars "$dir/style.css" "$out_dir/styles.css" fi fi @@ -783,7 +786,7 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while target_url="/$rel_dir/index.html" [ "$rel_dir" = "." ] && target_url="/index.html" if needs_rebuild "$md_file" "$out_dir/index.html"; then - render_markdown "$md_file" "$is_home" "$target_url" > "$out_dir/index.html" + render_markdown "$md_file" "$is_home" "$target_url" > "$out_dir/index.html" fi continue fi @@ -845,7 +848,7 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while target_url="/$rel_dir/index.html" [ "$rel_dir" = "." ] && target_url="/index.html" if needs_rebuild "$dir" "$out_dir/index.html"; then - render_markdown "$temp_index" "$is_home" "$target_url" > "$out_dir/index.html" + render_markdown "$temp_index" "$is_home" "$target_url" > "$out_dir/index.html" fi rm "$temp_index" fi @@ -884,11 +887,11 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type f -print" | sort | while is_home="false"; [ "$file" = "$src/index.md" ] && is_home="true" out_file="$out/${rel_path%.md}.html" if needs_rebuild "$file" "$out_file"; then - render_markdown "$file" "$is_home" > "$out_file" + render_markdown "$file" "$is_home" > "$out_file" fi else if needs_rebuild "$file" "$out/$rel_path"; then - cp "$file" "$out/$rel_path" + cp "$file" "$out/$rel_path" fi fi done diff --git a/markdown.sh b/markdown.sh index 2b6db36..4176c71 100755 --- a/markdown.sh +++ b/markdown.sh @@ -52,7 +52,7 @@ while grep '^>' "$temp_file" >/dev/null; do fi done -awk -f "$awk_dir/blockquote_to_admonition.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file" +awk -v custom_admonitions="$CUSTOM_ADMONITIONS" -f "$awk_dir/blockquote_to_admonition.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file" awk -f "$awk_dir/fenced_code.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file" awk -f "$awk_dir/indented_code.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file" awk -f "$awk_dir/pipe_tables.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file" diff --git a/site/index.md b/site/index.md index 8e7f448..8e06dcf 100644 --- a/site/index.md +++ b/site/index.md @@ -86,6 +86,7 @@ generate_feed = false feed_file = "rss.xml" posts_dir = "" enable_header_links = true +custom_admonitions = "" ``` - `title` site title @@ -112,6 +113,7 @@ enable_header_links = true - `feed_file` filename for the generated RSS feed (default: "rss.xml") - `posts_dir` directory name containing posts (e.g., "posts"). Enables reverse-chronological sorting, title headings in indexes, and automatic backlinks. - `enable_header_links` turns markdown section headings into clickable anchor links (default: true) +- `custom_admonitions` comma separated list of custom admonitions ## Ignores diff --git a/site/site.conf b/site/site.conf index 6291448..8ca7ac6 100644 --- a/site/site.conf +++ b/site/site.conf @@ -19,3 +19,4 @@ error_page = "not_found.html" versioning = true enable_header_links = true base_url = "https://kewt.krzak.org" +custom_admonitions = ""