hugo-PaperMod/content/post/emoji-support.md

3.1 KiB
Raw Blame History

+++ author = "Hugo Authors" title = "Emoji Support" date = "2019-03-05" description = "Guide to emoji usage in Hugo" tags = [ "emoji", ] emoji = " :orc: :orc: :v_paw_fk1: :v_paw_fk1: :cannabis_leaf: :cannabis_leaf:" +++

Emoji can be enabled in a Hugo project in a number of ways.

The emojify function can be called directly in templates or Inline Shortcodes.

To enable emoji globally, set enableEmoji to true in your sites configuration and then you can type emoji shorthand codes directly in content files; e.g.

🙈 :see_no_evil: 🙉 :hear_no_evil: 🙊 :speak_no_evil:


The Emoji cheat sheet is a useful reference for emoji shorthand codes.


N.B. 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; e.g.

{{< highlight html >}} .emoji { font-family: Apple Color Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI Symbol,Android Emoji,EmojiSymbols; } {{< /highlight >}}


If you feel restricted by Unicode Standard emoji and want to use custom emoji the replaceRE function makes it easy to perform Static Image Replacement in Hugo.

In this example we will be using emoji from the Mutant Standard set.

  • Do not use enableEmoji in your Hugo project's configuration

  • Store the icons of the custom emoji set under /static/

  • Use the shorthand codes provided by the custom emoji set in your content files e.g. :orc:

  • In your templates execute the Image Replacement like so:

{{< highlight html >}} {{ replaceRE "(\:([a-zA-Z0-9_]*)\:)" <img class="emoji" src="/${2}.svg" alt="${1}" title="${1}"> .Content | markdownify | safeHTML }} {{< /highlight >}}

{{< css.inline >}}

{{ replaceRE "(\\ :([a-zA-Z0-9_]*)\\: )" `${1}` .Page.Params.emoji | safeHTML }}

{{< /css.inline >}}

N.B. The above RegEx captures all alphanumerics and underscores within two colon : characters (amend it according to your custom emoji set's specification).