Skip to content

Commit

Permalink
feat: 新增动效组件依赖,美化文档
Browse files Browse the repository at this point in the history
  • Loading branch information
ikenxuan committed Jul 22, 2024
1 parent 5c73260 commit 6fbdddd
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 17 deletions.
47 changes: 47 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
import { defineConfig } from 'vitepress'
// 时间线
import timeline from 'vitepress-markdown-timeline'
// 任务列表
import taskLists from "markdown-it-task-lists"
// mathjax3公式支持
import mathjax3 from 'markdown-it-mathjax3'
// 页脚
import footnote_plugin from 'markdown-it-footnote'
// 双向链接
import { BiDirectionalLinks } from '@nolebase/markdown-it-bi-directional-links'
// 行内链接预览
import { InlineLinkPreviewElementTransform } from '@nolebase/vitepress-plugin-inline-link-preview/markdown-it'
// 基于git的页面历史
import {
GitChangelog,
GitChangelogMarkdownSection,
} from '@nolebase/vitepress-plugin-git-changelog/vite'
// 页面属性
import {
PageProperties,
PagePropertiesMarkdownSection
} from '@nolebase/vitepress-plugin-page-properties/vite'

export default defineConfig({
lang: 'zh-CN',
base: '/Karin',
title: 'karin',
description: '基于 Kritor 进行开发的nodejs机器人框架',
markdown: {
math: true,
// 全局代码块行号显示
lineNumbers: true,
image: {
Expand All @@ -25,8 +44,36 @@ export default defineConfig({
md.use(mathjax3)
// 脚注
md.use(footnote_plugin)
// 双向链接
md.use(BiDirectionalLinks())
// 行内链接预览
md.use(InlineLinkPreviewElementTransform)
},
},
vite: {
plugins: [
GitChangelog({
// 要获取git日志的仓库
repoURL: () => 'https://github.com/KarinJS/Karin',
}),
GitChangelogMarkdownSection({
sections: {
// 禁用页面历史
disableChangelog: false,
// 禁用贡献者
disableContributors: false,
},
}),
// 页面属性
PageProperties(),
PagePropertiesMarkdownSection({
excludes: [
'toc.md',
'index.md',
],
}),
],
},
vue: {
template: {
compilerOptions: {
Expand Down
118 changes: 118 additions & 0 deletions docs/.vitepress/theme/components/Share.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<script lang="ts" setup>
import { useClipboard } from '@vueuse/core'
import { ref, watch } from 'vue'
import { useRoute } from 'vitepress'
// 无协议前缀域名
const plainTargetDomain = 'karinjs.github.io'
interface HyphenResp<T> {
data: T
}
interface HyphenNewShortURLResp {
url: string
shortUrl: string
}
const APIHost = 'https://api.ayaka.io/hyphen'
const newUrlEndpoint = `${APIHost}/api/v1/url`
const queryUrlEndpoint = `${APIHost}/api/v1/url/full`
const route = useRoute()
async function findExistingLink (url: string): Promise<string> {
const res = await fetch(`${queryUrlEndpoint}?url=${url}`)
if (res.status !== 200) {
if (res.status === 404)
return ''
console.error(await res.json())
return ''
}
const resJson = await res.json()
return resJson.data.shortUrl as string
}
async function createShareLink (url: string) {
const res = await fetch(newUrlEndpoint, {
method: 'POST',
body: JSON.stringify({ url }),
headers: {
'Content-Type': 'application/json',
},
})
if (res.status !== 200) {
console.error(await res.json())
return null
}
const resJson = (await res.json()) as HyphenResp<HyphenNewShortURLResp>
return resJson.data
}
async function getShareLink (): Promise<string> {
// 本身就是短地址或不是生产环境的话不处理,节省资源
if (
window.location.hostname !== plainTargetDomain
|| window.location.pathname.length <= 20
) return window.location.href
const url = window.location.href
let linkHash = ''
const existingLink = await findExistingLink(url)
if (existingLink !== '') {
linkHash = existingLink
}
else {
const newLink = await createShareLink(url)
if (newLink === null)
return window.location.href
linkHash = newLink.shortUrl
}
return `${window.location.origin}/to/${linkHash}`
}
const shareLink = ref('')
watch(() => route.path, async (val, oldVal, onCleanup) => {
if (typeof window === 'undefined')
return
shareLink.value = ''
let cleanup = false
onCleanup(() => cleanup = true)
const link = await getShareLink()
if (cleanup)
return
shareLink.value = link
}, { immediate: true })
const { copy, copied: shareSuccess } = useClipboard()
function copyShareLink () {
copy(shareLink.value)
}
</script>

<template>
<button h-full ws-nowrap px3 text-sm font-medium text="$vp-c-text-1" :class="[
shareSuccess ? '!text-green-400' : '',
shareLink ? 'hover:sm:text-$vp-c-brand' : '!cursor-wait',
]" :disabled="!shareLink || shareSuccess" @click="copyShareLink()">
<Transition mode="out-in" enter-active-class="transition-all duration-250 ease-out"
leave-active-class="transition-all duration-250 ease-out" enter-from-class="transform translate-y-30px opacity-0"
leave-to-class="transform translate-y--30px opacity-0" enter-to-class="opacity-100"
leave-from-class="opacity-100">
<span v-if="shareSuccess" flex items-center space-x-1>
<span class="i-octicon:checkbox-16" />
<span>复制成功</span>
</span>
<span v-else flex items-center space-x-1>
<span class="i-octicon:share-16" />
<span>分享此页</span>
</span>
</Transition>
</button>
<div class="bg-$vp-c-divider-light" mx2 block h-24px w-1px md:hidden />
</template>
93 changes: 90 additions & 3 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,104 @@
/* .vitepress\theme\index.ts */
import DefaultTheme from 'vitepress/theme'
import mediumZoom from 'medium-zoom'
import { onMounted, watch, nextTick } from 'vue'
import { onMounted, watch, nextTick, h } from 'vue'
import { useData, useRoute } from 'vitepress'
import 'vitepress-markdown-timeline/dist/theme/index.css'
import './style/index.css'
// 代码块添加折叠
import codeblocksFold from 'vitepress-plugin-codeblocks-fold'
import 'vitepress-plugin-codeblocks-fold/style/index.css'
// 基于git的页面历史
import {
NolebaseGitChangelogPlugin
} from '@nolebase/vitepress-plugin-git-changelog/client'
import '@nolebase/vitepress-plugin-git-changelog/client/style.css'
// 行内链接预览
import {
NolebaseInlineLinkPreviewPlugin,
} from '@nolebase/vitepress-plugin-inline-link-preview/client'
import '@nolebase/vitepress-plugin-inline-link-preview/client/style.css'
// 顶级的阅读增强,页面右上角小书本
import {
NolebaseEnhancedReadabilitiesMenu,
NolebaseEnhancedReadabilitiesScreenMenu,
} from '@nolebase/vitepress-plugin-enhanced-readabilities/client'
import '@nolebase/vitepress-plugin-enhanced-readabilities/client/style.css'
// 闪烁高亮当前目标标题
import {
NolebaseHighlightTargetedHeading,
} from '@nolebase/vitepress-plugin-highlight-targeted-heading/client'
// 快速复制当前页的url
import Share from './components/Share.vue'
// 页面属性
import {
NolebasePagePropertiesPlugin,
} from '@nolebase/vitepress-plugin-page-properties/client'
import '@nolebase/vitepress-plugin-page-properties/client/style.css'

export default {
extends: DefaultTheme,
enhanceApp ({ app }) {
app.use(NolebaseGitChangelogPlugin)
app.use(NolebaseInlineLinkPreviewPlugin)
// app.use(NuAsciinemaPlayer)
app.use(NolebasePagePropertiesPlugin<{
progress: number
}>(), {
properties: {
'zh-CN': [
{
key: 'wordCount',
type: 'dynamic',
title: '字数',
options: {
type: 'wordsCount',
},
},
{
key: 'readingTime',
type: 'dynamic',
title: '阅读时间',
options: {
type: 'readingTime',
dateFnsLocaleName: 'zhCN',
},
},
{
key: 'updatedAt',
type: 'datetime',
title: '更新时间',
formatAsFrom: true,
dateFnsLocaleName: 'zhCN',
},
],
},
})
},
Layout: () => {
return h(DefaultTheme.Layout, null, {

'nav-bar-content-after': () => [
// 为较宽的屏幕的导航栏添加阅读增强菜单
h(NolebaseEnhancedReadabilitiesMenu),
// 快速复制当前页的url
h(Share),
],
// 为较窄的屏幕(通常是小于 iPad Mini)添加阅读增强菜单
'nav-screen-content-after': () => h(NolebaseEnhancedReadabilitiesScreenMenu),
'layout-top': () => [
h(NolebaseHighlightTargetedHeading),
],
})
},

/** 响应式图片缩放 */
setup () {
const route = useRoute()
// 获取前言和路由
const { frontmatter } = useData()
// 代码块添加折叠
codeblocksFold({ route, frontmatter }, true, 400)

const initZoom = () => {
// 响应式的图片放大缩小
// mediumZoom('[data-zoomable]', { background: 'var(--vp-c-bg)' }); // 默认
Expand All @@ -23,6 +111,5 @@ export default {
() => route.path,
() => nextTick(() => initZoom())
)
const { frontmatter } = useData()
},
}
3 changes: 2 additions & 1 deletion docs/.vitepress/theme/style/index.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import './var.css';
@import './vp-code-group.css';
@import './mathjax3.css';
@import './mathjax3.css';
@import './main.css'
3 changes: 3 additions & 0 deletions docs/.vitepress/theme/style/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.VPSocialLinks.VPNavBarSocialLinks.social-links {
margin-right: 0;
}
4 changes: 0 additions & 4 deletions docs/.vitepress/theme/style/var.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
/* var.css */
/* */
:root {
/* 主题色,浅色模式,深紫色调 */
/* 鼠标滑过高亮色,代码块高亮色,加粗高亮色 */
--vp-c-brand-1: #5224b6;
/* --vp-c-brand-1-2: #5224b6; */
--vp-c-brand-2: #352984;
--vp-c-brand-3: #6d68c1;
/* 主页logo大图底色 设置右图像渐变 */
--vp-home-hero-image-background-image: linear-gradient(-45deg, #f6abe9 50%, #ebe0ba 50%);
--vp-home-hero-image-filter: blur(150px);
}
Expand Down
13 changes: 7 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ hero:
name: Karin
tagline: 基于 Kritor 标准进行开发的nodejs机器人框架
actions:
- theme: alt
text: onebots
link: https://docs.onebots.org/
- theme: alt
text: 插件索引
link: /plugins/index
- theme: brand
text: 快速上手
link: /start/start
- theme: alt
text: 插件索引
link: /plugins/index
- theme: alt
text: onebots
link: https://docs.onebots.org/


features:
- title: 轻量级
Expand Down
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@
"author": "Lain",
"version": "0.0.3",
"type": "module",
"devDependencies": {
"vitepress": "^1.3.0"
},
"scripts": {
"dev": "vitepress dev docs",
"build": "vitepress build docs",
"preview": "vitepress preview docs"
},
"dependencies": {
"@nolebase/markdown-it-bi-directional-links": "^2.2.2",
"@nolebase/vitepress-plugin-enhanced-readabilities": "^2.2.2",
"@nolebase/vitepress-plugin-git-changelog": "^2.2.2",
"@nolebase/vitepress-plugin-highlight-targeted-heading": "^2.2.2",
"@nolebase/vitepress-plugin-inline-link-preview": "^2.2.2",
"@nolebase/vitepress-plugin-meta": "^2.2.2",
"@nolebase/vitepress-plugin-page-properties": "^2.2.2",
"@vueuse/core": "^10.11.0",
"markdown-it-footnote": "^4.0.0",
"markdown-it-mathjax3": "^4.3.2",
"markdown-it-task-lists": "^2.1.1",
"medium-zoom": "^1.1.0",
"vite": "^5.3.4",
"vitepress": "^1.3.1",
"vitepress-markdown-timeline": "^1.2.1",
"vitepress-plugin-codeblocks-fold": "^1.2.28",
"vue": "^3.4.33"
}
}

0 comments on commit 6fbdddd

Please sign in to comment.