From b918609acc11d2deb1dd2182597c7cbb3624dbdb Mon Sep 17 00:00:00 2001
From: Cirno the Strongest <1447794+CirnoT@users.noreply.github.com>
Date: Sun, 28 Jun 2020 06:05:50 +0200
Subject: [PATCH] Use custom SVGs for commit signing lock icon (#12017)

* Use custom SVGs for commit signing lock icon

* missing spans

* editorconfig

* xmlns and remove aria-hidden

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
---
 .editorconfig                    | 3 +++
 assets/svg/gitea-lock-cog.svg    | 4 ++++
 assets/svg/gitea-lock.svg        | 3 +++
 assets/svg/gitea-unlock.svg      | 3 +++
 templates/repo/commit_page.tmpl  | 9 +++------
 templates/repo/shabox_badge.tmpl | 9 +++------
 web_src/less/_repository.less    | 6 +++++-
 webpack.config.js                | 5 ++++-
 8 files changed, 28 insertions(+), 14 deletions(-)
 create mode 100644 assets/svg/gitea-lock-cog.svg
 create mode 100644 assets/svg/gitea-lock.svg
 create mode 100644 assets/svg/gitea-unlock.svg

diff --git a/.editorconfig b/.editorconfig
index 5b3a4ff79..6059fa100 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -23,3 +23,6 @@ indent_size = 2
 
 [Makefile]
 indent_style = tab
+
+[*.svg]
+insert_final_newline = false
diff --git a/assets/svg/gitea-lock-cog.svg b/assets/svg/gitea-lock-cog.svg
new file mode 100644
index 000000000..13e374a9d
--- /dev/null
+++ b/assets/svg/gitea-lock-cog.svg
@@ -0,0 +1,4 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="14" height="16" viewBox="0 0 14 16">
+  <path d="M12.5 7h-.75V4.75C11.75 2.131 9.619 0 7 0S2.25 2.131 2.25 4.75V7H1.5A1.5 1.5 0 000 8.5v6A1.5 1.5 0 001.5 16h11a1.5 1.5 0 001.5-1.5v-6A1.5 1.5 0 0012.5 7zM9.25 7h-4.5V4.75C4.75 3.51 5.76 2.5 7 2.5s2.25 1.01 2.25 2.25z"/>
+  <path d="M6.433 10.244q-.508.237-.7.765-.192.527.045 1.036.237.508.764.7.528.192 1.036-.045.509-.237.7-.765.193-.527-.044-1.036-.237-.508-.765-.7-.528-.192-1.036.045zM4.765 8.032l1.065-.497q.057-.027.128-.013.07.014.107.067l.548.825q.302-.03.524-.017.162-.28.423-.822.035-.074.097-.103.063-.03.13-.009.239.047.74.234.502.186.551.292.027.057.015.145l-.21.903q.21.16.386.352.689-.228.958-.277.15-.03.214.11l.497 1.065q.031.067.014.136-.017.07-.077.103l-.82.546q.032.271.023.515l.83.437q.065.027.098.1.032.067.003.144-.265.86-.436 1.167-.033.056-.095.085-.058.027-.128.013-.135-.025-.433-.096-.3-.07-.46-.1-.179.24-.382.417l.28.938q.019.067-.014.13-.032.061-.094.09l-1.065.497q-.058.026-.128.013-.071-.014-.105-.062l-.55-.83q-.253.036-.53.019-.183.32-.422.822-.035.074-.093.101-.048.023-.13.009-.231-.045-.736-.233-.505-.187-.554-.293-.03-.062-.01-.147l.204-.901q-.209-.16-.386-.352-.688.228-.957.277-.15.03-.215-.11l-.496-1.065q-.032-.067-.014-.136.017-.07.077-.104l.82-.545q-.033-.271-.024-.515l-.83-.442q-.064-.023-.098-.095-.029-.062-.008-.142.283-.885.447-1.172.023-.051.09-.082.057-.027.128-.014.134.026.433.096.299.071.459.102.182-.237.378-.416l-.275-.94q-.02-.067.013-.13.033-.061.095-.09z" fill="#fff" fill-rule="evenodd" stroke-width=".2"/>
+</svg>
\ No newline at end of file
diff --git a/assets/svg/gitea-lock.svg b/assets/svg/gitea-lock.svg
new file mode 100644
index 000000000..2511b9433
--- /dev/null
+++ b/assets/svg/gitea-lock.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="14" height="16" viewBox="0 0 14 16">
+  <path d="M12.5 7h-.75V4.75A4.756 4.756 0 007 0a4.756 4.756 0 00-4.75 4.75V7H1.5A1.5 1.5 0 000 8.5v6A1.5 1.5 0 001.5 16h11a1.5 1.5 0 001.5-1.5v-6A1.5 1.5 0 0012.5 7zM9.25 7h-4.5V4.75C4.75 3.51 5.76 2.5 7 2.5s2.25 1.01 2.25 2.25z"/>
+</svg>
\ No newline at end of file
diff --git a/assets/svg/gitea-unlock.svg b/assets/svg/gitea-unlock.svg
new file mode 100644
index 000000000..afaa9f03d
--- /dev/null
+++ b/assets/svg/gitea-unlock.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="14" height="16" viewBox="0 0 14 16">
+  <path d="M12.5 8H4.75V4.778c0-1.237.99-2.265 2.228-2.278A2.253 2.253 0 019.25 4.75v.5c0 .416.334.75.75.75h1c.416 0 .75-.334.75-.75v-.5c0-2.625-2.14-4.76-4.766-4.75C4.36.01 2.25 2.172 2.25 4.797V8H1.5A1.5 1.5 0 000 9.5v5A1.5 1.5 0 001.5 16h11a1.5 1.5 0 001.5-1.5v-5A1.5 1.5 0 0012.5 8z"/>
+</svg>
\ No newline at end of file
diff --git a/templates/repo/commit_page.tmpl b/templates/repo/commit_page.tmpl
index 51f56574c..f9e8c4acb 100644
--- a/templates/repo/commit_page.tmpl
+++ b/templates/repo/commit_page.tmpl
@@ -90,7 +90,7 @@
 			<div class="ui bottom attached message {{$class}}">
 				{{if .Verification.Verified }}
 					{{if ne .Verification.SigningUser.ID 0}}
-						<i class="lock icon"></i>
+						{{svg "gitea-lock" 16}}
 						{{if eq .Verification.TrustStatus "trusted"}}
 							<span class="ui text">{{.i18n.Tr "repo.commits.signed_by"}}:</span>
 						{{else if eq .Verification.TrustStatus "untrusted"}}
@@ -102,17 +102,14 @@
 						<a href="{{.Verification.SigningUser.HomeLink}}"><strong>{{.Verification.SigningUser.Name}}</strong> <{{.Verification.SigningEmail}}></a>
 						<span class="pull-right"><span class="ui text">{{.i18n.Tr "repo.commits.gpg_key_id"}}:</span> {{.Verification.SigningKey.KeyID}}</span>
 					{{else}}
-						<i class="icons" title="{{.i18n.Tr "gpg.default_key"}}">
-							<i class="lock icon"></i>
-							<i class="tiny inverted cog icon centerlock"></i>
-						</i>
+						<span title="{{.i18n.Tr "gpg.default_key"}}">{{svg "gitea-lock-cog" 16}}</span>
 						<span class="ui text">{{.i18n.Tr "repo.commits.signed_by"}}:</span>
 						<img class="ui avatar image" src="{{AvatarLink .Verification.SigningEmail}}" />
 						<strong>{{.Verification.SigningUser.Name}}</strong> <{{.Verification.SigningEmail}}>
 						<span class="pull-right"><span class="ui text">{{.i18n.Tr "repo.commits.gpg_key_id"}}:</span> <i class="cogs icon" title="{{.i18n.Tr "gpg.default_key"}}"></i>{{.Verification.SigningKey.KeyID}}</span>
 					{{end}}
 				{{else if .Verification.Warning}}
-					<i class="unlock icon"></i>
+					{{svg "gitea-unlock" 16}}
 					<span class="ui text">{{.i18n.Tr .Verification.Reason}}</span>
 					<span class="pull-right"><span class="ui text">{{.i18n.Tr "repo.commits.gpg_key_id"}}:</span> <i class="warning icon"></i>{{.Verification.SigningKey.KeyID}}</span>
 				{{else}}
diff --git a/templates/repo/shabox_badge.tmpl b/templates/repo/shabox_badge.tmpl
index f4bd30fdb..f46b52004 100644
--- a/templates/repo/shabox_badge.tmpl
+++ b/templates/repo/shabox_badge.tmpl
@@ -2,17 +2,14 @@
 	{{if .verification.Verified}}
 		<div title="{{if eq .verification.TrustStatus "trusted"}}{{else if eq .verification.TrustStatus "untrusted"}}{{$.root.i18n.Tr "repo.commits.signed_by_untrusted_user"}}: {{else}}{{$.root.i18n.Tr "repo.commits.signed_by_untrusted_user_unmatched"}}: {{end}}{{.verification.Reason}}">
 		{{if ne .verification.SigningUser.ID 0}}
-			<i class="lock icon"></i>
+			{{svg "gitea-lock" 16}}
 			<img class="ui signature avatar image" src="{{.verification.SigningUser.RelAvatarLink}}" />
 		{{else}}
-			<i title="{{.verification.Reason}}" class="icons">
-				<i class="lock icon"></i>
-				<i class="tiny inverted cog icon centerlock"></i>
-			</i>
+			<span title="{{$.root.i18n.Tr "gpg.default_key"}}">{{svg "gitea-lock-cog" 16}}</span>
 			<img class="ui signature avatar image" src="{{AvatarLink .verification.SigningEmail}}" />
 		{{end}}
 		</div>
 	{{else}}
-		<i title="{{$.root.i18n.Tr .verification.Reason}}" class="unlock icon"></i>
+		<span title="{{$.root.i18n.Tr .verification.Reason}}">{{svg "gitea-unlock" 16}}</span>
 	{{end}}
 </div>
diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less
index 2fd67b66f..b26f0fa88 100644
--- a/web_src/less/_repository.less
+++ b/web_src/less/_repository.less
@@ -1484,8 +1484,12 @@
                 margin-right: 0;
             }
 
+            .svg {
+                margin: 0 .25em 0 0;
+            }
+
             > div {
-                display: inline-flex;
+                display: flex;
                 align-items: center;
             }
         }
diff --git a/webpack.config.js b/webpack.config.js
index fa96f42e9..7b917cbdc 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -50,7 +50,10 @@ module.exports = {
     serviceworker: [
       resolve(__dirname, 'web_src/js/serviceworker.js'),
     ],
-    icons: glob('node_modules/@primer/octicons/build/svg/**/*.svg'),
+    icons: [
+      ...glob('node_modules/@primer/octicons/build/svg/**/*.svg'),
+      ...glob('assets/svg/*.svg'),
+    ],
     ...themes,
   },
   devtool: false,