Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,30 @@ icon:
---
```

##### Highlighting Important Content

> [!NOTE]
> 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)).

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`

```
> [!NOTE]
> Useful information that users should know, even when skimming content.

> [!TIP]
> Helpful advice for doing things better or more easily.

> [!IMPORTANT]
> Key information users need to know to achieve their goal.

> [!WARNING]
> Urgent info that needs immediate user attention to avoid problems.

> [!CAUTION]
> Advises about risks or negative outcomes.
```

#### Layouts
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`.

Expand Down
28 changes: 28 additions & 0 deletions site/layouts/_default/_markup/render-blockquote.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{ $emojis := dict
"caution" ":bangbang:"
"important" ":information_source:"
"note" ":memo:"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@psiinon I changed the emoji for "note" from 📄 to 📝. I was thinking the latter looks more colourful and is more noticeable (matches the other icons better, I think).

callouts_changed emoji

"tip" ":bulb:"
"warning" ":warning:"
}}

{{ if eq .Type "alert" }}
<blockquote class="alert alert-{{ .AlertType }}">
<p class="alert-heading">
{{ transform.Emojify (index $emojis .AlertType) }}
{{ with .AlertTitle }}
{{ . }}
{{ else }}
{{ or (i18n .AlertType) (title .AlertType) }}
{{ end }}
</p>

<div class="alert-content">
{{ .Text }}
</div>
</blockquote>
{{ else }}
<blockquote>
{{ .Text }}
</blockquote>
{{ end }}
55 changes: 55 additions & 0 deletions src/css/_page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,58 @@ article {
#content-wrap {
padding-bottom: var(--footer-height);
}

/* Styles for blockquote alerts, aka admonitions or callouts */
// Source: https://github.com/KKKZOZ/hugo-admonitions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason not to use the module instead of c/p?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not especially. There are several more types of callouts in the module and definitely more robust styling. However, I was just looking to add the most basic types.

Note that the template itself is from an example in the Hugo docs (only a couple of lines changed). It's just the CSS I copied from the module (one line changed).

Do you suggest adding the module directly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kingthorin I replied @thc202 earlier. My comment is supposed to be up there just before yours, although I added it using the mobile app. Maybe that's why it's not showing up? Anyway, here it is again:

Not especially. There are several more types of callouts in the module and definitely more robust styling. However, I was just looking to add the most basic types.

Note that the template itself is from an example in the Hugo docs (only a couple of lines changed). It's just the CSS I copied from the module (one line changed).

Do you suggest adding the module directly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be preferable than duplicate functionality IMHO.


// Alert colors
$alert-colors: (
caution: #e64553,
important: #7D4DDA,
note: #096ae1,
tip: #179299,
warning: #df8e1d
);

// Base alert styles
.alert {
margin: 1rem 0;
border-radius: 4px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
border-left-width: 4px;
border-left-style: solid;
padding: 0.8rem 1rem;
background: rgba(0, 0, 0, 0.05);
font-size: 1rem;

p {
margin: 0;
}
}

// Alert headers
.alert-heading {
font-weight: bold;
font-size: 1.1rem;
display: flex;
align-items: center;
gap: 0.5rem;
}

// Alert content
.alert-content > p {
padding-top: 0.5rem;;
}

// Generate alert types
@each $type, $color in $alert-colors {
.alert-#{$type} {
border-left-color: $color;

.alert-heading {
color: $color;
}
}
}

/* END Styles for blockquote alerts */