docs/.vitepress/theme/index.ts

f56c8bdd0cfb1400e12187562177700a942e5a60
wotaku/docs/.vitepress/theme/index.ts history · blame · raw

132 lines · 4305 bytes

  1/**
  2 *  Copyright (c) 2024 taskylizard
  3 *
  4 *  Licensed under the Apache License, Version 2.0 (the "License");
  5 *  you may not use this file except in compliance with the License.
  6 *  You may obtain a copy of the License at
  7 *
  8 *  http://www.apache.org/licenses/LICENSE-2.0
  9 *
 10 *  Unless required by applicable law or agreed to in writing, software
 11 *  distributed under the License is distributed on an "AS IS" BASIS,
 12 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13 *  See the License for the specific language governing permissions and
 14 *  limitations under the License.
 15 */
 16import type { Theme } from 'vitepress'
 17import DefaultTheme from 'vitepress/theme'
 18import '@nolebase/vitepress-plugin-git-changelog/client/style.css'
 19import './styles/style.css'
 20import FloatingVue from 'floating-vue'
 21import { enhanceAppWithTabs } from 'vitepress-plugin-tabs/client'
 22import { NolebaseGitChangelogPlugin } from '@nolebase/vitepress-plugin-git-changelog/client'
 23import { NolebasePagePropertiesPlugin } from '@nolebase/vitepress-plugin-page-properties/client'
 24import '@nolebase/vitepress-plugin-enhanced-readabilities/client/style.css'
 25import '@nolebase/vitepress-plugin-page-properties/client/style.css'
 26import '@nolebase/vitepress-plugin-git-changelog/client/style.css'
 27import 'floating-vue/dist/style.css'
 28import { createMediumZoomProvider } from './composables/medium-zoom'
 29import { createOpProvider } from './composables/op'
 30import Button from './components/Button.vue'
 31import Tooltip from './components/Tooltip.vue'
 32import Authors from './components/Authors.vue'
 33import GradientCard from './components/GradientCard.vue'
 34import 'virtual:uno.css'
 35import Feedback from './components/Feedback.vue'
 36import Layout from './Layout.vue'
 37import PreferenceRadio from './components/PreferenceRadio.vue'
 38import './styles/tooltip-hint.css'
 39
 40export default {
 41  extends: DefaultTheme,
 42  Layout: Layout,
 43  enhanceApp({ app, router, siteData }) {
 44    app.use(FloatingVue, {
 45      themes: {
 46        hint: {
 47          $extend: 'tooltip',
 48          delay: { show: 0, hide: 0 },
 49          html: true
 50        },
 51        'vp-tooltip': {
 52          $extend: 'tooltip',
 53          $resetCss: true,
 54          triggers: ['click', 'touch'],
 55          autoHide: true
 56        }
 57      }
 58    })
 59    enhanceAppWithTabs(app)
 60    app.component('Button', Button)
 61    app.component('Authors', Authors)
 62    app.component('Tooltip', Tooltip)
 63    app.component('Feedback', Feedback)
 64    app.component('PreferenceRadio', PreferenceRadio)
 65    createMediumZoomProvider(app, router)
 66    createOpProvider(app)
 67    app.component('GradientCard', GradientCard)
 68    app.use(NolebaseGitChangelogPlugin, {
 69      commitsRelativeTime: true,
 70      hideChangelogHeader: true,
 71      mapAuthors: [
 72        {
 73          name: 'taskylizard',
 74          username: 'taskylizard',
 75          avatar: 'https://github.com/taskylizard.png'
 76        },
 77        {
 78          name: 'Duck',
 79          username: 'woducku',
 80          avatar: 'https://github.com/woducku.png'
 81        }
 82      ]
 83    })
 84    app.use(
 85      NolebasePagePropertiesPlugin<{ tags: string[]; progress: number }>(),
 86      [
 87        {
 88          locales: {
 89            en: [
 90              {
 91                key: 'tags',
 92                type: 'tags',
 93                title: 'Tags'
 94              },
 95              {
 96                key: 'createdAt',
 97                type: 'datetime',
 98                title: 'Created at',
 99                formatAsFrom: true,
100                dateFnsLocaleName: 'enUS'
101              },
102              {
103                key: 'updatedAt',
104                type: 'datetime',
105                title: 'Updated at',
106                formatAsFrom: true,
107                dateFnsLocaleName: 'enUS'
108              },
109              {
110                key: 'wordsCount',
111                type: 'dynamic',
112                title: 'Word count',
113                options: {
114                  type: 'wordsCount'
115                }
116              },
117              {
118                key: 'readingTime',
119                type: 'dynamic',
120                title: 'Reading time',
121                options: {
122                  type: 'readingTime',
123                  dateFnsLocaleName: 'enUS'
124                }
125              }
126            ]
127          }
128        }
129      ]
130    )
131  }
132} satisfies Theme