chore: tweak (#857)

This commit is contained in:
pengzhanbo 2026-02-15 11:32:47 +08:00 committed by GitHub
parent 9751059fcd
commit 6db6a58c27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 20 additions and 19 deletions

View File

@ -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)
})

View File

@ -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>>(

View File

@ -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)

View File

@ -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'])
}

View File

@ -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')
}

View File

@ -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

View 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')
}
}
}