Skip to content

Commit 37109b1

Browse files
committed
feat(docs): 添加 GitHub Star 组件
- 在 VitePress 文档中添加 GitHub Star 按钮组件,用于显示项目 Star 数量。 - 更新主题配置以集成新组件。 - 优化代码格式和结构,提高可读性。
1 parent 927b079 commit 37109b1

4 files changed

Lines changed: 250 additions & 127 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<template>
2+
<a
3+
class="github-star-link"
4+
href="https://github.com/anghunk/linuxdo-scripts"
5+
target="_blank"
6+
rel="noreferrer"
7+
>
8+
<span class="github-star-icon" aria-hidden="true">
9+
<svg viewBox="0 0 16 16" fill="currentColor" aria-hidden="true">
10+
<path
11+
d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8Z"
12+
/>
13+
</svg>
14+
</span>
15+
<span class="github-star-text">
16+
Star
17+
<span v-if="stars !== null" class="github-star-count">{{ formattedStars }}</span>
18+
</span>
19+
</a>
20+
</template>
21+
22+
<script setup>
23+
import { onMounted, ref, computed } from 'vue';
24+
25+
const stars = ref(null);
26+
27+
const formattedStars = computed(() => {
28+
if (stars.value == null) return '';
29+
const value = stars.value;
30+
if (value >= 1000) {
31+
const base = value / 1000;
32+
const fixed = base >= 10 ? base.toFixed(0) : base.toFixed(1);
33+
return fixed + 'k';
34+
}
35+
return String(value);
36+
});
37+
38+
async function fetchStars() {
39+
try {
40+
const cached = sessionStorage.getItem('cwd_github_stars');
41+
if (cached) {
42+
const parsed = JSON.parse(cached);
43+
if (parsed && typeof parsed.count === 'number') {
44+
stars.value = parsed.count;
45+
return;
46+
}
47+
}
48+
} catch (e) {
49+
}
50+
51+
try {
52+
const response = await fetch('https://api.github.com/repos/anghunk/linuxdo-scripts');
53+
if (!response.ok) {
54+
return;
55+
}
56+
const data = await response.json();
57+
if (data && typeof data.stargazers_count === 'number') {
58+
stars.value = data.stargazers_count;
59+
try {
60+
sessionStorage.setItem(
61+
'cwd_github_stars',
62+
JSON.stringify({ count: data.stargazers_count })
63+
);
64+
} catch (e) {
65+
}
66+
}
67+
} catch (e) {
68+
}
69+
}
70+
71+
onMounted(() => {
72+
fetchStars();
73+
});
74+
</script>
75+

docs/docs/.vitepress/config.js

Lines changed: 79 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,84 @@
11
import nav from './configs/nav';
22
import AutoSidebar from 'vite-plugin-vitepress-auto-sidebar';
33

4-
const taskLists = require('markdown-it-task-checkbox')
4+
const taskLists = require('markdown-it-task-checkbox');
55

66
export default {
7-
title: 'LinuxDo Scripts 文档',
8-
dist: '/dist',
9-
head: [
10-
['link', {
11-
rel: 'icon',
12-
href: 'https://github.com/anghunk/linuxdo-scripts/blob/main/public/icon/128.png?raw=true'
13-
}]
14-
],
15-
vite: {
16-
plugins: [
17-
/* 自动生成左侧 */
18-
AutoSidebar({
19-
ignoreIndexItem: true, // 忽略首页
20-
titleFromFile: true, // 读取 md 文件 # 一级标题作为侧边
21-
collapsed: false, // 是否默认收缩
22-
})
23-
],
24-
},
25-
markdown: {
26-
config: (md) => {
27-
md.use(taskLists, {
28-
disabled: true,
29-
divWrap: false,
30-
divClass: 'checkbox',
31-
idPrefix: 'cbx_',
32-
ulClass: 'task-list',
33-
liClass: 'task-list-item',
34-
})
35-
}
36-
},
37-
ignoreDeadLinks: true,
38-
themeConfig: {
39-
siteTitle: 'LinuxDo Scripts 文档',
40-
nav,
41-
editLink: {
42-
pattern: 'https://github.com/anghunk/linuxdo-scripts/blob/main/docs/docs/:path',
43-
text: '在 GitHub 上编辑此页面'
44-
},
45-
socialLinks: [{
46-
icon: 'github',
47-
link: 'https://github.com/anghunk/linuxdo-scripts'
48-
}, ],
49-
lastUpdated: true,
50-
lastUpdatedText: '最后更新于',
51-
footer: {
52-
message: 'Released under the MIT License.',
53-
copyright: 'Copyright 2026 anghunk'
54-
},
55-
search: {
56-
provider: 'local',
57-
options: {
58-
locales: {
59-
zh: {
60-
translations: {
61-
button: {
62-
buttonText: '搜索文档',
63-
buttonAriaLabel: '搜索文档'
64-
},
65-
modal: {
66-
noResultsText: '无法找到相关结果',
67-
resetButtonTitle: '清除查询条件',
68-
footer: {
69-
selectText: '选择',
70-
navigateText: '切换'
71-
}
72-
}
73-
}
74-
}
75-
}
76-
}
77-
}
78-
}
79-
}
7+
title: 'LinuxDo Scripts 文档',
8+
dist: '/dist',
9+
head: [
10+
[
11+
'link',
12+
{
13+
rel: 'icon',
14+
href: 'https://github.com/anghunk/linuxdo-scripts/blob/main/public/icon/128.png?raw=true',
15+
},
16+
],
17+
],
18+
vite: {
19+
plugins: [
20+
/* 自动生成左侧 */
21+
AutoSidebar({
22+
ignoreIndexItem: true, // 忽略首页
23+
titleFromFile: true, // 读取 md 文件 # 一级标题作为侧边
24+
collapsed: false, // 是否默认收缩
25+
}),
26+
],
27+
},
28+
markdown: {
29+
config: (md) => {
30+
md.use(taskLists, {
31+
disabled: true,
32+
divWrap: false,
33+
divClass: 'checkbox',
34+
idPrefix: 'cbx_',
35+
ulClass: 'task-list',
36+
liClass: 'task-list-item',
37+
});
38+
},
39+
},
40+
ignoreDeadLinks: true,
41+
themeConfig: {
42+
siteTitle: 'LinuxDo Scripts 文档',
43+
nav,
44+
editLink: {
45+
pattern: 'https://github.com/anghunk/linuxdo-scripts/blob/main/docs/docs/:path',
46+
text: '在 GitHub 上编辑此页面',
47+
},
48+
socialLinks: [
49+
// {
50+
// icon: 'github',
51+
// link: 'https://github.com/anghunk/linuxdo-scripts',
52+
// },
53+
],
54+
lastUpdated: true,
55+
lastUpdatedText: '最后更新于',
56+
footer: {
57+
message: 'Released under the MIT License.',
58+
copyright: 'Copyright 2026 anghunk',
59+
},
60+
search: {
61+
provider: 'local',
62+
options: {
63+
locales: {
64+
zh: {
65+
translations: {
66+
button: {
67+
buttonText: '搜索文档',
68+
buttonAriaLabel: '搜索文档',
69+
},
70+
modal: {
71+
noResultsText: '无法找到相关结果',
72+
resetButtonTitle: '清除查询条件',
73+
footer: {
74+
selectText: '选择',
75+
navigateText: '切换',
76+
},
77+
},
78+
},
79+
},
80+
},
81+
},
82+
},
83+
},
84+
};

docs/docs/.vitepress/theme/custom.css

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,39 @@ html {
143143
display: none;
144144
}
145145

146-
/* 自定义侧边栏 */
146+
.github-star-link {
147+
display: inline-flex;
148+
align-items: center;
149+
gap: 6px;
150+
padding: 2px 8px;
151+
margin-left: 10px;
152+
border-radius: 999px;
153+
border: 1px solid var(--vp-c-border);
154+
font-size: 12px;
155+
color: var(--vp-c-text-1);
156+
text-decoration: none;
157+
transition:
158+
background-color 0.2s ease,
159+
border-color 0.2s ease,
160+
color 0.2s ease;
161+
}
162+
163+
.github-star-link:hover {
164+
background-color: var(--vp-c-bg-soft);
165+
border-color: var(--vp-c-brand-1);
166+
color: var(--vp-c-brand-1);
167+
}
168+
169+
.github-star-icon svg {
170+
width: 16px;
171+
}
172+
173+
.github-star-text {
174+
display: inline-flex;
175+
align-items: center;
176+
}
177+
178+
.github-star-count {
179+
margin-left: 4px;
180+
font-weight: 600;
181+
}

0 commit comments

Comments
 (0)