Commit bcdf0231a5

bcdf0231a5d311dbb499df7f80af82e564c9d25d

parent: 584d27c583

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-05-24 17:11 UTC

kyu-kurarin

Layout: unified · split

docs/.vitepress/configs/index.ts +3 −1
@@ -10,6 +10,7 @@ import {
10 PagePropertiesMarkdownSection 10 PagePropertiesMarkdownSection
11} from '@nolebase/vitepress-plugin-page-properties/vite' 11} from '@nolebase/vitepress-plugin-page-properties/vite'
12import { fileURLToPath, URL } from 'node:url' 12import { fileURLToPath, URL } from 'node:url'
13import { collectHeadingsPlugin } from '../plugins/collectHeadings'
13import UnoCSS from 'unocss/vite' 14import UnoCSS from 'unocss/vite'
14import Devtools from 'vite-plugin-vue-devtools' 15import Devtools from 'vite-plugin-vue-devtools'
15import type { DefaultTheme, Plugin, UserConfig } from 'vitepress' 16import type { DefaultTheme, Plugin, UserConfig } from 'vitepress'
@@ -107,6 +108,7 @@ export const shared: UserConfig<DefaultTheme.Config> = {
107 ] 108 ]
108 }, 109 },
109 plugins: [ 110 plugins: [
111 collectHeadingsPlugin(fileURLToPath(new URL('../../', import.meta.url))),
110 Devtools(), 112 Devtools(),
111 PageProperties(), 113 PageProperties(),
112 PagePropertiesMarkdownSection(), 114 PagePropertiesMarkdownSection(),
@@ -148,4 +150,4 @@ export const shared: UserConfig<DefaultTheme.Config> = {
148 ] 150 ]
149 } 151 }
150 } 152 }
151} 153}\ No newline at end of file
docs/.vitepress/plugins/collectHeadings.js added +48
@@ -0,0 +1,48 @@
1import { readdirSync, readFileSync, writeFileSync } from 'fs'
2import { join } from 'path'
3
4export function collectHeadingsPlugin(docsDir) {
5 return {
6 name: 'collect-h2-headings',
7 buildStart() {
8 const headings = []
9 collectFromDir(docsDir, docsDir, headings)
10 writeFileSync(
11 join(docsDir, '.vitepress', 'headings.json'),
12 JSON.stringify(headings, null, 2)
13 )
14 }
15 }
16}
17
18function collectFromDir(baseDir, dir, headings) {
19 for (const entry of readdirSync(dir, { withFileTypes: true })) {
20 if (entry.isDirectory() && !entry.name.startsWith('.')) {
21 collectFromDir(baseDir, join(dir, entry.name), headings)
22 } else if (entry.name.endsWith('.md')) {
23 const filePath = join(dir, entry.name)
24 const content = readFileSync(filePath, 'utf-8')
25 const lines = content.split('\n')
26
27 // Derive URL path from file path
28 let urlPath = filePath
29 .replace(baseDir, '')
30 .replace(/\\/g, '/')
31 .replace(/\.md$/, '')
32 .replace(/\/index$/, '/')
33 if (!urlPath.startsWith('/')) urlPath = '/' + urlPath
34
35 for (const line of lines) {
36 const match = line.match(/^##\s+(.+)/)
37 if (match) {
38 const title = match[1].trim()
39 const anchor = '#' + title
40 .toLowerCase()
41 .replace(/[^\w\s-]/g, '')
42 .replace(/\s+/g, '-')
43 headings.push({ path: urlPath, anchor, title })
44 }
45 }
46 }
47 }
48}\ No newline at end of file
docs/.vitepress/theme/components/SidebarCard.vue +27 −1
@@ -5,8 +5,24 @@
5 5
6 All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder. 6 All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
7--> 7-->
8<script setup>
9import { useRouter } from 'vitepress'
10import headings from '../headings.json'
11
12const router = useRouter()
13
14function goRandom() {
15 const pick = headings[Math.floor(Math.random() * headings.length)]
16 router.go(pick.path + pick.anchor)
17}
18</script>
19
8<template> 20<template>
9 <div class="mt-2 overflow-hidden rounded-lg border-2 border-solid border-$vp-c-default-soft relative z-0 max-md:border max-md:border-neutral-200 max-md:dark:border-neutral-700"> 21 <div
22 class="mt-2 overflow-hidden rounded-lg border-2 border-solid border-$vp-c-default-soft relative z-0 max-md:border max-md:border-neutral-200 max-md:dark:border-neutral-700"
23 @click="goRandom"
24 title="I'm feeling lucky"
25 >
10 <img 26 <img
11 src="/soemy.webp" 27 src="/soemy.webp"
12 alt="" 28 alt=""
@@ -17,7 +33,17 @@
17</template> 33</template>
18 34
19<style scoped> 35<style scoped>
36div {
37 cursor: pointer;
38}
39
40div:hover img {
41 opacity: 0.85;
42 transition: opacity 0.2s;
43}
44
20img { 45img {
21 pointer-events: none; 46 pointer-events: none;
47 transition: opacity 0.2s;
22} 48}
23</style>\ No newline at end of file 49</style>\ No newline at end of file