Skip to content

Commit 3328c4a

Browse files
author
An Phan
committed
Add GitHub badges
1 parent dbca79c commit 3328c4a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

app/site/src/components/Item.vue

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
<a v-if="item.author.url" :href="item.author.url">{{ item.author.name }}</a>
88
<template v-else>{{ item.author.name }}</template>
99
</span>
10+
<a v-if="githubBadgeUrl" :href="item.url" class="github-badge">
11+
<img :src="githubBadgeUrl">
12+
</a>
1013
</h1>
1114
<div class="thin" v-if="item.description" v-html="item.description"></div>
1215
<footer class="thin" v-if="item.tags">
@@ -24,7 +27,18 @@ import { filterByTag } from '../mixins'
2427
2528
export default {
2629
props: ['item'],
27-
mixins: [filterByTag]
30+
mixins: [filterByTag],
31+
computed: {
32+
githubBadgeUrl() {
33+
const re = /https?:\/\/github\.com\/([A-Za-z0-9-_]*)\/([A-Za-z0-9-_]*)\/?$/i
34+
const matches = re.exec(this.item.url)
35+
if (!matches) {
36+
return null
37+
}
38+
39+
return `https://img.shields.io/github/stars/${matches[1]}/${matches[2]}.svg?style=social&label=★`
40+
}
41+
}
2842
}
2943
</script>
3044

@@ -45,6 +59,13 @@ article {
4559
&:only-child {
4660
margin-bottom: 0;
4761
}
62+
63+
.github-badge {
64+
padding-top: .3rem;
65+
display: inline-block;
66+
vertical-align: middle;
67+
margin-left: 6px;
68+
}
4869
}
4970
5071
footer {

0 commit comments

Comments
 (0)