Skip to content

Commit 62b5cfe

Browse files
authored
Merge pull request #2977 from Wryhder/alert-template
Add a template for blockquote alerts (aka callouts)
2 parents 3d6725a + 9cfb05e commit 62b5cfe

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,30 @@ icon:
117117
---
118118
```
119119

120+
##### Highlighting Important Content
121+
122+
> [!NOTE]
123+
> You can highlight important information in your articles or docs using different types of callouts (also known as admonitions – or alerts, as used in [the Hugo docs](https://gohugo.io/render-hooks/blockquotes/#alerts)).
124+
125+
The examples below use the same syntax as in Github Markdown. The template responsible for rendering them is at `site/layouts/_default/_markup/render-blockquote.html`
126+
127+
```
128+
> [!NOTE]
129+
> Useful information that users should know, even when skimming content.
130+
131+
> [!TIP]
132+
> Helpful advice for doing things better or more easily.
133+
134+
> [!IMPORTANT]
135+
> Key information users need to know to achieve their goal.
136+
137+
> [!WARNING]
138+
> Urgent info that needs immediate user attention to avoid problems.
139+
140+
> [!CAUTION]
141+
> Advises about risks or negative outcomes.
142+
```
143+
120144
#### Layouts
121145
For controlling what HTML is rendered, you need to work with the site templates. In the directory, `site/layouts/`, you'll find a number of HTML files with various template tags. The first file to check out is `site/layouts/_default/baseof.html` - this is the base layout Hugo uses to build your site that templates extend. Hugo has a lookup order for associating a content entry to a template. A single entry whose type is post (`type: post`), Hugo will look for a layout in `site/layouts/post/single.html`, and if that does not exist, it will fallback to `site/layouts/_default/single.html`.
122146

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{{ $emojis := dict
2+
"caution" ":bangbang:"
3+
"important" ":information_source:"
4+
"note" ":memo:"
5+
"tip" ":bulb:"
6+
"warning" ":warning:"
7+
}}
8+
9+
{{ if eq .Type "alert" }}
10+
<blockquote class="alert alert-{{ .AlertType }}">
11+
<p class="alert-heading">
12+
{{ transform.Emojify (index $emojis .AlertType) }}
13+
{{ with .AlertTitle }}
14+
{{ . }}
15+
{{ else }}
16+
{{ or (i18n .AlertType) (title .AlertType) }}
17+
{{ end }}
18+
</p>
19+
20+
<div class="alert-content">
21+
{{ .Text }}
22+
</div>
23+
</blockquote>
24+
{{ else }}
25+
<blockquote>
26+
{{ .Text }}
27+
</blockquote>
28+
{{ end }}

src/css/_page.scss

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,58 @@ article {
117117
#content-wrap {
118118
padding-bottom: var(--footer-height);
119119
}
120+
121+
/* Styles for blockquote alerts, aka admonitions or callouts */
122+
// Source: https://github.com/KKKZOZ/hugo-admonitions
123+
124+
// Alert colors
125+
$alert-colors: (
126+
caution: #e64553,
127+
important: #7D4DDA,
128+
note: #096ae1,
129+
tip: #179299,
130+
warning: #df8e1d
131+
);
132+
133+
// Base alert styles
134+
.alert {
135+
margin: 1rem 0;
136+
border-radius: 4px;
137+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
138+
border-left-width: 4px;
139+
border-left-style: solid;
140+
padding: 0.8rem 1rem;
141+
background: rgba(0, 0, 0, 0.05);
142+
font-size: 1rem;
143+
144+
p {
145+
margin: 0;
146+
}
147+
}
148+
149+
// Alert headers
150+
.alert-heading {
151+
font-weight: bold;
152+
font-size: 1.1rem;
153+
display: flex;
154+
align-items: center;
155+
gap: 0.5rem;
156+
}
157+
158+
// Alert content
159+
.alert-content > p {
160+
padding-top: 0.5rem;;
161+
}
162+
163+
// Generate alert types
164+
@each $type, $color in $alert-colors {
165+
.alert-#{$type} {
166+
border-left-color: $color;
167+
168+
.alert-heading {
169+
color: $color;
170+
}
171+
}
172+
}
173+
174+
/* END Styles for blockquote alerts */

0 commit comments

Comments
 (0)