Skip to content

Commit f7d357a

Browse files
authored
Merge pull request #506 from zihanKuang/fix-alert-default-title
fix: correct default title behavior in alert component when only color is provided
2 parents 2c4fa25 + 3dbf804 commit f7d357a

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

layouts/shortcodes/alert.html

+22-6
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,29 @@
5555

5656
{{ $_hugo_config := `{ "version": 1 }` }}
5757
{{ $color := .Get "color" | default "primary" }}
58-
<div class="alert alert-{{ $color }}" role="alert">
59-
{{ with .Get "title" | default "Success"}}<h4 class="alert-heading">{{ . | safeHTML }}</h4>{{ end }}
60-
{{ if eq .Page.File.Ext "md" }}
61-
{{ .Inner | markdownify }}
62-
{{ else }}
63-
{{ .Inner | htmlUnescape | safeHTML }}
58+
{{ $title := .Get "title" }}
59+
60+
{{ if not $title }}
61+
{{ if eq $color "warning" }}
62+
{{ $title = "Warning" }}
63+
{{ else if eq $color "danger" }}
64+
{{ $title = "Danger" }}
65+
{{ else if eq $color "info" }}
66+
{{ $title = "Info" }}
67+
{{ else if eq $color "note" }}
68+
{{ $title = "Note" }}
69+
{{ else }}
70+
{{ $title = "Success" }}
71+
{{ end }}
6472
{{ end }}
73+
74+
<div class="alert alert-{{ $color }}" role="alert">
75+
<h4 class="alert-heading">{{ $title | safeHTML }}</h4>
76+
{{ if eq .Page.File.Ext "md" }}
77+
{{ .Inner | markdownify }}
78+
{{ else }}
79+
{{ .Inner | htmlUnescape | safeHTML }}
80+
{{ end }}
6581
</div>
6682

6783
{{ end }}

0 commit comments

Comments
 (0)