feat: custom admonitions

This commit is contained in:
2026-03-20 08:31:58 +01:00
parent 137be9579a
commit cc7fee573f
5 changed files with 27 additions and 9 deletions

View File

@@ -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 "<div class=\"admonition admonition-" lkind "\">"
print "<p class=\"admonition-title\">" cap(lkind) "</p>"
has_body = 0

17
kewt.sh
View File

@@ -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'
<!doctype html>
@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -19,3 +19,4 @@ error_page = "not_found.html"
versioning = true
enable_header_links = true
base_url = "https://kewt.krzak.org"
custom_admonitions = ""