feat(admonition): allow full customization

This commit is contained in:
ZhenShuo Leo
2025-12-31 15:41:13 +08:00
parent bf0713c0cf
commit 3c534548df
4 changed files with 69 additions and 32 deletions
@@ -94,6 +94,9 @@ The alert sign (`+` or `-`) is optional to control whether the admonition is fol
> **GitHub types:** `NOTE`, `TIP`, `IMPORTANT`, `WARNING`, `CAUTION` > **GitHub types:** `NOTE`, `TIP`, `IMPORTANT`, `WARNING`, `CAUTION`
> **Obsidian types:** `note`, `abstract`, `info`, `todo`, `tip`, `success`, `question`, `warning`, `failure`, `danger`, `bug`, `example`, `quote` > **Obsidian types:** `note`, `abstract`, `info`, `todo`, `tip`, `success`, `question`, `warning`, `failure`, `danger`, `bug`, `example`, `quote`
> [!INFO]- Customize admonition
> See the [admonition customization guide](https://github.com/nunocoracao/blowfish/blob/main/layouts/_default/_markup/render-blockquote.html).
<br/><br/><br/> <br/><br/><br/>
## Article ## Article
@@ -94,6 +94,9 @@ Admonition 的用途与 alert shortcode 类似,但其实现方式是通过 Hug
> **GitHub 类型:** `NOTE`, `TIP`, `IMPORTANT`, `WARNING`, `CAUTION` > **GitHub 类型:** `NOTE`, `TIP`, `IMPORTANT`, `WARNING`, `CAUTION`
> **Obsidian 类型:** `note`, `abstract`, `info`, `todo`, `tip`, `success`, `question`, `warning`, `failure`, `danger`, `bug`, `example`, `quote` > **Obsidian 类型:** `note`, `abstract`, `info`, `todo`, `tip`, `success`, `question`, `warning`, `failure`, `danger`, `bug`, `example`, `quote`
> [!INFO]- 自定义提示框
> 请参阅 [提示框自定义指南](https://github.com/nunocoracao/blowfish/blob/main/layouts/_default/_markup/render-blockquote.html)。
<br/><br/><br/> <br/><br/><br/>
## Article ## Article
+29 -32
View File
@@ -1,36 +1,33 @@
{{- if eq .Type "alert" -}} {{- /* To customize your own admonitions, you can do the following:
{{- $typeMap := dict
"attention" "warning"
"check" "success"
"cite" "quote"
"done" "success"
"error" "danger"
"fail" "failure"
"faq" "question"
"hint" "tip"
"help" "question"
"missing" "failure"
"summary" "abstract"
"tldr" "abstract"
-}}
{{- $iconMap := dict 1. Change colors
"abstract" "file-lines"
"bug" "bug" Define your colors in `assets/css/custom.css` using the variables from:
"caution" "fire" https://github.com/nunocoracao/blowfish/blob/main/assets/css/components/admonition.css
"danger" "fire"
"example" "list-ol" Example:
"failure" "xmark" ```
"important" "star" :root {
"info" "circle-info" --adm-note-bg: red;
"note" "circle-info" }
"success" "check" html.dark {
"todo" "list-check" --adm-note-bg: green;
"tip" "lightbulb" }
"question" "circle-question" ```
"quote" "quote-left"
"warning" "triangle-exclamation" This will update the background color for light and dark mode.
-}}
2. Change icons and type settings
You can override the default type and icon mappings by creating your own
`impls/hooks/admonition-maps.html` in your `layouts` folder.
This allows you to assign different icons or styles for each admonition type.
*/ -}}
{{- if eq .Type "alert" -}}
{{- $maps := partialCached "impls/hooks/admonition-maps.html" . -}}
{{- $typeMap := $maps.typeMap -}}
{{- $iconMap := $maps.iconMap -}}
{{- $rawType := .AlertType | lower -}} {{- $rawType := .AlertType | lower -}}
{{- $normalizedType := index $typeMap $rawType | default $rawType -}} {{- $normalizedType := index $typeMap $rawType | default $rawType -}}
@@ -0,0 +1,34 @@
{{- /* Override this file in your site to customize admonition type aliases and icon mappings */ -}}
{{- return dict
"typeMap" (dict
"attention" "warning"
"check" "success"
"cite" "quote"
"done" "success"
"error" "danger"
"fail" "failure"
"faq" "question"
"hint" "tip"
"help" "question"
"missing" "failure"
"summary" "abstract"
"tldr" "abstract"
)
"iconMap" (dict
"abstract" "file-lines"
"bug" "bug"
"caution" "fire"
"danger" "fire"
"example" "list-ol"
"failure" "xmark"
"important" "star"
"info" "circle-info"
"note" "circle-info"
"success" "check"
"todo" "list-check"
"tip" "lightbulb"
"question" "circle-question"
"quote" "quote-left"
"warning" "triangle-exclamation"
)
-}}