aboutsummaryrefslogtreecommitdiffstats
path: root/templates
diff options
context:
space:
mode:
authormrsdizzie <info@mrsdizzie.com>2020-04-28 14:05:39 -0400
committerGitHub <noreply@github.com>2020-04-28 15:05:39 -0300
commit4563eb873d3d46953aeb43a1cebf3389906b0b88 (patch)
tree3d11783240910c1d515d39c644b69c5477c812d5 /templates
parent922a239079aefb78a05f1234f8883d8096f46c62 (diff)
downloadgitea-4563eb873d3d46953aeb43a1cebf3389906b0b88.tar.gz
gitea-4563eb873d3d46953aeb43a1cebf3389906b0b88.zip
Support unicode emojis and remove emojify.js (#11032)
* Support unicode emojis and remove emojify.js This PR replaces all use of emojify.js and adds unicode emoji support to various areas of gitea. This works in a few ways: First it adds emoji parsing support into gitea itself. This allows us to * Render emojis from valid alias (:smile:) * Detect unicode emojis and let us put them in their own class with proper aria-labels and styling * Easily allow for custom "emoji" * Support all emoji rendering and features without javascript * Uses plain unicode and lets the system render in appropriate emoji font * Doesn't leave us relying on external sources for updates/fixes/features That same list of emoji is also used to create a json file which replaces the part of emojify.js that populates the emoji search tribute. This file is about 35KB with GZIP turned on and I've set it to load after the page renders to not hinder page load time (and this removes loading emojify.js also) For custom "emoji" it uses a pretty simple scheme of just looking for /emojis/img/name.png where name is something a user has put in the "allowed reactions" setting we already have. The gitea reaction that was previously hard coded into a forked copy of emojify.js is included and works as a custom reaction under this method. The emoji data sourced here is from https://github.com/github/gemoji which is the gem library Github uses for their emoji rendering (and a data source for other sites). So we should be able to easily render any emoji and :alias: that Github can, removing any errors from migrated content. They also update it as well, so we can sync when there are new unicode emoji lists released. I've included a slimmed down and slightly modified forked copy of https://github.com/knq/emoji to make up our own emoji module. The code is pretty straight forward and again allows us to have a lot of flexibility in what happens. I had seen a few comments about performance in some of the other threads if we render this ourselves, but there doesn't seem to be any issue here. In a test it can parse, convert, and render 1,000 emojis inside of a large markdown table in about 100ms on my laptop (which is many more emojis than will ever be in any normal issue). This also prevents any flickering and other weirdness from using javascript to render some things while using go for others. Not included here are image fall back URLS. I don't really think they are necessary for anything new being written in 2020. However, managing the emoji ourselves would allow us to add these as a feature later on if it seems necessary. Fixes: https://github.com/go-gitea/gitea/issues/9182 Fixes: https://github.com/go-gitea/gitea/issues/8974 Fixes: https://github.com/go-gitea/gitea/issues/8953 Fixes: https://github.com/go-gitea/gitea/issues/6628 Fixes: https://github.com/go-gitea/gitea/issues/5130 * add new shared function emojiHTML * don't increase emoji size in issue title * Update templates/repo/issue/view_content/add_reaction.tmpl Co-Authored-By: 6543 <6543@obermui.de> * Support for emoji rendering in various templates * Render code and review comments as they should be * Better way to handle mail subjects * insert unicode from tribute selection * Add template helper for plain text when needed * Use existing replace function I forgot about * Don't include emoji greater than Unicode Version 12 Only include emoji and aliases in JSON * Update build/generate-emoji.go * Tweak regex slightly to really match everything including random invisible characters. Run tests for every emoji we have * final updates * code review * code review * hard code gitea custom emoji to match previous behavior * Update .eslintrc Co-Authored-By: silverwind <me@silverwind.io> * disable preempt Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Diffstat (limited to 'templates')
-rw-r--r--templates/base/footer.tmpl66
-rw-r--r--templates/base/head.tmpl10
-rw-r--r--templates/pwa/serviceworker_js.tmpl1
-rw-r--r--templates/repo/commit_page.tmpl2
-rw-r--r--templates/repo/issue/list.tmpl2
-rw-r--r--templates/repo/issue/view_content/add_reaction.tmpl10
-rw-r--r--templates/repo/issue/view_content/comments.tmpl8
-rw-r--r--templates/repo/issue/view_content/reactions.tmpl12
-rw-r--r--templates/repo/issue/view_title.tmpl2
-rw-r--r--templates/user/dashboard/feeds.tmpl14
-rw-r--r--templates/user/dashboard/issues.tmpl2
11 files changed, 32 insertions, 97 deletions
diff --git a/templates/base/footer.tmpl b/templates/base/footer.tmpl
index 083f44a368..07cbba7069 100644
--- a/templates/base/footer.tmpl
+++ b/templates/base/footer.tmpl
@@ -36,72 +36,8 @@
{{end}}
{{if .RequireTribute}}
<script src="{{StaticUrlPrefix}}/vendor/plugins/tribute/tribute.min.js"></script>
- <script>
- var issuesTribute = new Tribute({
- values: [
- {{ range .Assignees }}
- {key: '{{.Name}} {{.FullName}}', value: '{{.Name}}',
- name: '{{.Name}}', fullname: '{{.FullName}}', avatar: '{{.RelAvatarLink}}'},
- {{ end }}
- ],
- noMatchTemplate: function () { return null },
- menuItemTemplate: function (item) {
- var user = item.original;
- var item = $('<div/>')
- item.append($('<img/>', {'src': user.avatar}))
- item.append($('<span/>', {'class': 'name'}).text(user.name))
- if (user.fullname && user.fullname != '') {
- item.append($('<span/>', {'class': 'fullname'}).text(user.fullname))
- }
- return item.html();
- }
- });
- var content = document.getElementById('content');
- if (content != null) {
- issuesTribute.attach(content);
- }
- </script>
- <script>
- var emojiTribute = new Tribute({
- collection: [{
- trigger: ':',
- requireLeadingSpace: true,
- values: function (text, cb) {
- var array = emojify.emojiNames;
- var data = [];
- for(var j=0; j<array.length; j++) {
- if(array[j].indexOf(text) !== -1) {
- data.push(array[j]);
- if(data.length > 5) {
- break;
- }
- }
- }
- cb(data);
- },
- lookup: function (item) {
- return item;
- },
- selectTemplate: function (item) {
- if (typeof item === 'undefined') return null;
- return ':' + item.original + ':';
- },
- menuItemTemplate: function (item) {
- return '<img class="emoji" src="{{StaticUrlPrefix}}/vendor/plugins/emojify/images/' + item.original + '.png"/>' + item.original;
- }
- }]
- });
- var emojiInputs = document.querySelectorAll('.emoji-input');
- if (emojiInputs.length > 0) {
- emojiTribute.attach(emojiInputs);
- }
- var content = document.getElementById('content');
- if (content != null) {
- emojiTribute.attach(document.getElementById('content'));
- }
- </script>
{{end}}
- <script src="{{StaticUrlPrefix}}/vendor/plugins/emojify/emojify.custom.js"></script>
+
<script src="{{StaticUrlPrefix}}/fomantic/semantic.min.js?v={{MD5 AppVer}}"></script>
<script src="{{StaticUrlPrefix}}/js/index.js?v={{MD5 AppVer}}"></script>
{{template "custom/footer" .}}
diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl
index 2d7d737a00..0ecf6821c3 100644
--- a/templates/base/head.tmpl
+++ b/templates/base/head.tmpl
@@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
- <title>{{if .Title}}{{.Title}} - {{end}} {{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}}</title>
+ <title>{{if .Title}}{{.Title | RenderEmojiPlain}} - {{end}} {{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}} </title>
<link rel="manifest" href="{{AppSubUrl}}/manifest.json" crossorigin="use-credentials">
{{if UseServiceWorker}}
<script>
@@ -99,6 +99,14 @@
TimeoutStep: {{NotificationSettings.TimeoutStep}},
MaxTimeout: {{NotificationSettings.MaxTimeout}},
},
+ {{if .RequireTribute}}
+ tributeValues: [
+ {{ range .Assignees }}
+ {key: '{{.Name}} {{.FullName}}', value: '{{.Name}}',
+ name: '{{.Name}}', fullname: '{{.FullName}}', avatar: '{{.RelAvatarLink}}'},
+ {{ end }}
+ ],
+ {{end}}
};
</script>
<link rel="shortcut icon" href="{{StaticUrlPrefix}}/img/favicon.png">
diff --git a/templates/pwa/serviceworker_js.tmpl b/templates/pwa/serviceworker_js.tmpl
index b32f671532..edb8ba6e1d 100644
--- a/templates/pwa/serviceworker_js.tmpl
+++ b/templates/pwa/serviceworker_js.tmpl
@@ -12,7 +12,6 @@ var urlsToCache = [
'{{StaticUrlPrefix}}/js/datetimepicker.js',
'{{StaticUrlPrefix}}/vendor/plugins/codemirror/addon/mode/loadmode.js',
'{{StaticUrlPrefix}}/vendor/plugins/codemirror/mode/meta.js',
- '{{StaticUrlPrefix}}/vendor/plugins/emojify/emojify.custom.js',
'{{StaticUrlPrefix}}/vendor/plugins/jquery.minicolors/jquery.minicolors.min.js',
'{{StaticUrlPrefix}}/vendor/plugins/simplemde/simplemde.min.js',
diff --git a/templates/repo/commit_page.tmpl b/templates/repo/commit_page.tmpl
index 1cfd0944d5..2e57207460 100644
--- a/templates/repo/commit_page.tmpl
+++ b/templates/repo/commit_page.tmpl
@@ -21,7 +21,7 @@
<a class="ui floated right blue tiny button" href="{{EscapePound .SourcePath}}">
{{.i18n.Tr "repo.diff.browse_source"}}
</a>
- <h3 class="has-emoji"><span class="message-wrapper"><span class="commit-summary" title="{{.Commit.Summary}}">{{RenderCommitMessage .Commit.Message $.RepoLink $.Repository.ComposeMetas}}</span></span>{{template "repo/commit_status" .CommitStatus}}</h3>
+ <h3><span class="message-wrapper"><span class="commit-summary" title="{{.Commit.Summary}}">{{RenderCommitMessage .Commit.Message $.RepoLink $.Repository.ComposeMetas}}</span></span>{{template "repo/commit_status" .CommitStatus}}</h3>
{{if IsMultilineCommitMessage .Commit.Message}}
<pre class="commit-body">{{RenderCommitBody .Commit.Message $.RepoLink $.Repository.ComposeMetas}}</pre>
{{end}}
diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl
index 4fe0aaa00d..cebcb7da6b 100644
--- a/templates/repo/issue/list.tmpl
+++ b/templates/repo/issue/list.tmpl
@@ -211,7 +211,7 @@
</div>
{{end}}
<div class="ui {{if .IsClosed}}{{if .IsPull}}{{if .PullRequest.HasMerged}}purple{{else}}red{{end}}{{else}}red{{end}}{{else}}{{if .IsRead}}white{{else}}green{{end}}{{end}} label">#{{.Index}}</div>
- <a class="title has-emoji" href="{{$.Link}}/{{.Index}}">{{.Title}}</a>
+ <a class="title" href="{{$.Link}}/{{.Index}}">{{RenderEmoji .Title}}</a>
{{if .IsPull }}
{{if (index $.CommitStatus .PullRequest.ID)}}
diff --git a/templates/repo/issue/view_content/add_reaction.tmpl b/templates/repo/issue/view_content/add_reaction.tmpl
index 543f313f0a..e061560138 100644
--- a/templates/repo/issue/view_content/add_reaction.tmpl
+++ b/templates/repo/issue/view_content/add_reaction.tmpl
@@ -4,17 +4,11 @@
{{svg "octicon-plus-small" 16}}
{{svg "octicon-smiley" 16}}
</a>
- <div class="menu has-emoji">
+ <div class="menu">
<div class="header">{{ .ctx.i18n.Tr "repo.pick_reaction"}}</div>
<div class="divider"></div>
{{range $value := AllowedReactions}}
- {{if eq $value "hooray"}}
- <div class="item" data-content="hooray">:tada:</div>
- {{else if eq $value "laugh"}}
- <div class="item" data-content="laugh">:laughing:</div>
- {{else}}
- <div class="item" data-content="{{$value}}">:{{$value}}:</div>
- {{end}}
+ <div class="item reaction" data-content="{{$value}}">{{ReactionToEmoji $value}}</div>
{{end}}
</div>
</div>
diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl
index 635ad50e44..3859f496ec 100644
--- a/templates/repo/issue/view_content/comments.tmpl
+++ b/templates/repo/issue/view_content/comments.tmpl
@@ -404,8 +404,12 @@
</span>
</div>
<div class="ui attached segment">
- <div class="detail">
- <span class="text black has-emoji">{{.Content}}</span>
+ <div class="render-content markdown has-emoji">
+ {{if .RenderedContent}}
+ {{.RenderedContent|Str2html}}
+ {{else}}
+ <span class="no-content">{{$.i18n.Tr "repo.issues.no_content"}}</span>
+ {{end}}
</div>
</div>
</div>
diff --git a/templates/repo/issue/view_content/reactions.tmpl b/templates/repo/issue/view_content/reactions.tmpl
index b2aa9339d1..4978edf3ff 100644
--- a/templates/repo/issue/view_content/reactions.tmpl
+++ b/templates/repo/issue/view_content/reactions.tmpl
@@ -1,13 +1,7 @@
{{range $key, $value := .Reactions}}
- <a class="ui label basic{{if $value.HasUser $.ctx.SignedUserID}} blue{{end}}{{if not $.ctx.IsSigned}} disabled{{end}} has-emoji" data-title="{{$value.GetFirstUsers}}{{if gt ($value.GetMoreUserCount) 0}} {{ $.ctx.i18n.Tr "repo.reactions_more" $value.GetMoreUserCount}}{{end}}" data-content="{{ $key }}" data-action-url="{{ $.ActionURL }}">
- {{if eq $key "hooray"}}
- :tada:
- {{else if eq $key "laugh"}}
- :laughing:
- {{else}}
- :{{$key}}:
- {{end}}
- {{len $value}}
+ <a class="ui label basic{{if $value.HasUser $.ctx.SignedUserID}} blue{{end}}{{if not $.ctx.IsSigned}} disabled{{end}}" data-title="{{$value.GetFirstUsers}}{{if gt ($value.GetMoreUserCount) 0}} {{ $.ctx.i18n.Tr "repo.reactions_more" $value.GetMoreUserCount}}{{end}}" data-content="{{ $key }}" data-action-url="{{ $.ActionURL }}">
+ <span class="reaction">{{ReactionToEmoji $key}}</span>
+ <span class="reaction-count">{{len $value}}</span>
</a>
{{end}}
{{if AllowedReactions}}
diff --git a/templates/repo/issue/view_title.tmpl b/templates/repo/issue/view_title.tmpl
index db048a119c..74ed1034d7 100644
--- a/templates/repo/issue/view_title.tmpl
+++ b/templates/repo/issue/view_title.tmpl
@@ -1,7 +1,7 @@
<div class="sixteen wide column title">
<div class="ui grid">
<h1 class="twelve wide column">
- <span class="index">#{{.Issue.Index}}</span> <span id="issue-title" class="has-emoji">{{.Issue.Title}}</span>
+ <span class="index">#{{.Issue.Index}}</span> <span id="issue-title">{{RenderEmoji .Issue.Title}}</span>
<div id="edit-title-input" class="ui input" style="display: none">
<input value="{{.Issue.Title}}" maxlength="255">
</div>
diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl
index b97eda3ca5..a1b4218dc4 100644
--- a/templates/user/dashboard/feeds.tmpl
+++ b/templates/user/dashboard/feeds.tmpl
@@ -79,23 +79,23 @@
{{ $repoLink := .GetRepoLink}}
{{if $push.Commits}}
{{range $push.Commits}}
- <li><img class="img-8" src="{{$push.AvatarLink .AuthorEmail}}"> <a class="commit-id" href="{{$repoLink}}/commit/{{.Sha1}}">{{ShortSha .Sha1}}</a> <span class="text truncate light grey has-emoji">{{.Message}}</span></li>
+ <li><img class="img-8" src="{{$push.AvatarLink .AuthorEmail}}"> <a class="commit-id" href="{{$repoLink}}/commit/{{.Sha1}}">{{ShortSha .Sha1}}</a> <span class="text truncate light grey">{{.Message}}</span></li>
{{end}}
{{end}}
{{if and (gt $push.Len 1) $push.CompareURL}}<li><a href="{{AppSubUrl}}/{{$push.CompareURL}}">{{$.i18n.Tr "action.compare_commits" $push.Len}} ยป</a></li>{{end}}
</ul>
</div>
{{else if eq .GetOpType 6}}
- <span class="text truncate issue title has-emoji">{{index .GetIssueInfos 1}}</span>
+ <span class="text truncate issue title">{{index .GetIssueInfos 1 | RenderEmoji}}</span>
{{else if eq .GetOpType 7}}
- <span class="text truncate issue title has-emoji">{{index .GetIssueInfos 1}}</span>
+ <span class="text truncate issue title">{{index .GetIssueInfos 1 | RenderEmoji}}</span>
{{else if or (eq .GetOpType 10) (eq .GetOpType 21) (eq .GetOpType 22) (eq .GetOpType 23)}}
- <a href="{{.GetCommentLink}}" class="text truncate issue title has-emoji">{{.GetIssueTitle}}</a>
- <p class="text light grey has-emoji">{{index .GetIssueInfos 1}}</p>
+ <a href="{{.GetCommentLink}}" class="text truncate issue title">{{.GetIssueTitle | RenderEmoji}}</a>
+ <p class="text light grey">{{index .GetIssueInfos 1 | RenderEmoji}}</p>
{{else if eq .GetOpType 11}}
- <p class="text light grey has-emoji">{{index .GetIssueInfos 1}}</p>
+ <p class="text light grey">{{index .GetIssueInfos 1}}</p>
{{else if or (eq .GetOpType 12) (eq .GetOpType 13) (eq .GetOpType 14) (eq .GetOpType 15)}}
- <span class="text truncate issue title has-emoji">{{.GetIssueTitle}}</span>
+ <span class="text truncate issue title">{{.GetIssueTitle | RenderEmoji}}</span>
{{end}}
<p class="text italic light grey">{{TimeSince .GetCreate $.i18n.Lang}}</p>
</div>
diff --git a/templates/user/dashboard/issues.tmpl b/templates/user/dashboard/issues.tmpl
index 780c8c1257..92e87da0ab 100644
--- a/templates/user/dashboard/issues.tmpl
+++ b/templates/user/dashboard/issues.tmpl
@@ -108,7 +108,7 @@
{{if .Repo}}
<li class="item">
<div class="ui label">{{.Repo.FullName}}#{{.Index}}</div>
- <a class="title has-emoji" href="{{.HTMLURL}}">{{.Title}}</a>
+ <a class="title" href="{{.HTMLURL}}">{{RenderEmoji .Title}}</a>
{{if .IsPull}}
{{if (index $.CommitStatus .PullRequest.ID)}}