Skip to content

Commit 1c3dd77

Browse files
chore: add release tag tip for index.md (#171)
1 parent dba83bc commit 1c3dd77

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

.vitepress/theme/custom.css

+15-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
display: none;
1717
}
1818

19-
2019
:root {
2120
--c-brand: #646cff;
2221
--c-brand-light: #747bff;
@@ -38,3 +37,18 @@
3837
display: block;
3938
margin-bottom: 10px;
4039
}
40+
41+
.release-tag {
42+
font-size: 20px;
43+
font-weight: bold;
44+
font-family: monospace;
45+
display: inline-block;
46+
position: absolute;
47+
top: 50%;
48+
transform: translateY(-50%);
49+
padding: 6px;
50+
margin-left: 6px;
51+
background: var(--c-brand);
52+
color: white;
53+
border-radius: 10px;
54+
}

.vitepress/theme/fetchReleaseTag.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { onMounted } from 'vue'
2+
3+
export default function fetchReleaseTag() {
4+
onMounted(() => {
5+
fetch('https://api.github.com/repos/vitejs/docs-cn/releases/latest')
6+
.then((res) => res.json())
7+
.then((json) => {
8+
const mainTitle = document.getElementById('main-title')
9+
mainTitle.style.position = 'relative'
10+
11+
const docsReleaseTag = document.createElement('span')
12+
docsReleaseTag.classList.add('release-tag')
13+
const releaseTagName = json.tag_name
14+
docsReleaseTag.innerText = releaseTagName
15+
16+
17+
mainTitle.appendChild(docsReleaseTag)
18+
})
19+
})
20+
}

index.md

+3
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ footer: MIT Licensed | Copyright © 2019-present Evan You & Vite Contributors
3434

3535
<script setup>
3636
import sponsors from './.vitepress/theme/sponsors.json'
37+
import fetchReleaseTag from './.vitepress/theme/fetchReleaseTag.js'
38+
39+
fetchReleaseTag()
3740
</script>

0 commit comments

Comments
 (0)