Skip to content

Commit

Permalink
feat: add optional hint/admonition icons (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxys authored Apr 30, 2022
1 parent 90cfc27 commit 7ce82f7
Show file tree
Hide file tree
Showing 25 changed files with 339 additions and 27 deletions.
1 change: 1 addition & 0 deletions .dictionary
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ Theming
Favicon[s]?
webpack
pre-processor[s]?
Asciidoc
6 changes: 3 additions & 3 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ steps:
NPM_CONFIG_LOGLEVEL: error

- name: testbuild
image: thegeeklab/hugo:0.93.2
image: thegeeklab/hugo:0.97.3
commands:
- mkdir -p exampleSite/themes/ && ln -s $(pwd)/ exampleSite/themes/hugo-geekblog
- hugo --panicOnWarning -s exampleSite/ -b http://localhost/
Expand Down Expand Up @@ -203,7 +203,7 @@ steps:
- refs/pull/**

- name: build
image: thegeeklab/hugo:0.93.2
image: thegeeklab/hugo:0.97.3
commands:
- hugo --panicOnWarning -s exampleSite/

Expand Down Expand Up @@ -285,6 +285,6 @@ depends_on:

---
kind: signature
hmac: 81346082b0ec800862167cfbe219ed2369e774b0fa15371febc103b0d30f9f09
hmac: e60db36deaaa99afbf3ab8fd17852bcfdf44813675e23fdef287e27c5f0919df

...
5 changes: 5 additions & 0 deletions exampleSite/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,8 @@ params:
geekblogImageLazyLoading: true
geekblogDarkModeDim: true
geekblogTagsToMenu: true

security:
exec:
allow:
- "^asciidoctor$"
2 changes: 1 addition & 1 deletion exampleSite/content/_includes/include-page.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
_**Example page include**_

{{< hint info >}}
{{< hint type=note >}}
**Example Shortcode**\
Shortcode used in an include page.
{{< /hint >}}
Expand Down
2 changes: 1 addition & 1 deletion exampleSite/content/posts/advanced/includes.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Attributes:

If no other options are specified, files will be rendered as Markdown using the `RenderString` [function](https://gohugo.io/functions/renderstring/).

{{< hint warning >}}
{{< hint type=important >}}
**Location of markdown files**\
If you include markdown files that should not get a menu entry, place them outside the content folder or exclude them otherwise.
{{< /hint >}}
Expand Down
46 changes: 37 additions & 9 deletions exampleSite/content/posts/advanced/shortcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ The [emojify](https://gohugo.io/functions/emojify/) function can be called direc

The [Emoji cheat sheet](http://www.emoji-cheat-sheet.com/) is a useful reference for emoji shorthand codes.

{{< hint info >}}
{{< hint type=note >}}
**Info**\
The above steps enable Unicode Standard emoji characters and sequences in Hugo, however the rendering of these glyphs depends on the browser and the platform. To style the emoji you can either use a third party emoji font or a font stack.
{{< /hint >}}
Expand Down Expand Up @@ -159,43 +159,71 @@ copious quo ad. Stet probates in duo.
## Hint

Hint shortcode can be used as hint/alerts/notification block.
There are four colors to choose: `info`, `ok`, `warning` and `danger`.

<!-- prettier-ignore -->
Attributes:

| Name | Usage | default |
| ---------------- | --------------------------------------------------------------------------------------- | --------------------- |
| type | color types to choose from | note |
| icon (optional) | custom icon to use | undefined (type name) |
| title (optional) | custom icon to use, need to be an icon from an [SVG sprite](/posts/features/icon-sets/) | undefined (type name) |

Syntax:

<!-- prettier-ignore-start -->
```tpl
{{</* hint [info|ok|warning|danger] */>}}
{{</* hint type=[note|tip|important|caution|warning] (icon=gblog_github) (title=GitHub) */>}}
**Markdown content**\
Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture.
Ornateness bland it ex enc, est yeti am bongo detract re.
Ornateness bland it ex enc, est yeti am bongo detract re.
{{</* /hint */>}}
```
<!-- prettier-ignore-end -->

### Example

{{< hint info >}}
{{< hint type=note >}}
**Markdown content**\
Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture.
Ornateness bland it ex enc, est yeti am bongo detract re.
{{< /hint >}}

{{< hint type=tip >}}
**Markdown content**\
Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture.
Ornateness bland it ex enc, est yeti am bongo detract re.
{{< /hint >}}

{{< hint ok >}}
{{< hint type=important >}}
**Markdown content**\
Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture.
Ornateness bland it ex enc, est yeti am bongo detract re.
{{< /hint >}}

{{< hint warning >}}
{{< hint type=caution >}}
**Markdown content**\
Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture.
Ornateness bland it ex enc, est yeti am bongo detract re.
{{< /hint >}}

{{< hint danger >}}
{{< hint type=warning >}}
**Markdown content**\
Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture.
Ornateness bland it ex enc, est yeti am bongo detract re.
{{< /hint >}}

Example with a custom icon and title:

<!-- prettier-ignore-start -->
<!-- spellchecker-disable -->
{{< hint type=note icon=gblog_github title=GitHub >}}
**Markdown content**\
Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture.
Ornateness bland it ex enc, est yeti am bongo detract re.
{{< /hint >}}
<!-- spellchecker-enable -->
<!-- prettier-ignore-end -->

## Icon

Simple shortcode to include icons from SVG sprites outside of menus.
Expand Down
30 changes: 30 additions & 0 deletions exampleSite/content/posts/asciidoc/admonition-icons.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
+++
title = "Admonition Icons"
date = 2020-06-22T20:00:00+02:00
+++

:icons: font

By default, the admonition is rendered with a plain text label. To enable font icons the document attribute `:icons: font` need to be set.

== Example

[NOTE]
Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture.
Ornateness bland it ex enc, est yeti am bongo detract re.

[TIP]
Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture.
Ornateness bland it ex enc, est yeti am bongo detract re.

[IMPORTANT]
Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture.
Ornateness bland it ex enc, est yeti am bongo detract re.

[CAUTION]
Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture.
Ornateness bland it ex enc, est yeti am bongo detract re.

[WARNING]
Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture.
Ornateness bland it ex enc, est yeti am bongo detract re.
73 changes: 73 additions & 0 deletions exampleSite/content/posts/asciidoc/admonitions.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
+++
title = "Admonitions"
date = 2020-06-22T20:00:00+02:00
+++

:toc:
:toclevels: 2

{{< toc >}}

== Admonition types

There are certain statements you may want to draw attention to by taking them out of the content's flow and labeling them with a priority. These are called admonitions.

```tpl
[NOTE|TIP|IMPORTANT|CAUTION|WARNING]
Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture.
Ornateness bland it ex enc, est yeti am bongo detract re.
```

=== Example

[NOTE]
Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture.
Ornateness bland it ex enc, est yeti am bongo detract re.

[TIP]
Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture.
Ornateness bland it ex enc, est yeti am bongo detract re.

[IMPORTANT]
Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture.
Ornateness bland it ex enc, est yeti am bongo detract re.

[CAUTION]
Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture.
Ornateness bland it ex enc, est yeti am bongo detract re.

[WARNING]
Dolor sit, sumo unique argument um no. Gracie nominal id xiv. Romanesque acclimates investiture.
Ornateness bland it ex enc, est yeti am bongo detract re.


== Admonition icons

Icons can be added by setting a unicode glyph or a character reference to the `tip-caption` attribute:

```text
:tip-caption: 💡

[TIP]
It's possible to use Unicode glyphs as admonition icons.
```

```text
:tip-caption: pass:[&#128293;]

[TIP]
It's possible to use Unicode glyphs as admonition icons.
```

=== Example

:tip-caption: 💡

[TIP]
It's possible to use Unicode glyphs as admonition icons.


:tip-caption: pass:[&#128293;]

[TIP]
It's possible to use Unicode glyphs as admonition icons.
7 changes: 5 additions & 2 deletions exampleSite/content/posts/usage/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ curl -L https://github.com/thegeeklab/hugo-geekblog/releases/latest/download/hug

### Option 2: Clone the GitHub repository

{{< hint info >}}
{{< hint type=note >}}
**Info**\
Keep in mind this method is not recommended and needs some extra steps to get it working.
If you want to use the Theme as submodule keep in mind that your build process need to
Expand Down Expand Up @@ -210,7 +210,7 @@ command = "command1 && command 2 && command3 && hugo"

### Subdirectories

{{< hint danger >}}
{{< hint type=important >}}
**Warning**\
As deploying Hugo sites on subdirectories is not as robust as on subdomains, we do not recommend this.
If you have a choice, using a domain/subdomain should always be the preferred solution!
Expand Down Expand Up @@ -260,3 +260,6 @@ There are a lot more things to discover. To get the most out of the Theme we hav
- [Advanced Images](/posts/post-with-images/)
- [Includes](/posts/advanced/includes/)
- [Table of Content](/posts/advanced/toc/)
- **Asciidoc**
- [Admonitions](/posts/asciidoc/admonitions/)
- [Admonition Icons](/posts/asciidoc/admonition-icons/)
17 changes: 15 additions & 2 deletions layouts/shortcodes/hint.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
<blockquote class="gblog-hint {{ .Get 0 }}">
{{ .Inner | $.Page.RenderString }}
{{ $type := default "note" (.Get "type") }}
{{ $icon := .Get "icon" }}
{{ $title := default ($type | title) (.Get "title") }}


<blockquote class="gblog-hint {{ $type | lower }}">
<div class="gblog-hint__title flex align-center">
{{- with $icon -}}
<svg class="gblog-icon {{ . }}"><use xlink:href="#{{ . }}"></use></svg>
<span>{{ $title }}</span>
{{- else -}}
<i class="fa {{ $type | lower }}" title="{{ $title }}"></i>
{{- end -}}
</div>
<div class="gblog-hint__text">{{ .Inner | $.Page.RenderString }}</div>
</blockquote>
5 changes: 5 additions & 0 deletions src/icons/check_circle_outline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/icons/dangerous.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/icons/error_outline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/icons/fire.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/icons/info_outline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions src/sass/_asciidoc.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.admonitionblock {
@each $name, $color in $hint-colors {
&.#{$name} {
border-left-color: $color;
background-color: scale-color($color, $lightness: 95%, $saturation: -30%);
color: $body-font-color;
}
}

margin: $padding-16 0;
padding: 0;

border-left: $border-4 solid var(--accent-color);
border-radius: $border-radius;

table {
margin: 0 !important;
padding: 0 !important;

tr {
border: 0 !important;
}

td {
&:first-child {
background-color: scale-color($gray-600, $alpha: -95%);
font-weight: bold;

&.icon {
.title {
display: flex;
align-items: center;
}

i.fa::after {
content: attr(title);
font-style: normal;
padding-left: $padding-24;
}

i.fa {
color: $black;
background-size: auto 90%;
background-repeat: no-repeat;
filter: invert(30%);
margin-left: -5px;
}

@each $name, $icon in $hint-icons {
i.fa.icon-#{$name} {
background-image: url(img/geekdoc-stack.svg##{$icon});
}
}
}
}

display: flex;
padding: $padding-4 $padding-16 !important;
}
}
}
Loading

0 comments on commit 7ce82f7

Please sign in to comment.