Skip to content

Commit 48ad76c

Browse files
authored
Fix repolist icons (#12228)
Fixes: #12226
1 parent a60f506 commit 48ad76c

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

templates/user/dashboard/repolist.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@
6161
<a @click="togglePrivateFilter()">
6262
<div class="ui checkbox" id="privateFilterCheckbox" title="{{.i18n.Tr "home.show_both_private_public"}}" v-if="privateFilter === 'both'">
6363
<input type="checkbox">
64-
<label><svg class="svg octicon-lock" width="16" height="16" aria-hidden="true"><use xlink:href="#octicon-lock" /></svg>{{.i18n.Tr "home.show_private"}}</label>
64+
<label>{{svg "octicon-lock" 16}}{{.i18n.Tr "home.show_private"}}</label>
6565
</div>
6666
<div class="ui checkbox" id="privateFilterCheckbox" title="{{.i18n.Tr "home.show_only_public"}}" v-if="privateFilter === 'public'">
6767
<input type="checkbox">
68-
<label><svg class="svg octicon-lock" width="16" height="16" aria-hidden="true"><use xlink:href="#octicon-lock" /></svg>{{.i18n.Tr "home.show_private"}}</label>
68+
<label>{{svg "octicon-lock" 16}}</svg>{{.i18n.Tr "home.show_private"}}</label>
6969
</div>
7070
<div class="ui checkbox" id="privateFilterCheckbox" title="{{.i18n.Tr "home.show_only_private"}}" v-if="privateFilter === 'private'">
7171
<input type="checkbox">
72-
<label><svg class="svg octicon-lock" width="16" height="16" aria-hidden="true"><use xlink:href="#octicon-lock" /></svg>{{.i18n.Tr "home.show_private"}}</label>
72+
<label>{{svg "octicon-lock" 16}}</svg>{{.i18n.Tr "home.show_private"}}</label>
7373
</div>
7474
</a>
7575
</div>
@@ -103,7 +103,7 @@
103103
<ul class="repo-owner-name-list">
104104
<li v-for="repo in repos" :class="{'private': repo.private || repo.internal}">
105105
<a :href="suburl + '/' + repo.full_name">
106-
<svg :class="'svg ' + repoClass(repo)" width="16" height="16" aria-hidden="true"><use :xlink:href="'#' + repoClass(repo)" /></svg>
106+
<component v-bind:is="repoIcon(repo)" size="16"></component>
107107
<strong class="text truncate item-name">${repo.full_name}</strong>
108108
<i v-if="repo.archived" class="archive icon archived-icon"></i>
109109
<span class="ui right text light grey">

web_src/js/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import initTableSort from './features/tablesort.js';
1919
import ActivityTopAuthors from './components/ActivityTopAuthors.vue';
2020
import {initNotificationsTable, initNotificationCount} from './features/notification.js';
2121
import {createCodeEditor} from './features/codeeditor.js';
22+
import {svgs} from './svg.js';
2223

2324
const {AppSubUrl, StaticUrlPrefix, csrf} = window.config;
2425

@@ -2625,6 +2626,15 @@ function linkEmailAction(e) {
26252626
}
26262627

26272628
function initVueComponents() {
2629+
// register svg icon vue components, e.g. <octicon-repo size="16"/>
2630+
for (const [name, htmlString] of Object.entries(svgs)) {
2631+
const template = htmlString
2632+
.replace(/height="[0-9]+"/, 'v-bind:height="size"')
2633+
.replace(/width="[0-9]+"/, 'v-bind:width="size"');
2634+
2635+
Vue.component(name, {props: ['size'], template});
2636+
}
2637+
26282638
const vueDelimeters = ['${', '}'];
26292639

26302640
Vue.component('repo-search', {
@@ -2950,7 +2960,7 @@ function initVueComponents() {
29502960
});
29512961
},
29522962

2953-
repoClass(repo) {
2963+
repoIcon(repo) {
29542964
if (repo.fork) {
29552965
return 'octicon-repo-forked';
29562966
} else if (repo.mirror) {

web_src/js/svg.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
import octiconGitMerge from '../../public/img/svg/octicon-git-merge.svg';
22
import octiconGitPullRequest from '../../public/img/svg/octicon-git-pull-request.svg';
3+
import octiconInternalRepo from '../../public/img/svg/octicon-internal-repo.svg';
34
import octiconIssueClosed from '../../public/img/svg/octicon-issue-closed.svg';
45
import octiconIssueOpened from '../../public/img/svg/octicon-issue-opened.svg';
56
import octiconLink from '../../public/img/svg/octicon-link.svg';
7+
import octiconLock from '../../public/img/svg/octicon-lock.svg';
8+
import octiconRepo from '../../public/img/svg/octicon-repo.svg';
9+
import octiconRepoClone from '../../public/img/svg/octicon-repo-clone.svg';
10+
import octiconRepoForked from '../../public/img/svg/octicon-repo-forked.svg';
11+
import octiconRepoTemplate from '../../public/img/svg/octicon-repo-template.svg';
12+
import octiconRepoTemplatePrivate from '../../public/img/svg/octicon-repo-template-private.svg';
613

7-
const svgs = {
14+
export const svgs = {
815
'octicon-git-merge': octiconGitMerge,
916
'octicon-git-pull-request': octiconGitPullRequest,
17+
'octicon-internal-repo': octiconInternalRepo,
1018
'octicon-issue-closed': octiconIssueClosed,
1119
'octicon-issue-opened': octiconIssueOpened,
1220
'octicon-link': octiconLink,
21+
'octicon-lock': octiconLock,
22+
'octicon-repo': octiconRepo,
23+
'octicon-repo-clone': octiconRepoClone,
24+
'octicon-repo-forked': octiconRepoForked,
25+
'octicon-repo-template': octiconRepoTemplate,
26+
'octicon-repo-template-private': octiconRepoTemplatePrivate,
1327
};
1428

1529
const parser = new DOMParser();

0 commit comments

Comments
 (0)