1
0
forked from bot/app

📝 [docs]: 新增在线展示

This commit is contained in:
远野千束 2024-09-01 22:00:17 +08:00
parent 359683dbae
commit 58d0d12c1f
5 changed files with 63 additions and 7 deletions

View File

@ -7,5 +7,8 @@ import StatsBar from '../../components/StatsBar.vue'
export default { export default {
extends: DefaultTheme, extends: DefaultTheme,
enhanceApp({ app }) {
app.component('StatsBar', StatsBar)
},
Layout: StatsBar Layout: StatsBar
} }

View File

@ -1,8 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import DefaultTheme from "vitepress/theme"; import DefaultTheme from "vitepress/theme";
import {ref, onMounted, onUnmounted} from "vue"; import {ref, onMounted, onUnmounted, watch} from "vue";
import {statsApi, GithubStats, RepoUrl, StarMapUrl} from "./scripts/statsApi"; import {statsApi, GithubStats, RepoUrl, StarMapUrl} from "./scripts/statsApi";
import {getTextRef, updateRef} from "./scripts/i18n"; import {getTextRef, updateRefData} from "./scripts/i18n";
import { onBeforeRouteUpdate } from 'vue-router';
import {useData} from "vitepress";
const {Layout} = DefaultTheme; const {Layout} = DefaultTheme;
@ -82,20 +84,27 @@ async function updateData() {
dataSections.prs.value.value = githubStats?.prs || 0; dataSections.prs.value.value = githubStats?.prs || 0;
} }
onMounted(() => { onMounted(() => {
const intervalId = setInterval(updateData, 10000); const intervalId = setInterval(updateData, 10000);
updateData(); updateData();
updateRefData();
onUnmounted(() => { onUnmounted(() => {
clearInterval(intervalId); clearInterval(intervalId);
}); });
}); });
onBeforeRouteUpdate(() => {
updateRefData();
});
</script> </script>
<template> <template>
<Layout> <Layout>
<template #home-features-before> <template #home-features-before>
<div class="stats-bar-content"> <div class="stats-bar-content">
<div class="button" @click="updateRefData">Update</div>
<div class="stats-bar"> <div class="stats-bar">
<div class="stats-info"> <div class="stats-info">
<div v-for="section in Object.values(dataSections)" :key="section.name" class="section"> <div v-for="section in Object.values(dataSections)" :key="section.name" class="section">

View File

@ -1,4 +1,5 @@
import {ref} from "vue"; import {ref} from "vue";
import {useData} from "vitepress"; import {useData} from "vitepress";
const i18nData = { const i18nData = {
@ -34,7 +35,7 @@ let refData = {}
function getText(lang: string, key: string): string { function getText(lang: string, key: string): string {
lang = formatLang(lang); lang = formatLang(lang);
return i18nData[key][key]; return i18nData[lang][key];
} }
function formatLang(lang: string): string { function formatLang(lang: string): string {
@ -44,8 +45,8 @@ function formatLang(lang: string): string {
return lang; return lang;
} }
export function updateRef() { export function updateRefData() {
const lang = useData().site.value.lang; const lang = formatLang(useData().site.value.lang);
for (let key in refData) { for (let key in refData) {
refData[key].value = getText(lang, key); refData[key].value = getText(lang, key);
} }
@ -53,6 +54,6 @@ export function updateRef() {
export function getTextRef(key: string): any { export function getTextRef(key: string): any {
const lang = formatLang(useData().site.value.lang); const lang = formatLang(useData().site.value.lang);
refData[key] = ref(i18nData[lang][key]); refData[key] = getText(lang, key);
return refData[key] return refData[key]
} }

View File

@ -12,6 +12,8 @@
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"clipboard": "^2.0.11", "clipboard": "^2.0.11",
"vue": "^3.4.38" "vue": "^3.4.38",
"vue-route": "^1.5.1",
"vue-router": "4"
} }
} }

View File

@ -11,6 +11,12 @@ dependencies:
vue: vue:
specifier: ^3.4.38 specifier: ^3.4.38
version: 3.4.38 version: 3.4.38
vue-route:
specifier: ^1.5.1
version: 1.5.1
vue-router:
specifier: '4'
version: 4.4.3(vue@3.4.38)
devDependencies: devDependencies:
'@intlify/unplugin-vue-i18n': '@intlify/unplugin-vue-i18n':
@ -809,6 +815,10 @@ packages:
'@vue/compiler-dom': 3.4.38 '@vue/compiler-dom': 3.4.38
'@vue/shared': 3.4.38 '@vue/shared': 3.4.38
/@vue/devtools-api@6.6.3:
resolution: {integrity: sha512-0MiMsFma/HqA6g3KLKn+AGpL1kgKhFWszC9U29NfpWK5LE7bjeXxySWJrOJ77hBz+TBrBQ7o4QJqbPbqbs8rJw==}
dev: false
/@vue/devtools-api@7.3.9: /@vue/devtools-api@7.3.9:
resolution: {integrity: sha512-D+GTYtFg68bqSu66EugQUydsOqaDlPLNmYw5oYk8k81uBu9/bVTUrqlAJrAA9Am7MXhKz2gWdDkopY6sOBf/Bg==} resolution: {integrity: sha512-D+GTYtFg68bqSu66EugQUydsOqaDlPLNmYw5oYk8k81uBu9/bVTUrqlAJrAA9Am7MXhKz2gWdDkopY6sOBf/Bg==}
dependencies: dependencies:
@ -1211,6 +1221,10 @@ packages:
engines: {node: '>=12.13'} engines: {node: '>=12.13'}
dev: true dev: true
/isarray@0.0.1:
resolution: {integrity: sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==}
dev: false
/js-yaml@3.14.1: /js-yaml@3.14.1:
resolution: {integrity: sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==} resolution: {integrity: sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==}
hasBin: true hasBin: true
@ -1299,6 +1313,18 @@ packages:
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
hasBin: true hasBin: true
/page@1.11.6:
resolution: {integrity: sha512-P6e2JfzkBrPeFCIPplLP7vDDiU84RUUZMrWdsH4ZBGJ8OosnwFkcUkBHp1DTIjuipLliw9yQn/ZJsXZvarsO+g==}
dependencies:
path-to-regexp: 1.2.1
dev: false
/path-to-regexp@1.2.1:
resolution: {integrity: sha512-DBw9IhWfevR2zCVwEZURTuQNseCvu/Q9f5ZgqMCK0Rh61bDa4uyjPAOy9b55yKiPT59zZn+7uYKxmWwsguInwg==}
dependencies:
isarray: 0.0.1
dev: false
/pathe@1.1.2: /pathe@1.1.2:
resolution: {integrity: sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ==} resolution: {integrity: sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ==}
dev: true dev: true
@ -1590,6 +1616,21 @@ packages:
vue: 3.4.38 vue: 3.4.38
dev: true dev: true
/vue-route@1.5.1:
resolution: {integrity: sha512-RoeEWvSTk/Zasjx11En4XPyE1jXwuFQ4Itr4fzh1TOSMYefUddhhlHXmAGFFPn37J1YrEymm6sU/3IRTyu23Aw==}
dependencies:
page: 1.11.6
dev: false
/vue-router@4.4.3(vue@3.4.38):
resolution: {integrity: sha512-sv6wmNKx2j3aqJQDMxLFzs/u/mjA9Z5LCgy6BE0f7yFWMjrPLnS/sPNn8ARY/FXw6byV18EFutn5lTO6+UsV5A==}
peerDependencies:
vue: ^3.2.0
dependencies:
'@vue/devtools-api': 6.6.3
vue: 3.4.38
dev: false
/vue@3.4.38: /vue@3.4.38:
resolution: {integrity: sha512-f0ZgN+mZ5KFgVv9wz0f4OgVKukoXtS3nwET4c2vLBGQR50aI8G0cqbFtLlX9Yiyg3LFGBitruPHt2PxwTduJEw==} resolution: {integrity: sha512-f0ZgN+mZ5KFgVv9wz0f4OgVKukoXtS3nwET4c2vLBGQR50aI8G0cqbFtLlX9Yiyg3LFGBitruPHt2PxwTduJEw==}
peerDependencies: peerDependencies: