mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-28 22:19:59 +02:00
Add emoji support
This uses the Emoji map from https://github.com/kyokomi/emoji -- but with a custom replacement implementation. The built-in are fine for most use cases, but in Hugo we do care about pure speed. The benchmarks below are skewed in Hugo's direction as the source and result is a byte slice, Kyokomi's implementation works best with strings. Curious: The easy-to-use `strings.Replacer` is also plenty fast. ``` BenchmarkEmojiKyokomiFprint-4 20000 86038 ns/op 33960 B/op 117 allocs/op BenchmarkEmojiKyokomiSprint-4 20000 83252 ns/op 38232 B/op 122 allocs/op BenchmarkEmojiStringsReplacer-4 100000 21092 ns/op 17248 B/op 25 allocs/op BenchmarkHugoEmoji-4 500000 5728 ns/op 624 B/op 13 allocs/op ``` Fixes #1891
This commit is contained in:
committed by
Cameron Moore
parent
5926c6c8d5
commit
cafb784799
@@ -1,4 +1,4 @@
|
||||
// Copyright 2015 The Hugo Authors. All rights reserved.
|
||||
// Copyright 2016 The Hugo Authors. All rights reserved.
|
||||
//
|
||||
// Portions Copyright The Go Authors.
|
||||
|
||||
@@ -1156,6 +1156,19 @@ func jsonify(v interface{}) (template.HTML, error) {
|
||||
return "", err
|
||||
}
|
||||
return template.HTML(b), nil
|
||||
|
||||
}
|
||||
|
||||
// emojify "emojifies" the given string.
|
||||
//
|
||||
// See http://www.emoji-cheat-sheet.com/
|
||||
func emojify(in interface{}) (template.HTML, error) {
|
||||
str, err := cast.ToStringE(in)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return template.HTML(helpers.Emojify([]byte(str))), nil
|
||||
}
|
||||
|
||||
func refPage(page interface{}, ref, methodName string) template.HTML {
|
||||
@@ -1715,6 +1728,7 @@ func init() {
|
||||
"dict": dictionary,
|
||||
"div": func(a, b interface{}) (interface{}, error) { return doArithmetic(a, b, '/') },
|
||||
"echoParam": returnWhenSet,
|
||||
"emojify": emojify,
|
||||
"eq": eq,
|
||||
"first": first,
|
||||
"ge": ge,
|
||||
|
Reference in New Issue
Block a user