Skip to content

Commit 64dd051

Browse files
committed
fix(@142vip/vitepress): 修改star趋势历史显示异常,切换域名
1 parent 0bcfa86 commit 64dd051

4 files changed

Lines changed: 33 additions & 10 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ flowchart TD
175175

176176
<a href="https://github.com/142vip/core-x" title="@142vip/core-x">
177177
<picture>
178-
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=142vip/core-x,142vip/408CSFamily,142vip/JavaScriptCollection&type=Date" />
178+
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=142vip%2Fcore-x%2C142vip%2F408csfamily%2C142vip%2Fjavascriptcollection&type=Date&sealed_token=iaO-GLnvLpYHibmRk7lxdWHU5MRcN8yp072DbAkSuka6yVP87RCc245bDe_8qXluQuI-105rgdN5qw_G7omm8P05FDOB4ir6De_EdwCOyZUuxWCQE-LfbA" />
179179
</picture>
180180
</a>
181181

packages/vitepress/src/components/VipOpenSource.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
<script lang="ts" setup>
22
import { ElImage, ElLink } from 'element-plus'
3+
import { computed } from 'vue'
34
import { useData } from 'vitepress'
45
import { VIP_OPEN_SOURCE_SPONSORS } from './constants/openSource'
56
import { getStarHistorySvgUrl } from './utils/starHistory'
67
import 'element-plus/theme-chalk/base.css'
78
import 'element-plus/theme-chalk/el-image.css'
89
import 'element-plus/theme-chalk/el-link.css'
910
10-
defineProps<{
11+
const props = defineProps<{
1112
repoNames?: string[]
1213
}>()
1314
1415
const { isDark } = useData()
16+
17+
const starHistorySrc = computed(() =>
18+
getStarHistorySvgUrl(props.repoNames, isDark.value),
19+
)
1520
</script>
1621

1722
<template>
@@ -73,7 +78,7 @@ const { isDark } = useData()
7378
<h2>趋势</h2>
7479
<div class="vip-open-source__star-history">
7580
<ElImage
76-
:src="getStarHistorySvgUrl(repoNames, isDark)"
81+
:src="starHistorySrc"
7782
alt="Github Star History"
7883
title="Github Star History"
7984
class="vip-open-source__star-img"
@@ -118,7 +123,6 @@ const { isDark } = useData()
118123
.vip-open-source__star-history {
119124
display: flex;
120125
justify-content: center;
121-
align-content: center;
122126
}
123127
124128
.vip-open-source__star-img {

packages/vitepress/src/components/constants/openSource.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ export const VIP_STAR_HISTORY_DEFAULT_REPOS = [
1919
'142vip/408CSFamily',
2020
'142vip/JavaScriptCollection',
2121
] as const
22+
23+
/** star-history.com 签发的 sealed token,用于匿名访问 SVG API */
24+
export const VIP_STAR_HISTORY_SEALED_TOKEN
25+
= 'iaO-GLnvLpYHibmRk7lxdWHU5MRcN8yp072DbAkSuka6yVP87RCc245bDe_8qXluQuI-105rgdN5qw_G7omm8P05FDOB4ir6De_EdwCOyZUuxWCQE-LfbA'
Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
import { VIP_STAR_HISTORY_DEFAULT_REPOS } from '../constants/openSource'
1+
import {
2+
VIP_STAR_HISTORY_DEFAULT_REPOS,
3+
VIP_STAR_HISTORY_SEALED_TOKEN,
4+
} from '../constants/openSource'
5+
6+
const STAR_HISTORY_API = 'https://api.star-history.com/svg'
27

38
/**
4-
* Star History 图表地址(随深浅色切换 theme)
9+
* Star History 图表地址(含 sealed_token,随深浅色切换 theme)
510
*/
611
export function getStarHistorySvgUrl(repoNames: string[] | undefined, isDark: boolean): string {
7-
const repos = repoNames?.length
8-
? repoNames
9-
: [...VIP_STAR_HISTORY_DEFAULT_REPOS]
10-
return `https://api.star-history.com/svg?repos=${repos.join(',')}&type=Date${isDark ? '&theme=dark' : ''}`
12+
const repos = (repoNames?.length ? repoNames : [...VIP_STAR_HISTORY_DEFAULT_REPOS])
13+
.map(repo => repo.toLowerCase())
14+
.join(',')
15+
16+
const params = new URLSearchParams({
17+
repos,
18+
type: 'Date',
19+
sealed_token: VIP_STAR_HISTORY_SEALED_TOKEN,
20+
})
21+
22+
if (isDark)
23+
params.set('theme', 'dark')
24+
25+
return `${STAR_HISTORY_API}?${params.toString()}`
1126
}

0 commit comments

Comments
 (0)