chore: tweak (#857)
This commit is contained in:
parent
9751059fcd
commit
6db6a58c27
@ -2,6 +2,7 @@ import type { FSWatcher } from 'chokidar'
|
||||
import type { App } from 'vuepress'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { deleteKey } from '@pengzhanbo/utils'
|
||||
import { watch } from 'chokidar'
|
||||
import { compileCode, parseEmbedCode } from './normal.js'
|
||||
import { readFileSync } from './supports/file.js'
|
||||
@ -77,7 +78,7 @@ export function demoWatcher(app: App, watchers: any[]): void {
|
||||
})
|
||||
|
||||
watcher.on('unlink', (path) => {
|
||||
delete tasks[path]
|
||||
deleteKey(tasks, path)
|
||||
watcher!.unwatch(path)
|
||||
})
|
||||
|
||||
|
||||
@ -66,11 +66,12 @@ export interface EmbedRuleBlockOptions<Meta extends Record<string, any>> {
|
||||
*
|
||||
* 创建嵌入规则块
|
||||
*
|
||||
* Syntax: @[name]()
|
||||
* 语法:@[name]()
|
||||
* Syntax: \@\[name]()
|
||||
*
|
||||
* 语法:\@\[name]()
|
||||
*
|
||||
* @param md - Markdown instance / Markdown 实例
|
||||
* @param options - Embed rule block options / 嵌入规则块选项
|
||||
* @param {EmbedRuleBlockOptions} options - Embed rule block options / 嵌入规则块选项
|
||||
* @typeParam Meta - Metadata type / 元数据类型
|
||||
*/
|
||||
export function createEmbedRuleBlock<Meta extends Record<string, any> = Record<string, any>>(
|
||||
|
||||
@ -21,7 +21,7 @@ const REG_HEADING = /^#\s*?([^#\s].*)?\n/
|
||||
* @param md - Markdown instance / Markdown 实例
|
||||
*/
|
||||
export function docsTitlePlugin(md: Markdown): void {
|
||||
const render = md.render
|
||||
const render = md.render.bind(md)
|
||||
md.render = (source, env: MarkdownEnv) => {
|
||||
if (!env.filePathRelative)
|
||||
return render(source, env)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import type { ThemeDocCollection, ThemeOptions } from '../../shared/index.js'
|
||||
import { toArray } from '@pengzhanbo/utils'
|
||||
import { deleteKey, toArray } from '@pengzhanbo/utils'
|
||||
import { removeLeadingSlash } from 'vuepress/shared'
|
||||
import { path } from 'vuepress/utils'
|
||||
|
||||
@ -64,10 +64,8 @@ export function compatBlogAndNotesToCollections(options: ThemeOptions): void {
|
||||
}) as ThemeDocCollection))
|
||||
}
|
||||
}
|
||||
|
||||
delete opt.notes
|
||||
deleteKey(opt, 'notes')
|
||||
}
|
||||
|
||||
delete options.blog
|
||||
delete options.notes
|
||||
deleteKey(options, ['blog', 'notes'])
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import type { Page } from 'vuepress/core'
|
||||
import type { ThemePageData } from '../../shared/index.js'
|
||||
import { toArray } from '@pengzhanbo/utils'
|
||||
import { deleteKey, toArray } from '@pengzhanbo/utils'
|
||||
import pMap from 'p-map'
|
||||
import { genEncrypt } from '../utils/index.js'
|
||||
|
||||
@ -16,5 +16,5 @@ export async function encryptPage(
|
||||
if (password.length) {
|
||||
page.data._e = (await pMap(password, item => genEncrypt(item))).join(':')
|
||||
}
|
||||
delete page.frontmatter.password
|
||||
deleteKey(page.frontmatter, 'password')
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import type { Page } from 'vuepress/core'
|
||||
import type { ThemePageData } from '../../shared/index.js'
|
||||
import { deleteKey } from '@pengzhanbo/utils'
|
||||
import { findCollection } from '../collections/findCollection.js'
|
||||
import { autoCategory } from './autoCategory.js'
|
||||
import { encryptPage } from './encryptPage.js'
|
||||
@ -33,7 +34,7 @@ function cleanPageData(page: Page<ThemePageData>) {
|
||||
|
||||
if (page.frontmatter.home) {
|
||||
page.frontmatter.pageLayout = 'home'
|
||||
delete page.frontmatter.home
|
||||
deleteKey(page.frontmatter, 'home')
|
||||
}
|
||||
|
||||
if (page.headers) {
|
||||
@ -45,14 +46,14 @@ function cleanPageData(page: Page<ThemePageData>) {
|
||||
page.data.type = 'friends'
|
||||
page.permalink = page.permalink ?? '/friends/'
|
||||
page.frontmatter.pageLayout = 'friends'
|
||||
delete page.frontmatter.friends
|
||||
deleteKey(page.frontmatter, 'friends')
|
||||
}
|
||||
|
||||
const pageType = page.frontmatter._pageLayout as string
|
||||
if (pageType) {
|
||||
page.frontmatter.draft = true
|
||||
page.data.type = pageType as any
|
||||
delete page.frontmatter._pageLayout
|
||||
deleteKey(page.frontmatter, '_pageLayout')
|
||||
}
|
||||
|
||||
if (page.frontmatter.pageLayout === 'blog' || page.frontmatter.pageLayout === 'posts') {
|
||||
@ -62,7 +63,7 @@ function cleanPageData(page: Page<ThemePageData>) {
|
||||
|
||||
if ('externalLink' in page.frontmatter) {
|
||||
page.frontmatter.externalLinkIcon = page.frontmatter.externalLink
|
||||
delete page.frontmatter.externalLink
|
||||
deleteKey(page.frontmatter, 'externalLink')
|
||||
}
|
||||
|
||||
// is markdown file
|
||||
|
||||
@ -7,6 +7,7 @@ import type {
|
||||
ThemeSidebar,
|
||||
ThemeSidebarItem,
|
||||
} from '../../shared/index.js'
|
||||
import { deleteKey } from '@pengzhanbo/utils'
|
||||
import {
|
||||
ensureLeadingSlash,
|
||||
entries,
|
||||
@ -191,15 +192,14 @@ function cleanSidebar(sidebar: (ThemeSidebarItem)[]) {
|
||||
if (isPlainObject(item)) {
|
||||
if (isArray(item.items)) {
|
||||
if (item.items.length === 0) {
|
||||
delete item.items
|
||||
delete item.collapsed
|
||||
deleteKey(item, ['items', 'collapsed'])
|
||||
}
|
||||
else {
|
||||
cleanSidebar(item.items as ThemeSidebarItem[])
|
||||
}
|
||||
}
|
||||
else if (!('items' in item)) {
|
||||
delete item.collapsed
|
||||
deleteKey(item, 'collapsed')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user