perf: 改进类型

This commit is contained in:
pengzhanbo 2024-07-08 02:40:54 +08:00
parent 57500524c5
commit 5a600048d5
13 changed files with 337 additions and 23 deletions

View File

@ -0,0 +1,40 @@
import type { Stats } from 'node:fs'
export interface AutoFrontmatterMarkdownFile {
filepath: string
relativePath: string
content: string
createTime: Date
stats: Stats
}
export type FrontmatterFn<T = any, K = object> = (
value: T,
file: AutoFrontmatterMarkdownFile,
data: K
) => T | PromiseLike<T>
export type AutoFrontmatterObject<K = object, T = any> = Record<string, FrontmatterFn<T, K>>
export type AutoFrontmatterArray = {
include: string | string[]
frontmatter: AutoFrontmatterObject
}[]
export interface AutoFrontmatter {
/**
* FilterPattern
*/
include?: string | string[]
exclude?: string | string[]
/**
* {
* key(value, file, data) {
* return value
* }
* }
*/
frontmatter?: AutoFrontmatterArray | AutoFrontmatterObject
}

View File

@ -3,6 +3,8 @@ export type ThemeImage =
| { src: string, alt?: string }
| { dark: string, light: string, alt?: string }
export type ThemeIcon = string | { svg: string }
export type ThemeColor = string | { light: string, dark: string }
export type ThemeOutline = false | number | [number, number] | 'deep'

View File

@ -1,10 +1,12 @@
import type { BlogPostDataItem } from '@vuepress-plume/plugin-blog-data'
import type { PageCategoryData } from './page-data.js'
export interface PlumeThemeBlogPostItem extends BlogPostDataItem {
tags: string[]
sticky: boolean
categoryList: PageCategoryData[]
export interface PlumeThemeBlogPostItem {
title: string
excerpt: string
path: string
tags?: string[]
sticky?: boolean | number
categoryList?: PageCategoryData[]
createTime: string
lang: string
encrypt?: boolean
@ -15,16 +17,21 @@ export type PlumeThemeBlogPostData = PlumeThemeBlogPostItem[]
export interface PlumeThemeBlog {
/**
* blog list link
*
*
* @default '/blog/'
*/
link?: string
/**
* glob string
* glob string
*
* @default - ['**\*.md']
* `.md` `notes`
*
* `blog`
* `['blog/**\/*.md']`
*
* @default - ['**\/*.md']
*/
include?: string[]

View File

@ -3,4 +3,7 @@ export * from './frontmatter/index.js'
export * from './options/index.js'
export * from './page-data.js'
export * from './blog.js'
export * from './sidebar.js'
export * from './navbar.js'
export * from './notes.js'
export * from './auto-frontmatter.js'

View File

@ -1,33 +1,75 @@
export type NavItem = NavItemWithLink | NavItemWithChildren
import type { ThemeIcon } from './base.js'
export type NavItem = string | NavItemWithLink | NavItemWithChildren
export interface NavItemWithLink {
/**
*
*/
text: string
/**
*
*/
link: string
icon?: string | { svg: string }
rel?: string
target?: string
/**
*
*/
icon?: ThemeIcon
prefix?: never
items?: never
/**
* `activeMatch` is expected to be a regex string. We can't use actual
* RegExp object here because it isn't serializable
*/
activeMatch?: string
rel?: string
target?: string
noIcon?: boolean
}
export interface NavItemChildren {
/**
*
*/
text?: string
icon?: string | { svg: string }
items: NavItemWithLink[]
/**
*
*
*/
prefix?: string
/**
*
*/
items: (string | NavItemWithLink)[]
}
export interface NavItemWithChildren {
text?: string
icon?: string | { svg: string }
items: (NavItemChildren | NavItemWithLink)[]
/**
*
*/
prefix?: string
/**
*
*/
icon?: ThemeIcon
/**
*
*/
items: (string | NavItemChildren | NavItemWithLink)[]
/**
* `activeMatch` is expected to be a regex string. We can't use actual
* RegExp object here because it isn't serializable
*
* `activeMatch`
* 使 RegExp
*/
activeMatch?: string
}

37
theme/src/shared/notes.ts Normal file
View File

@ -0,0 +1,37 @@
import type { SidebarItem } from './sidebar.js'
export interface NotesOptions {
/**
*
* @default '/notes/'
*/
dir: string
/**
*
* @default '/'
*/
link: string
/**
*
*/
notes: NoteItem[]
}
export interface NoteItem {
/**
*
*/
dir: string
/**
* `notes.link`
*/
link: string
/**
*
*/
text?: string
/**
*
*/
sidebar?: 'auto' | (string | SidebarItem)[]
}

View File

@ -1,4 +1,5 @@
import type { ThemeData } from '@vuepress/plugin-theme-data'
import type { LocaleConfig } from 'vuepress/shared'
import type { AutoFrontmatter } from '../auto-frontmatter.js'
import type { PlumeThemeLocaleData } from './locale.js'
import type { PlumeThemePluginOptions } from './plugins.js'
import type { PlumeThemeEncrypt } from './encrypt.js'
@ -23,15 +24,24 @@ export interface PlumeThemeOptions extends PlumeThemeLocaleOptions {
hostname?: string
/**
*
*
*/
encrypt?: PlumeThemeEncrypt
/**
*
*/
configFile?: string
autoFrontmatter?: false | Omit<AutoFrontmatter, 'frontmatter'>
}
export type PlumeThemeLocaleOptions = PlumeThemeData
export type PlumeThemeData = ThemeData<PlumeThemeLocaleData>
export type PlumeThemeData = PlumeThemeLocaleData & {
locales?: LocaleConfig<Omit<PlumeThemeLocaleData, 'blog'>>
}
export * from './locale.js'
export * from './plugins.js'

View File

@ -1,8 +1,9 @@
import type { LocaleData } from 'vuepress/core'
import type { NotesDataOptions } from '@vuepress-plume/plugin-notes-data'
import type { SocialLink, SocialLinkIconUnion, ThemeOutline, ThemeTransition } from '../base.js'
import type { PlumeThemeBlog } from '../blog.js'
import type { NavItem } from '../navbar.js'
import type { SidebarMulti } from '../sidebar.js'
import type { NotesOptions } from '../notes.js'
export interface PlumeThemeLocaleData extends LocaleData {
/**
@ -77,7 +78,12 @@ export interface PlumeThemeLocaleData extends LocaleData {
*
* notes配置到navbar中
*/
notes?: false | NotesDataOptions
notes?: false | NotesOptions
/**
*
*/
sidebar?: SidebarMulti
/**
*

View File

@ -1,6 +1,5 @@
import type { DocsearchOptions } from '@vuepress/plugin-docsearch'
import type { SearchPluginOptions } from '@vuepress-plume/plugin-search'
import type { AutoFrontmatterOptions } from '@vuepress-plume/plugin-auto-frontmatter'
import type { BaiduTongjiOptions } from '@vuepress-plume/plugin-baidu-tongji'
import type { ShikiPluginOptions } from '@vuepress-plume/plugin-shikiji'
import type { CommentPluginOptions } from '@vuepress/plugin-comment'
@ -8,6 +7,7 @@ import type { MarkdownEnhancePluginOptions } from 'vuepress-plugin-md-enhance'
import type { ReadingTimePluginOptions } from '@vuepress/plugin-reading-time'
import type { MarkdownPowerPluginOptions } from 'vuepress-plugin-md-power'
import type { WatermarkPluginOptions } from '@vuepress/plugin-watermark'
import type { AutoFrontmatter } from '../auto-frontmatter.js'
export interface PlumeThemePluginOptions {
/**
@ -59,7 +59,10 @@ export interface PlumeThemePluginOptions {
baiduTongji?: false | BaiduTongjiOptions
frontmatter?: Omit<AutoFrontmatterOptions, 'frontmatter'>
/**
* @deprecated 使 `autoFrontmatter`
*/
frontmatter?: Omit<AutoFrontmatter, 'frontmatter'>
readingTime?: false | ReadingTimePluginOptions

View File

@ -0,0 +1,39 @@
import type { ThemeIcon } from '../base.js'
export type ResolvedNavItem =
| ResolvedNavItemWithLink
| ResolvedNavItemWithChildren
export interface ResolvedNavItemWithLink {
text: string
link: string
icon?: ThemeIcon
items?: never
/**
* `activeMatch` is expected to be a regex string. We can't use actual
* RegExp object here because it isn't serializable
*/
activeMatch?: string
rel?: string
target?: string
noIcon?: boolean
}
export interface ResolvedNavItemChildren {
text?: string
icon?: ThemeIcon
items: ResolvedNavItemWithLink[]
}
export interface ResolvedNavItemWithChildren {
text?: string
icon?: ThemeIcon
items: (ResolvedNavItemChildren | ResolvedNavItemWithLink)[]
/**
* `activeMatch` is expected to be a regex string. We can't use actual
* RegExp object here because it isn't serializable
*/
activeMatch?: string
}

View File

@ -0,0 +1,52 @@
import type { ThemeIcon } from '../base.js'
export type ResolvedSidebar = ResolvedSidebarItem[] | ResolvedSidebarMulti
export type ResolvedSidebarMulti = Record<
string,
ResolvedSidebarItem[] | { items: ResolvedSidebarItem[] }
>
export interface ResolvedSidebarItem {
/**
*
*/
text?: string
/**
*
*/
link?: string
/**
*
*/
icon?: ThemeIcon
/**
*
*/
items?: ResolvedSidebarItem[]
/**
*
*
* `true`
*
* `false`
*/
collapsed?: boolean
/**
*
*/
prefix?: string
/**
* @deprecated 使 `prefix`
*/
dir?: string
rel?: string
target?: string
}

View File

@ -0,0 +1,54 @@
import type { ThemeIcon } from './base.js'
export type Sidebar = 'auto' | (string | SidebarItem)[] | SidebarMulti
export type SidebarMulti = Record<
string,
| 'auto'
| (string | SidebarItem)[]
| { items: 'auto' | (string | SidebarItem)[], prefix?: string }
>
export interface SidebarItem {
/**
*
*/
text?: string
/**
*
*/
link?: string
/**
*
*/
icon?: ThemeIcon
/**
*
*/
items?: 'auto' | (string | SidebarItem)[]
/**
*
*
* `true`
*
* `false`
*/
collapsed?: boolean
/**
*
*/
prefix?: string
/**
* @deprecated 使 `prefix`
*/
dir?: string
rel?: string
target?: string
}

View File

@ -0,0 +1,19 @@
import type { LocaleConfig } from 'vuepress/shared'
import type { PlumeThemeLocaleData } from './options/locale.js'
import type { PlumeThemeEncrypt } from './options/encrypt.js'
import type { AutoFrontmatter } from './auto-frontmatter.js'
export type ThemeConfig = PlumeThemeLocaleData & {
locales?: LocaleConfig<Omit<PlumeThemeLocaleData, 'blog'>>
/**
* frontmatter
*/
autoFrontmatter?: false | Omit<AutoFrontmatter, 'frontmatter'>
/**
*
*/
encrypt?: PlumeThemeEncrypt
}