Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support unicode emojis and remove emojify.js #11032

Merged
merged 99 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
d579c50
Support unicode emojis and remove emojify.js
mrsdizzie Apr 9, 2020
fe2bc47
add new shared function emojiHTML
silverwind Apr 13, 2020
0ede4e7
don't increase emoji size in issue title
silverwind Apr 13, 2020
6b2ce48
Update templates/repo/issue/view_content/add_reaction.tmpl
silverwind Apr 14, 2020
5a91f51
Support for emoji rendering in various templates
mrsdizzie Apr 15, 2020
4fd041c
Render code and review comments as they should be
mrsdizzie Apr 15, 2020
08c508e
Better way to handle mail subjects
mrsdizzie Apr 15, 2020
7c7c4e5
fix lint
mrsdizzie Apr 15, 2020
3224944
insert unicode from tribute selection
silverwind Apr 15, 2020
5c53378
Add template helper for plain text when needed
mrsdizzie Apr 15, 2020
f512e1a
small refactor
silverwind Apr 15, 2020
6a6705f
Use existing replace function I forgot about
mrsdizzie Apr 15, 2020
337d44f
Don't include emoji greater than Unicode Version 12
mrsdizzie Apr 15, 2020
bdd6aea
Fix regex
mrsdizzie Apr 16, 2020
6393a91
Update build/generate-emoji.go
lafriks Apr 16, 2020
7879f7c
Tweak regex slightly to really match everything including random invi…
mrsdizzie Apr 17, 2020
c2bed68
final updates
mrsdizzie Apr 17, 2020
d9ad9fc
last test fix
mrsdizzie Apr 17, 2020
f416214
code review
mrsdizzie Apr 17, 2020
4618afc
code review
mrsdizzie Apr 17, 2020
b4ca18b
hard code gitea custom emoji to match previous behavior
mrsdizzie Apr 17, 2020
40787b4
Merge branch 'master' into emoji
guillep2k Apr 18, 2020
57d4c5d
Merge branch 'master' into emoji
lafriks Apr 18, 2020
ebfb65e
Merge branch 'master' into emoji
lafriks Apr 19, 2020
17dfefc
Merge branch 'master' into emoji
lafriks Apr 19, 2020
d989ee7
Merge branch 'master' into emoji
mrsdizzie Apr 19, 2020
3ce33c7
Merge branch 'master' into emoji
guillep2k Apr 19, 2020
ff80057
test trying to add these files back
mrsdizzie Apr 20, 2020
e4793de
Merge branch 'master' into emoji
mrsdizzie Apr 20, 2020
77a41ec
attempt to remove useless frontend builds
silverwind Apr 20, 2020
9f6b7b4
Revert "attempt to remove useless frontend builds"
silverwind Apr 20, 2020
eb9c9c2
Add some debugging code to test if disk write being limited during tests
mrsdizzie Apr 21, 2020
4f0092d
more debugging
mrsdizzie Apr 21, 2020
b6ad60c
more debugging try to limit what drone does while testing
mrsdizzie Apr 21, 2020
673f31d
drone fix
mrsdizzie Apr 21, 2020
6b1123c
remove dep
mrsdizzie Apr 21, 2020
d6d0c02
try one more time
mrsdizzie Apr 21, 2020
2008ef4
fix
mrsdizzie Apr 21, 2020
db6bf37
yet more debugging
mrsdizzie Apr 21, 2020
f7e9e60
typo
mrsdizzie Apr 21, 2020
d62518b
drone testing
mrsdizzie Apr 22, 2020
41beece
typo
mrsdizzie Apr 22, 2020
8f0628f
revert debugging changes
mrsdizzie Apr 22, 2020
9c081af
change from master that got lost in rebases
mrsdizzie Apr 22, 2020
2b4bfa4
Merge branch 'master' into emoji
mrsdizzie Apr 22, 2020
147f226
formatting error
mrsdizzie Apr 22, 2020
0153bd2
Merge branch 'master' into emoji
mrsdizzie Apr 22, 2020
0304aee
Update .eslintrc
mrsdizzie Apr 22, 2020
e18f275
Merge branch 'master' into emoji
mrsdizzie Apr 23, 2020
49dfdcc
another debugging attempt
mrsdizzie Apr 23, 2020
c00a209
better way to track slow time
mrsdizzie Apr 24, 2020
d1755cb
remove debugging of debugging
mrsdizzie Apr 24, 2020
4264061
lint
mrsdizzie Apr 24, 2020
af89bc1
expand to push command
mrsdizzie Apr 24, 2020
00d5ba2
add hook logging
mrsdizzie Apr 24, 2020
0a9804e
Merge branch 'master' into emoji
mrsdizzie Apr 24, 2020
a33d6d1
one more
mrsdizzie Apr 24, 2020
81e28d2
get a better idea if gitea is really exiting after running hook
mrsdizzie Apr 24, 2020
0fb103a
Merge branch 'master' into emoji
mrsdizzie Apr 24, 2020
a0038cc
fmt
mrsdizzie Apr 24, 2020
65f7595
revert last change it doesn't work as it does on my machine
mrsdizzie Apr 24, 2020
16571c2
try different way to get time
mrsdizzie Apr 25, 2020
9bfaf86
more logging
mrsdizzie Apr 25, 2020
8adbbe7
more log
mrsdizzie Apr 25, 2020
bc43a5f
time init
mrsdizzie Apr 25, 2020
6b46b8c
trace all init calls
mrsdizzie Apr 26, 2020
c56b526
not these
mrsdizzie Apr 26, 2020
92af022
almost
mrsdizzie Apr 26, 2020
4d1cd05
less logging
mrsdizzie Apr 26, 2020
952ee78
debug
mrsdizzie Apr 26, 2020
36cd227
debug
mrsdizzie Apr 26, 2020
6fff0dd
drone
mrsdizzie Apr 26, 2020
f0d6c16
drone
mrsdizzie Apr 26, 2020
1e25d2f
more init log
mrsdizzie Apr 26, 2020
2b36fc0
less logging
mrsdizzie Apr 26, 2020
51017ab
debug
mrsdizzie Apr 26, 2020
2d369fa
debug
mrsdizzie Apr 26, 2020
54e1a8c
undo last change it was not that
mrsdizzie Apr 26, 2020
a55332b
strace
mrsdizzie Apr 26, 2020
acc19ec
trace all hooks
mrsdizzie Apr 26, 2020
0ef92ba
more trace
mrsdizzie Apr 26, 2020
c5c13ac
see if related to preemptive scheduling
mrsdizzie Apr 27, 2020
4b9e43c
lint
mrsdizzie Apr 27, 2020
7cd7afe
goproxy
mrsdizzie Apr 27, 2020
608e5ca
remove emoji init
mrsdizzie Apr 27, 2020
252787b
try again
mrsdizzie Apr 27, 2020
2490f18
fmt
mrsdizzie Apr 27, 2020
d31d7bd
really fix lint
mrsdizzie Apr 27, 2020
d4c9b75
remove some debugging code
mrsdizzie Apr 28, 2020
0c58b15
more cleanup
mrsdizzie Apr 28, 2020
144c78e
Merge branch 'master' into emoji
mrsdizzie Apr 28, 2020
080f5e6
different logging
mrsdizzie Apr 28, 2020
53e3abb
disable preempt
mrsdizzie Apr 28, 2020
8317565
more debug undoing
mrsdizzie Apr 28, 2020
cf1ec0e
Merge branch 'master' into emoji
mrsdizzie Apr 28, 2020
24545a7
more cleanup
mrsdizzie Apr 28, 2020
9ebb307
Merge branch 'master' into emoji
mrsdizzie Apr 28, 2020
3473119
delete all emojify files
mrsdizzie Apr 28, 2020
82caeb3
ci
mrsdizzie Apr 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ globals:
__webpack_public_path__: true
CodeMirror: false
Dropzone: false
emojify: false
SimpleMDE: false
u2fApi: false
Tribute: false

overrides:
- files: ["web_src/**/*.worker.js"]
Expand Down
1 change: 1 addition & 0 deletions assets/emoji.json

Large diffs are not rendered by default.

184 changes: 184 additions & 0 deletions build/generate-emoji.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// Copyright 2015 Kenneth Shaw
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

// +build ignore

package main

import (
"encoding/json"
"flag"
"fmt"
"go/format"
"io/ioutil"
"log"
"net/http"
"regexp"
"sort"
"strconv"
"strings"
)

const (
gemojiURL = "https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json"
maxUnicodeVersion = 12
)

var (
flagOut = flag.String("o", "modules/emoji/emoji_data.go", "out")
)

// Gemoji is a set of emoji data.
type Gemoji []Emoji
lafriks marked this conversation as resolved.
Show resolved Hide resolved

// Emoji represents a single emoji and associated data.
type Emoji struct {
Emoji string `json:"emoji"`
Description string `json:"description,omitempty"`
Aliases []string `json:"aliases"`
UnicodeVersion string `json:"unicode_version,omitempty"`
}

// Don't include some fields in JSON
func (e Emoji) MarshalJSON() ([]byte, error) {
type emoji Emoji
x := emoji(e)
x.UnicodeVersion = ""
x.Description = ""
return json.Marshal(x)
}

func main() {
var err error

flag.Parse()

// generate data
buf, err := generate()
if err != nil {
log.Fatal(err)
}

// write
err = ioutil.WriteFile(*flagOut, buf, 0644)
if err != nil {
log.Fatal(err)
}
}

var replacer = strings.NewReplacer(
"main.Gemoji", "Gemoji",
"main.Emoji", "\n",
"}}", "},\n}",
", Description:", ", ",
", Aliases:", ", ",
", UnicodeVersion:", ", ",
)

var emojiRE = regexp.MustCompile(`\{Emoji:"([^"]*)"`)

func generate() ([]byte, error) {
var err error

// load gemoji data
res, err := http.Get(gemojiURL)
if err != nil {
return nil, err
}
defer res.Body.Close()

// read all
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
}

// unmarshal
var data Gemoji
err = json.Unmarshal(body, &data)
if err != nil {
return nil, err
}

var re = regexp.MustCompile(`keycap|registered|copyright`)
tmp := data[:0]

// filter out emoji that require greater than max unicode version
for i := range data {
val, _ := strconv.ParseFloat(data[i].UnicodeVersion, 64)
if int(val) <= maxUnicodeVersion {
// remove these keycaps for now they really complicate matching since
// they include normal letters in them
if re.MatchString(data[i].Description) {
continue
}
tmp = append(tmp, data[i])
}
}
data = tmp

sort.Slice(data, func(i, j int) bool {
return data[i].Aliases[0] < data[j].Aliases[0]
})

aliasPairs := make([]string, 0)
aliasMap := make(map[string]int, len(data))

for i, e := range data {
if e.Emoji == "" || len(e.Aliases) == 0 {
continue
}
for _, a := range e.Aliases {
if a == "" {
continue
}
aliasMap[a] = i
aliasPairs = append(aliasPairs, ":"+a+":", e.Emoji)
}
}

// gitea customizations
i, ok := aliasMap["tada"]
if ok {
data[i].Aliases = append(data[i].Aliases, "hooray")
}
i, ok = aliasMap["laughing"]
if ok {
data[i].Aliases = append(data[i].Aliases, "laugh")
}

// add header
str := replacer.Replace(fmt.Sprintf(hdr, gemojiURL, data))

// change the format of the unicode string
str = emojiRE.ReplaceAllStringFunc(str, func(s string) string {
var err error
s, err = strconv.Unquote(s[len("{Emoji:"):])
if err != nil {
panic(err)
}
return "{" + strconv.QuoteToASCII(s)
})

// write a JSON file to use with tribute
file, _ := json.Marshal(data)
_ = ioutil.WriteFile("assets/emoji.json", file, 0644)

// format
return format.Source([]byte(str))
}

const hdr = `
// Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package emoji

// Code generated by gen.go. DO NOT EDIT.
// Sourced from %s
//
var GemojiData = %#v
`
5 changes: 3 additions & 2 deletions custom/conf/app.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ SHOW_USER_EMAIL = true
DEFAULT_THEME = gitea
; All available themes. Allow users select personalized themes regardless of the value of `DEFAULT_THEME`.
mrsdizzie marked this conversation as resolved.
Show resolved Hide resolved
THEMES = gitea,arc-green
; All available reactions. Allow users react with different emoji's
; For the whole list look at https://gitea.com/gitea/gitea.com/issues/8
;All available reactions users can choose on issues/prs and comments.
mrsdizzie marked this conversation as resolved.
Show resolved Hide resolved
;Values can be emoji alias (:smile:) or a unicode emoji.
;For custom reactions, add a tightly cropped square image to public/emoji/img/reaction_name.png
REACTIONS = +1, -1, laugh, hooray, confused, heart, rocket, eyes
; Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used.
DEFAULT_SHOW_FULL_NAME = false
Expand Down
4 changes: 3 additions & 1 deletion docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
- `DEFAULT_THEME`: **gitea**: \[gitea, arc-green\]: Set the default theme for the Gitea install.
- `THEMES`: **gitea,arc-green**: All available themes. Allow users select personalized themes
mrsdizzie marked this conversation as resolved.
Show resolved Hide resolved
regardless of the value of `DEFAULT_THEME`.
- `REACTIONS`: All available reactions. Allow users react with different emoji's.
- `REACTIONS`: All available reactions users can choose on issues/prs and comments
mrsdizzie marked this conversation as resolved.
Show resolved Hide resolved
Values can be emoji alias (:smile:) or a unicode emoji.
For custom reactions, add a tightly cropped square image to public/emoji/img/reaction_name.png
- `DEFAULT_SHOW_FULL_NAME`: **false**: Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used.
- `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page.
- `USE_SERVICE_WORKER`: **true**: Whether to enable a Service Worker to cache frontend assets.
Expand Down
1 change: 0 additions & 1 deletion docs/content/page/index.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ Windows, on architectures like amd64, i386, ARM, PowerPC, and others.
* [DropzoneJS](http://www.dropzonejs.com/)
* [Highlight](https://highlightjs.org/)
* [Clipboard](https://zenorocha.github.io/clipboard.js/)
* [Emojify](https://github.com/Ranks/emojify.js)
* [CodeMirror](https://codemirror.net/)
* [jQuery Date Time Picker](https://github.com/xdan/datetimepicker)
* [jQuery MiniColors](https://github.com/claviska/jquery-minicolors)
Expand Down
1 change: 0 additions & 1 deletion docs/content/page/index.fr-fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ Le but de ce projet est de fournir de la manière la plus simple, la plus rapide
* [DropzoneJS](http://www.dropzonejs.com/)
* [Highlight](https://highlightjs.org/)
* [Clipboard](https://zenorocha.github.io/clipboard.js/)
* [Emojify](https://github.com/Ranks/emojify.js)
* [CodeMirror](https://codemirror.net/)
* [jQuery Date Time Picker](https://github.com/xdan/datetimepicker)
* [jQuery MiniColors](https://github.com/claviska/jquery-minicolors)
Expand Down
1 change: 0 additions & 1 deletion docs/content/page/index.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Gitea的首要目标是创建一个极易安装,运行非常快速,安装和
* [DropzoneJS](http://www.dropzonejs.com/)
* [Highlight](https://highlightjs.org/)
* [Clipboard](https://zenorocha.github.io/clipboard.js/)
* [Emojify](https://github.com/Ranks/emojify.js)
* [CodeMirror](https://codemirror.net/)
* [jQuery Date Time Picker](https://github.com/xdan/datetimepicker)
* [jQuery MiniColors](https://github.com/claviska/jquery-minicolors)
Expand Down
1 change: 0 additions & 1 deletion docs/content/page/index.zh-tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Gitea 的首要目標是建立一個容易安裝,運行快速,安装和使
* [DropzoneJS](http://www.dropzonejs.com/)
* [Highlight](https://highlightjs.org/)
* [Clipboard](https://zenorocha.github.io/clipboard.js/)
* [Emojify](https://github.com/Ranks/emojify.js)
* [CodeMirror](https://codemirror.net/)
* [jQuery Date Time Picker](https://github.com/xdan/datetimepicker)
* [jQuery MiniColors](https://github.com/claviska/jquery-minicolors)
Expand Down
119 changes: 119 additions & 0 deletions modules/emoji/emoji.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// Copyright 2015 Kenneth Shaw
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package emoji

import (
"strings"
"sync"
)

// Gemoji is a set of emoji data.
type Gemoji []Emoji

// Emoji represents a single emoji and associated data.
type Emoji struct {
Emoji string
Description string
Aliases []string
UnicodeVersion string
}

var (
// codeMap provides a map of the emoji unicode code to its emoji data.
codeMap map[string]int

// aliasMap provides a map of the alias to its emoji data.
aliasMap map[string]int

// codeReplacer is the string replacer for emoji codes.
codeReplacer *strings.Replacer

// aliasReplacer is the string replacer for emoji aliases.
aliasReplacer *strings.Replacer

once sync.Once
)

func loadMap() {

once.Do(func() {

// initialize
codeMap = make(map[string]int, len(GemojiData))
aliasMap = make(map[string]int, len(GemojiData))

// process emoji codes and aliases
codePairs := make([]string, 0)
aliasPairs := make([]string, 0)
for i, e := range GemojiData {
if e.Emoji == "" || len(e.Aliases) == 0 {
continue
}

// setup codes
codeMap[e.Emoji] = i
codePairs = append(codePairs, e.Emoji, ":"+e.Aliases[0]+":")

// setup aliases
for _, a := range e.Aliases {
if a == "" {
continue
}

aliasMap[a] = i
aliasPairs = append(aliasPairs, ":"+a+":", e.Emoji)
}
}

// create replacers
codeReplacer = strings.NewReplacer(codePairs...)
aliasReplacer = strings.NewReplacer(aliasPairs...)
})
}

// FromCode retrieves the emoji data based on the provided unicode code (ie,
// "\u2618" will return the Gemoji data for "shamrock").
func FromCode(code string) *Emoji {
loadMap()
i, ok := codeMap[code]
if !ok {
return nil
}

return &GemojiData[i]
}

// FromAlias retrieves the emoji data based on the provided alias in the form
// "alias" or ":alias:" (ie, "shamrock" or ":shamrock:" will return the Gemoji
// data for "shamrock").
func FromAlias(alias string) *Emoji {
loadMap()
if strings.HasPrefix(alias, ":") && strings.HasSuffix(alias, ":") {
alias = alias[1 : len(alias)-1]
}

i, ok := aliasMap[alias]
if !ok {
return nil
}

return &GemojiData[i]
}

// ReplaceCodes replaces all emoji codes with the first corresponding emoji
// alias (in the form of ":alias:") (ie, "\u2618" will be converted to
// ":shamrock:").
func ReplaceCodes(s string) string {
loadMap()
return codeReplacer.Replace(s)
}

// ReplaceAliases replaces all aliases of the form ":alias:" with its
// corresponding unicode value.
func ReplaceAliases(s string) string {
loadMap()
return aliasReplacer.Replace(s)
}
Loading