diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-02-25 02:52:11 +0300 |
---|---|---|
committer | Cameron Moore <moorereason@gmail.com> | 2016-03-12 00:51:37 +0300 |
commit | cafb784799e2e09df7345ca1d7cfcfae4d1b7aa2 (patch) | |
tree | 1201fcb64fb2dd74a2f846cd2d008bba5a48a298 /hugolib/handler_page.go | |
parent | 5926c6c8d5ae950a0ea2ef6492b1e03095b60574 (diff) |
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
Diffstat (limited to 'hugolib/handler_page.go')
-rw-r--r-- | hugolib/handler_page.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/hugolib/handler_page.go b/hugolib/handler_page.go index cc8ac6bb1..ae429d151 100644 --- a/hugolib/handler_page.go +++ b/hugolib/handler_page.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Hugo Authors. All rights reserved. +// Copyright 2016 The Hugo Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ import ( "github.com/spf13/hugo/source" "github.com/spf13/hugo/tpl" jww "github.com/spf13/jwalterweatherman" + "github.com/spf13/viper" ) func init() { @@ -114,6 +115,10 @@ func commonConvert(p *Page, t tpl.Template) HandledResult { var err error + if viper.GetBool("EnableEmoji") { + p.rawContent = helpers.Emojify(p.rawContent) + } + renderedContent := p.renderContent(helpers.RemoveSummaryDivider(p.rawContent)) if len(p.contentShortCodes) > 0 { |