Skip to content

Commit 8a6d0b8

Browse files
committed
Updated version of git repositoryMap
1 parent a4c107c commit 8a6d0b8

8 files changed

Lines changed: 337 additions & 139 deletions

File tree

docs/.vitepress/config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default withPwa(defineConfig({
1313
titleTemplate: '开发笔记',
1414
description: '小路的开发笔记',
1515
head: [
16-
[ 'link', { rel: 'icon', href: withBase('/logo.svg') } ],
16+
[ 'link', { rel: 'icon', href: withBase('/favicon.ico') } ],
1717
[ 'meta', { property: 'og:title', content: '开发笔记' } ],
1818
[ 'meta', { property: 'og:image', content: withBase('/logo.svg') } ],
1919
[ 'meta', { property: 'og:description', content: '小路的开发笔记' } ],
@@ -77,8 +77,8 @@ export default withPwa(defineConfig({
7777
},
7878
{ icon: 'github', link: 'https://github.com/peiyanlu/vite-press/' },
7979
],
80-
// search: isDev ? local : algolia,
81-
search: algolia,
80+
search: isDev ? local : algolia,
81+
// search: algolia,
8282
externalLinkIcon: true,
8383
},
8484
locales: {

docs/.vitepress/config/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function createGitCachePlugin(): Plugin {
1818
if (resolvedConfig.vitepress) {
1919
const { srcDir, cacheDir } = resolvedConfig.vitepress
2020

21-
await cacheAllGitTimestamps(srcDir)
21+
await cacheAllGitTimestamps(srcDir, [ '*.md' ], [ /README\.md$/, /index\.md$/, /-ignore\.md$/ ])
2222
saveCache(cacheDir)
2323
}
2424
},

docs/.vitepress/global.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ declare global {
55
interface Window {
66
_hmt: any
77
Gitalk: Function
8-
jinrishici: Function
98
}
109
}
1110

docs/.vitepress/theme/components/global/DocShici.vue

Lines changed: 0 additions & 128 deletions
This file was deleted.

docs/.vitepress/utils/getGitTimestamp.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const slash = (p: string): string => p.replace(/\\/g, '/')
4747
// }
4848

4949

50-
export async function getGitTimestamp(file: string): Promise<GitFileTimes> {
50+
export const getGitTimestamp = async (file: string): Promise<GitFileTimes> => {
5151
const cached = cache.get(file)
5252
if (cached) return cached
5353

@@ -70,7 +70,7 @@ export async function getGitTimestamp(file: string): Promise<GitFileTimes> {
7070
return res
7171
}
7272

73-
export async function cacheAllGitTimestamps(root: string, patterns: string[] = [ '*.md' ]) {
73+
export const cacheAllGitTimestamps = async (root: string, patterns: string[] = [ '*.md' ], excludes: RegExp[] = []) => {
7474
// git 根目录
7575
const cp = spawnSync('git', [ 'rev-parse', '--show-toplevel' ], { encoding: 'utf8' })
7676
if (cp.error) throw cp.error
@@ -79,7 +79,8 @@ export async function cacheAllGitTimestamps(root: string, patterns: string[] = [
7979
// 文件列表
8080
const args = [ 'ls-files', ...patterns ]
8181
const { stdout: lsOut } = spawnSync('git', args, { cwd: root, encoding: 'utf8' })
82-
const files = lsOut.split('\n').filter(Boolean)
82+
const ls = lsOut.split('\n').filter(Boolean)
83+
const files = ls.filter(file => !excludes.some((r) => r.test(file)))
8384

8485
const asyncFn = (file: string) => {
8586
return new Promise<GitFileTimes>((resolve, reject) => {
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<script lang="ts" setup>
2+
import { useDebounceFn, useFetch } from '@vueuse/core'
3+
import { computed, onMounted, ref, unref } from 'vue'
4+
5+
6+
interface ResultData {
7+
popularity: number;
8+
origin: {
9+
dynasty: string;
10+
author: string;
11+
title: string;
12+
content: string[];
13+
translate: string[] | null
14+
};
15+
matchTags: string[];
16+
cacheAt: string;
17+
recommendedReason: string;
18+
id: string;
19+
content: string;
20+
}
21+
22+
interface ShiCiResult {
23+
data: ResultData;
24+
ipAddress: string;
25+
status: 'success' | 'error';
26+
token: string;
27+
}
28+
29+
const loading = ref(false)
30+
const result = ref<ResultData>()
31+
const tokenCache = ref<string>('VOdlQy7mK2kuULsBfAEh8bgVpXaYf62i') // https://v2.jinrishici.com/token
32+
33+
34+
const getUrl = <T extends Record<any, any>>(url: string, record: T) => {
35+
const u = new URL(url)
36+
u.search = new URLSearchParams(Object.entries(record).filter(([ _, v ]) => Boolean(v))).toString()
37+
return u.toString()
38+
}
39+
40+
const getResult = async () => {
41+
const url = getUrl(
42+
'https://v2.jinrishici.com/one.json',
43+
{ 'client': 'npm-sdk/1.0', 'X-User-Token': tokenCache.value },
44+
)
45+
46+
const { data } = await useFetch(url, { method: 'GET' }, { refetch: true }).json()
47+
return unref<ShiCiResult>(data)
48+
}
49+
50+
const handleContent = useDebounceFn(async () => {
51+
loading.value = true
52+
const { data, token } = await getResult().catch()
53+
result.value = data
54+
tokenCache.value = token
55+
loading.value = false
56+
}, 500)
57+
58+
59+
const origin = computed(() => {
60+
if (!result.value) return
61+
const { origin: { author, dynasty } } = result.value
62+
return [ author, dynasty ].join(' · ')
63+
})
64+
65+
const mTitle = computed(() => {
66+
return result.value?.origin?.title || ''
67+
})
68+
69+
onMounted(() => {
70+
handleContent()
71+
})
72+
</script>
73+
74+
<template>
75+
<div class="shi-wrapper">
76+
<div class="shi-wrapper-content">
77+
<template v-if="result">
78+
<svg-icon
79+
v-if="loading"
80+
style="font-size: 20px;"
81+
name="loading-DoubleRing"
82+
/>
83+
84+
<div
85+
class="line"
86+
:title="mTitle"
87+
@click="handleContent"
88+
>
89+
<div v-text="result.content" />
90+
<sub v-text="origin" />
91+
</div>
92+
</template>
93+
94+
<div
95+
v-else
96+
class="error"
97+
@click="handleContent"
98+
v-text="'点击重新加载'"
99+
/>
100+
</div>
101+
</div>
102+
</template>
103+
104+
<style lang="scss" scoped>
105+
.shi-wrapper {
106+
display: flex;
107+
flex-flow: row nowrap;
108+
justify-content: center;
109+
height: 16px;
110+
text-align: center;
111+
line-height: 1;
112+
113+
&-content {
114+
display: flex;
115+
flex-flow: row nowrap;
116+
align-items: center;
117+
gap: 6px;
118+
cursor: pointer;
119+
user-select: none;
120+
121+
.line {
122+
display: flex;
123+
align-items: flex-end;
124+
flex-flow: row wrap;
125+
justify-content: flex-start;
126+
height: 16px;
127+
color: var(--vp-c-text-light-1);
128+
gap: 6px;
129+
}
130+
131+
.error {
132+
color: var(--vp-c-danger-1);
133+
opacity: .6;
134+
}
135+
}
136+
}
137+
</style>

docs/archive/components/DocTimeline.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts" setup>
2-
import DocShici from '@theme/components/global/DocShici.vue'
2+
import DocShiCi from './DocShiCi.vue'
33
import DocTag from '@theme/components/global/DocTag.vue'
44
import SvgIcon from '@theme/components/global/SvgIcon.vue'
55
import { useMagicKeys } from '@vueuse/core'
@@ -84,7 +84,7 @@ const count = computed(() => {
8484
<div>{{ `共 ${ count } 篇,持续更新中` }}</div>
8585
</div>
8686

87-
<DocShici class="doc-shici" />
87+
<DocShiCi class="doc-shici" />
8888

8989
<div class="doc-timeline">
9090
<DocTimelineItem

0 commit comments

Comments
 (0)