feat: custom admonitions
This commit is contained in:
@@ -22,7 +22,19 @@ END {
|
|||||||
sub(/^\[!/, "", kind)
|
sub(/^\[!/, "", kind)
|
||||||
sub(/\]$/, "", kind)
|
sub(/\]$/, "", kind)
|
||||||
lkind = tolower(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 "<div class=\"admonition admonition-" lkind "\">"
|
||||||
print "<p class=\"admonition-title\">" cap(lkind) "</p>"
|
print "<p class=\"admonition-title\">" cap(lkind) "</p>"
|
||||||
has_body = 0
|
has_body = 0
|
||||||
|
|||||||
17
kewt.sh
17
kewt.sh
@@ -68,8 +68,8 @@ base_url = ""
|
|||||||
generate_feed = false
|
generate_feed = false
|
||||||
feed_file = "rss.xml"
|
feed_file = "rss.xml"
|
||||||
posts_dir = ""
|
posts_dir = ""
|
||||||
|
custom_admonitions = ""
|
||||||
EOF
|
EOF
|
||||||
fi
|
|
||||||
|
|
||||||
cat > "$new_dir/template.html" <<'EOF'
|
cat > "$new_dir/template.html" <<'EOF'
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
@@ -166,6 +166,7 @@ base_url = ""
|
|||||||
generate_feed = false
|
generate_feed = false
|
||||||
feed_file = "rss.xml"
|
feed_file = "rss.xml"
|
||||||
posts_dir = ""
|
posts_dir = ""
|
||||||
|
custom_admonitions = ""
|
||||||
CONFEOF
|
CONFEOF
|
||||||
|
|
||||||
# Update site.conf
|
# Update site.conf
|
||||||
@@ -447,6 +448,7 @@ base_url=""
|
|||||||
generate_feed="false"
|
generate_feed="false"
|
||||||
feed_file="rss.xml"
|
feed_file="rss.xml"
|
||||||
posts_dir=""
|
posts_dir=""
|
||||||
|
custom_admonitions=""
|
||||||
|
|
||||||
load_config() {
|
load_config() {
|
||||||
[ -f "$1" ] || return
|
[ -f "$1" ] || return
|
||||||
@@ -498,6 +500,7 @@ load_config() {
|
|||||||
generate_feed) generate_feed="$val" ;;
|
generate_feed) generate_feed="$val" ;;
|
||||||
feed_file) feed_file="${val#/}" ;;
|
feed_file) feed_file="${val#/}" ;;
|
||||||
posts_dir) posts_dir="${val#/}" ;;
|
posts_dir) posts_dir="${val#/}" ;;
|
||||||
|
custom_admonitions) custom_admonitions="$val" ;;
|
||||||
esac
|
esac
|
||||||
done < "$1"
|
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 [ -f "$dir/styles.css" ]; then
|
||||||
if needs_rebuild "$dir/styles.css" "$out_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
|
fi
|
||||||
elif [ -f "$dir/style.css" ]; then
|
elif [ -f "$dir/style.css" ]; then
|
||||||
if needs_rebuild "$dir/style.css" "$out_dir/styles.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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -783,7 +786,7 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while
|
|||||||
target_url="/$rel_dir/index.html"
|
target_url="/$rel_dir/index.html"
|
||||||
[ "$rel_dir" = "." ] && target_url="/index.html"
|
[ "$rel_dir" = "." ] && target_url="/index.html"
|
||||||
if needs_rebuild "$md_file" "$out_dir/index.html"; then
|
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
|
fi
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
@@ -845,7 +848,7 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while
|
|||||||
target_url="/$rel_dir/index.html"
|
target_url="/$rel_dir/index.html"
|
||||||
[ "$rel_dir" = "." ] && target_url="/index.html"
|
[ "$rel_dir" = "." ] && target_url="/index.html"
|
||||||
if needs_rebuild "$dir" "$out_dir/index.html"; then
|
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
|
fi
|
||||||
rm "$temp_index"
|
rm "$temp_index"
|
||||||
fi
|
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"
|
is_home="false"; [ "$file" = "$src/index.md" ] && is_home="true"
|
||||||
out_file="$out/${rel_path%.md}.html"
|
out_file="$out/${rel_path%.md}.html"
|
||||||
if needs_rebuild "$file" "$out_file"; then
|
if needs_rebuild "$file" "$out_file"; then
|
||||||
render_markdown "$file" "$is_home" > "$out_file"
|
render_markdown "$file" "$is_home" > "$out_file"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if needs_rebuild "$file" "$out/$rel_path"; then
|
if needs_rebuild "$file" "$out/$rel_path"; then
|
||||||
cp "$file" "$out/$rel_path"
|
cp "$file" "$out/$rel_path"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ while grep '^>' "$temp_file" >/dev/null; do
|
|||||||
fi
|
fi
|
||||||
done
|
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/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/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"
|
awk -f "$awk_dir/pipe_tables.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ generate_feed = false
|
|||||||
feed_file = "rss.xml"
|
feed_file = "rss.xml"
|
||||||
posts_dir = ""
|
posts_dir = ""
|
||||||
enable_header_links = true
|
enable_header_links = true
|
||||||
|
custom_admonitions = ""
|
||||||
```
|
```
|
||||||
|
|
||||||
- `title` site title
|
- `title` site title
|
||||||
@@ -112,6 +113,7 @@ enable_header_links = true
|
|||||||
- `feed_file` filename for the generated RSS feed (default: "rss.xml")
|
- `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.
|
- `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)
|
- `enable_header_links` turns markdown section headings into clickable anchor links (default: true)
|
||||||
|
- `custom_admonitions` comma separated list of custom admonitions
|
||||||
|
|
||||||
## Ignores
|
## Ignores
|
||||||
|
|
||||||
|
|||||||
@@ -19,3 +19,4 @@ error_page = "not_found.html"
|
|||||||
versioning = true
|
versioning = true
|
||||||
enable_header_links = true
|
enable_header_links = true
|
||||||
base_url = "https://kewt.krzak.org"
|
base_url = "https://kewt.krzak.org"
|
||||||
|
custom_admonitions = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user