diff --git a/.commitlintrc.cjs b/.commitlintrc.cjs index d49f81a3..26eade88 100644 --- a/.commitlintrc.cjs +++ b/.commitlintrc.cjs @@ -1,5 +1,5 @@ -const fs = require('fs') -const path = require('path') +const fs = require('node:fs') +const path = require('node:path') const packages = fs.readdirSync(path.resolve(__dirname, 'plugins')) diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 82509958..00000000 --- a/.eslintignore +++ /dev/null @@ -1,9 +0,0 @@ -node_modules/ -.temp/ -.cache/ -lib/ -dist/ -!.vuepress/ -!.*.js -scripts/ -LICENSE diff --git a/.eslintrc.cjs b/.eslintrc.cjs deleted file mode 100644 index 6be809fd..00000000 --- a/.eslintrc.cjs +++ /dev/null @@ -1,57 +0,0 @@ -module.exports = { - root: true, - extends: 'vuepress', - globals: { - __VUEPRESS_VERSION__: 'readonly', - __VUEPRESS_BASE__: 'readonly', - __VUEPRESS_DEV__: 'readonly', - __VUEPRESS_SSR__: 'readonly', - __VUE_HMR_RUNTIME__: 'readonly', - __VUE_OPTIONS_API__: 'readonly', - __VUE_PROD_DEVTOOLS__: 'readonly', - }, - overrides: [ - { - files: ['*.ts', '*.vue', '*.cts'], - extends: 'vuepress-typescript', - parserOptions: { - project: ['tsconfig.json'], - }, - rules: { - '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-non-null-assertion': 'off', - 'vue/multi-word-component-names': 'off', - '@typescript-eslint/explicit-function-return-type': 'off', - 'vue/component-tags-order': [ - 'error', - { - order: ['script', 'template', 'style'], - }, - ], - }, - }, - { - files: ['**/client/config.ts'], - rules: { - 'vue/match-component-file-name': 'off', - }, - }, - { - files: ['**/__tests__/**/*.ts'], - env: { - jest: true, - }, - rules: { - '@typescript-eslint/explicit-function-return-type': 'off', - 'vue/one-component-per-file': 'off', - 'import/no-extraneous-dependencies': 'off', - }, - }, - { - files: ['docs/**/*.ts'], - rules: { - 'import/no-extraneous-dependencies': 'off', - }, - }, - ], -} diff --git a/.vscode/settings.json b/.vscode/settings.json index fb2289d5..038a9c07 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,14 +9,6 @@ "files.trimTrailingWhitespace": false }, "typescript.tsdk": "node_modules/typescript/lib", - "eslint.experimental.useFlatConfig": false, - "eslint.validate": [ - "javascript", - "javascriptreact", - "typescript", - "typescriptreact", - "vue" - ], "cSpell.words": [ "bumpp", "caniuse", diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 00000000..b0d2616e --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,17 @@ +import config from '@pengzhanbo/eslint-config-vue' + +export default config({ + formatters: { + css: false, + }, + ignores: ['.temp', '.cache', 'lib', 'dist', 'docs', '**/*.html'], + globals: { + __VUEPRESS_VERSION__: 'readonly', + __VUEPRESS_BASE__: 'readonly', + __VUEPRESS_DEV__: 'readonly', + __VUEPRESS_SSR__: 'readonly', + __VUE_HMR_RUNTIME__: 'readonly', + __VUE_OPTIONS_API__: 'readonly', + __VUE_PROD_DEVTOOLS__: 'readonly', + }, +}) diff --git a/package.json b/package.json index 5157962e..15d8996f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,11 @@ { "name": "vuepress-theme-plume-monorepo", + "type": "module", "version": "1.0.0-rc.5", "private": true, + "packageManager": "pnpm@8.12.1", + "author": "pengzhanbo", + "license": "MIT", "keywords": [ "vuepress", "vuepress-next", @@ -9,9 +13,10 @@ "vuepress theme", "vuepress-theme-plume" ], - "license": "MIT", - "author": "pengzhanbo", - "type": "module", + "engines": { + "node": ">=16", + "pnpm": ">=7" + }, "scripts": { "autoUpdate": "node scripts/autoInstall.js", "build": "pnpm run build:package", @@ -24,7 +29,7 @@ "docs:build": "pnpm --filter=docs docs:build", "docs:clean": "pnpm --filter=docs docs:clean", "docs:serve": "pnpm --filter=docs docs:serve", - "lint": "eslint --ext .js,.ts,.vue .", + "lint": "eslint .", "pkg": "node scripts/create/index.js", "prepare": "husky install", "release": "pnpm release:check && pnpm release:version && pnpm release:publish", @@ -34,20 +39,10 @@ "release:version": "bumpp package.json plugins/*/package.json theme/package.json --execute=\"pnpm release:changelog\" --commit \"build: publish v%s\" --all --tag --push", "up": "taze -r major" }, - "lint-staged": { - "*.{js,ts,vue}": "eslint --fix", - "*.{json,yml,css,scss}": "prettier --write", - "package.json": "sort-package-json" - }, - "config": { - "commitizen": { - "path": "./node_modules/cz-conventional-changelog" - } - }, - "prettier": "prettier-config-vuepress", "devDependencies": { "@commitlint/cli": "^18.4.3", "@commitlint/config-conventional": "^18.4.3", + "@pengzhanbo/eslint-config-vue": "^1.4.0", "@types/minimist": "^1.2.5", "@types/node": "20.9.1", "@types/webpack-env": "^1.18.4", @@ -60,8 +55,7 @@ "cross-env": "^7.0.3", "cz-conventional-changelog": "^3.3.0", "eslint": "^8.56.0", - "eslint-config-vuepress": "^4.9.0", - "eslint-config-vuepress-typescript": "^4.9.0", + "eslint-plugin-format": "^0.1.0", "execa": "^8.0.1", "handlebars": "^4.7.8", "husky": "^8.0.3", @@ -69,8 +63,6 @@ "minimist": "^1.2.8", "ora": "^8.0.1", "pnpm": "^8.12.1", - "prettier": "^3.1.1", - "prettier-config-vuepress": "^4.4.0", "rimraf": "^5.0.5", "sort-package-json": "^2.6.0", "taze": "^0.13.0", @@ -78,11 +70,6 @@ "typescript": "^5.3.3", "vite": "^5.0.10" }, - "packageManager": "pnpm@8.12.1", - "engines": { - "node": ">=16", - "pnpm": ">=7" - }, "pnpm": { "peerDependencyRules": { "ignoreMissing": [ @@ -99,5 +86,13 @@ "jest" ] } + }, + "lint-staged": { + "*": "eslint --fix" + }, + "config": { + "commitizen": { + "path": "./node_modules/cz-conventional-changelog" + } } } diff --git a/plugins/plugin-auto-frontmatter/README.md b/plugins/plugin-auto-frontmatter/README.md index e4277015..6b0c7ca6 100644 --- a/plugins/plugin-auto-frontmatter/README.md +++ b/plugins/plugin-auto-frontmatter/README.md @@ -9,14 +9,15 @@ yarn add @vuepress-plume/plugin-auto-frontmatter ## Usage ``` js // .vuepress/config.js -import { autoFrontmatterPlugin } from '@vuepress-plume/plugin-auto-frontmatter' +import { autoFrontmatterPlugin } from '@vuepress-plume/plugin-auto-frontmatter' export default { - //... + // ... plugins: [ autoFrontmatterPlugin({ formatter: { createTime(formatTime, file, matter) { - if (formatTime) return formatTime + if (formatTime) + return formatTime return file.createTime } } @@ -32,7 +33,7 @@ export default { `{ include?: string | string[]; exclude?: string | string[]; formatter: Formatter }` -- `include` +- `include` include 匹配字符串或数组,匹配需要自动生成 `frontmatter` 的 md文件。 默认预设为 `['**/*.md']`。 @@ -70,14 +71,15 @@ export default { /** * formatterObj 对象中的 key 即为 frontmatter 配置中的key * 其方法返回的值将作为 frontmatter[key] 的值 - * *.md + * .md * --- * createTime: 2022-03-26T11:46:50.000Z * --- */ - const formatterObj: Formatter = { + const formatterObj: Formatter = { createTime(formatTime, file, matter) { - if (formatTime) return formatTime + if (formatTime) + return formatTime return file.createTime } } @@ -92,25 +94,24 @@ export default { return value } }, - { - // 通配,如果文件没有被其他精细glob命中, - // 则使用 通配 formatter - // 如果是数组,必须有且用一个 include 为 * 的 项 - include: '*', - formatter: { - title(title) { - return title || '默认标题' - } + }, + { + // 通配,如果文件没有被其他精细glob命中, + // 则使用 通配 formatter + // 如果是数组,必须有且用一个 include 为 * 的 项 + include: '*', + formatter: { + title(title) { + return title || '默认标题' } } } ] - - ``` +``` ## Why ? - **为什么需要这个插件?** - + 有时候在开发一些主题时,期望使用户更专注于内容的编写,尽可能减少配置性的工作,可以将一些重复性的必要的配置 直接通过本插件自动生成。 diff --git a/plugins/plugin-auto-frontmatter/package.json b/plugins/plugin-auto-frontmatter/package.json index a06b3695..dc28e849 100644 --- a/plugins/plugin-auto-frontmatter/package.json +++ b/plugins/plugin-auto-frontmatter/package.json @@ -1,18 +1,18 @@ { "name": "@vuepress-plume/plugin-auto-frontmatter", + "type": "module", "version": "1.0.0-rc.5", "description": "The Plugin for VuePres 2", + "author": "pengzhanbo ", + "license": "MIT", "homepage": "https://github.com/pengzhanbo/vuepress-theme-plume#readme", - "bugs": { - "url": "https://github.com/pengzhanbo/vuepress-theme-plume/issues" - }, "repository": { "type": "git", "url": "git+https://github.com/pengzhanbo/vuepress-theme-plume.git" }, - "license": "MIT", - "author": "pengzhanbo ", - "type": "module", + "bugs": { + "url": "https://github.com/pengzhanbo/vuepress-theme-plume/issues" + }, "exports": { ".": "./lib/node/index.js", "./package.json": "./package.json" diff --git a/plugins/plugin-auto-frontmatter/src/node/plugin.ts b/plugins/plugin-auto-frontmatter/src/node/plugin.ts index 3476c822..0f6ea55d 100644 --- a/plugins/plugin-auto-frontmatter/src/node/plugin.ts +++ b/plugins/plugin-auto-frontmatter/src/node/plugin.ts @@ -13,11 +13,11 @@ import type { import { readMarkdown, readMarkdownList } from './readFiles.js' import { ensureArray, isEmptyObject } from './utils.js' -export const autoFrontmatterPlugin = ({ +export function autoFrontmatterPlugin({ include = ['**/*.{md,MD}'], exclude = ['.vuepress/**/*', 'node_modules'], frontmatter = {}, -}: AutoFrontmatterOptions = {}): Plugin => { +}: AutoFrontmatterOptions = {}): Plugin { include = ensureArray(include) exclude = ensureArray(exclude) @@ -27,8 +27,8 @@ export const autoFrontmatterPlugin = ({ ? frontmatter : [{ include: '*', frontmatter }] - const globFormatter: FrontmatterObject = - matterFrontmatter.find(({ include }) => include === '*')?.frontmatter || {} + const globFormatter: FrontmatterObject + = matterFrontmatter.find(({ include }) => include === '*')?.frontmatter || {} const otherFormatters = matterFrontmatter .filter(({ include }) => include !== '*') @@ -56,14 +56,15 @@ export const autoFrontmatterPlugin = ({ const yaml = isEmptyObject(data) ? '' : jsonToYaml - .stringify(data) - .replace(/\n\s{2}/g, '\n') - .replace(/"/g, '') + .stringify(data) + .replace(/\n\s{2}/g, '\n') + .replace(/"/g, '') const newContent = yaml ? `${yaml}---\n${content}` : content fs.writeFileSync(filepath, newContent, 'utf-8') - } catch (e) { - console.log(e) + } + catch (e) { + console.error(e) } } @@ -71,9 +72,8 @@ export const autoFrontmatterPlugin = ({ name: '@vuepress-plume/plugin-auto-frontmatter', onInitialized: async (app) => { const markdownList = await readMarkdownList(app.dir.source(), globFilter) - for (const file of markdownList) { + for (const file of markdownList) await formatMarkdown(file) - } }, onWatched: async (app, watchers) => { const watcher = chokidar.watch('**/*.md', { @@ -83,7 +83,8 @@ export const autoFrontmatterPlugin = ({ }) watcher.on('add', async (relativePath) => { - if (!globFilter(relativePath)) return + if (!globFilter(relativePath)) + return await formatMarkdown(readMarkdown(app.dir.source(), relativePath)) }) diff --git a/plugins/plugin-auto-frontmatter/src/node/readFiles.ts b/plugins/plugin-auto-frontmatter/src/node/readFiles.ts index e6b41fef..6b7a8093 100644 --- a/plugins/plugin-auto-frontmatter/src/node/readFiles.ts +++ b/plugins/plugin-auto-frontmatter/src/node/readFiles.ts @@ -5,24 +5,18 @@ import type { MarkdownFile } from '../shared/index.js' type MarkdownFileList = MarkdownFile[] -export const readMarkdownList = async ( - sourceDir: string, - filter: (id: string) => boolean -): Promise => { +export async function readMarkdownList(sourceDir: string, filter: (id: string) => boolean): Promise { const files: string[] = await fg(['**/*.md'], { cwd: sourceDir, ignore: ['node_modules', '.vuepress'], }) return files - .filter((file) => filter(file)) - .map((file) => readMarkdown(sourceDir, file)) + .filter(file => filter(file)) + .map(file => readMarkdown(sourceDir, file)) } -export const readMarkdown = ( - sourceDir: string, - relativePath: string -): MarkdownFile => { +export function readMarkdown(sourceDir: string, relativePath: string): MarkdownFile { const filepath = path.join(sourceDir, relativePath) const stats = fs.statSync(filepath) return { @@ -34,6 +28,6 @@ export const readMarkdown = ( } } -export const getFileCreateTime = (stats: fs.Stats): Date => { +export function getFileCreateTime(stats: fs.Stats): Date { return stats.birthtime.getFullYear() !== 1970 ? stats.birthtime : stats.atime } diff --git a/plugins/plugin-auto-frontmatter/src/node/utils.ts b/plugins/plugin-auto-frontmatter/src/node/utils.ts index f0dec1ee..4ba1705d 100644 --- a/plugins/plugin-auto-frontmatter/src/node/utils.ts +++ b/plugins/plugin-auto-frontmatter/src/node/utils.ts @@ -1,6 +1,8 @@ export function ensureArray(thing: T | T[] | null | undefined): T[] { - if (Array.isArray(thing)) return thing - if (thing === null || thing === undefined) return [] + if (Array.isArray(thing)) + return thing + if (thing === null || thing === undefined) + return [] return [thing] } diff --git a/plugins/plugin-auto-frontmatter/src/shared/index.ts b/plugins/plugin-auto-frontmatter/src/shared/index.ts index cc58c19f..cd1f8cf7 100644 --- a/plugins/plugin-auto-frontmatter/src/shared/index.ts +++ b/plugins/plugin-auto-frontmatter/src/shared/index.ts @@ -1,4 +1,5 @@ import type fs from 'node:fs' + export interface MarkdownFile { filepath: string relativePath: string @@ -13,7 +14,7 @@ export type FrontmatterFn = ( data: K ) => T | PromiseLike -export type FrontmatterObject = Record>; +export type FrontmatterObject = Record> export type FrontmatterArray = { include: string | string[] diff --git a/plugins/plugin-auto-frontmatter/tsconfig.build.json b/plugins/plugin-auto-frontmatter/tsconfig.build.json index e4e8ce38..809551b3 100644 --- a/plugins/plugin-auto-frontmatter/tsconfig.build.json +++ b/plugins/plugin-auto-frontmatter/tsconfig.build.json @@ -4,6 +4,6 @@ "rootDir": "./src", "outDir": "./lib" }, - "include": ["./src"], - "files": [] + "files": [], + "include": ["./src"] } diff --git a/plugins/plugin-baidu-tongji/README.md b/plugins/plugin-baidu-tongji/README.md index 5f842812..733692d2 100644 --- a/plugins/plugin-baidu-tongji/README.md +++ b/plugins/plugin-baidu-tongji/README.md @@ -11,7 +11,7 @@ yarn add @vuepress-plume/plugin-baidu-tongji // .vuepress/config.js const { baiduTongjiPlugin } = require('@vuepress-plume/plugin-baidu-tongji') module.exports = { - //... + // ... plugins: [ baiduTongjiPlugin({ key: '', // 百度统计使用的 key diff --git a/plugins/plugin-baidu-tongji/package.json b/plugins/plugin-baidu-tongji/package.json index ce5d4e98..6b1d5138 100644 --- a/plugins/plugin-baidu-tongji/package.json +++ b/plugins/plugin-baidu-tongji/package.json @@ -1,18 +1,18 @@ { "name": "@vuepress-plume/plugin-baidu-tongji", + "type": "module", "version": "1.0.0-rc.5", "description": "The Plugin for VuePres 2", + "author": "pengzhanbo (https://github.com/pengzhanbo/)", + "license": "MIT", "homepage": "https://github.com/pengzhanbo/vuepress-theme-plume#readme", - "bugs": { - "url": "https://github.com/pengzhanbo/vuepress-theme-plume/issues" - }, "repository": { "type": "git", "url": "git+https://github.com/pengzhanbo/vuepress-theme-plume.git" }, - "license": "MIT", - "author": "pengzhanbo (https://github.com/pengzhanbo/)", - "type": "module", + "bugs": { + "url": "https://github.com/pengzhanbo/vuepress-theme-plume/issues" + }, "exports": { ".": "./lib/node/index.js", "./package.json": "./package.json" diff --git a/plugins/plugin-baidu-tongji/src/node/plugin.ts b/plugins/plugin-baidu-tongji/src/node/plugin.ts index 09f37aba..78b16658 100644 --- a/plugins/plugin-baidu-tongji/src/node/plugin.ts +++ b/plugins/plugin-baidu-tongji/src/node/plugin.ts @@ -4,11 +4,11 @@ export interface BaiduTongjiOptions { key?: string } -export const baiduTongjiPlugin = ({ key = '' }: BaiduTongjiOptions): Plugin => { +export function baiduTongjiPlugin({ key = '' }: BaiduTongjiOptions): Plugin { return { name: '@vuepress-plume/plugin-baidu-tongji', extendsPage: (page) => { - page.frontmatter.head = page.frontmatter.head || []; + page.frontmatter.head = page.frontmatter.head || [] page.frontmatter.head?.push([ 'script', { diff --git a/plugins/plugin-baidu-tongji/tsconfig.build.json b/plugins/plugin-baidu-tongji/tsconfig.build.json index 9a9c1efa..8445d924 100644 --- a/plugins/plugin-baidu-tongji/tsconfig.build.json +++ b/plugins/plugin-baidu-tongji/tsconfig.build.json @@ -1,10 +1,10 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { + "composite": true, "rootDir": "./src", - "outDir": "./lib", - "composite": true + "outDir": "./lib" }, - "include": ["./src"], - "files": [] + "files": [], + "include": ["./src"] } diff --git a/plugins/plugin-blog-data/README.md b/plugins/plugin-blog-data/README.md index cc619c6d..e0afe43c 100644 --- a/plugins/plugin-blog-data/README.md +++ b/plugins/plugin-blog-data/README.md @@ -9,7 +9,7 @@ yarn add @vuepress-plume/plugin-blog-data // .vuepress/config.js const { blogDataPlugin } = require('@vuepress-plume/plugin-blog-data') module.exports = { - //... + // ... plugins: [ blogDataPlugin() ] diff --git a/plugins/plugin-blog-data/package.json b/plugins/plugin-blog-data/package.json index 41235b1e..68f1a881 100644 --- a/plugins/plugin-blog-data/package.json +++ b/plugins/plugin-blog-data/package.json @@ -1,18 +1,18 @@ { "name": "@vuepress-plume/plugin-blog-data", + "type": "module", "version": "1.0.0-rc.5", "description": "The Plugin for VuePres 2", + "author": "pengzhanbo ", + "license": "MIT", "homepage": "https://github.com/pengzhanbo/vuepress-theme-plume#readme", - "bugs": { - "url": "https://github.com/pengzhanbo/vuepress-theme-plume/issues" - }, "repository": { "type": "git", "url": "git+https://github.com/pengzhanbo/vuepress-theme-plume.git" }, - "license": "MIT", - "author": "pengzhanbo ", - "type": "module", + "bugs": { + "url": "https://github.com/pengzhanbo/vuepress-theme-plume/issues" + }, "exports": { ".": "./lib/node/index.js", "./client": "./lib/client/index.js", diff --git a/plugins/plugin-blog-data/src/client/composables/useBlogPostData.ts b/plugins/plugin-blog-data/src/client/composables/useBlogPostData.ts index 222caea7..b302671f 100644 --- a/plugins/plugin-blog-data/src/client/composables/useBlogPostData.ts +++ b/plugins/plugin-blog-data/src/client/composables/useBlogPostData.ts @@ -9,9 +9,11 @@ export type BlogDataRef = Ref export const blogPostData: BlogDataRef = ref(blogPostDataRaw) -export const useBlogPostData = < - T extends BlogPostData = BlogPostData ->(): BlogDataRef => blogPostData as BlogDataRef +export function useBlogPostData< + T extends BlogPostData = BlogPostData, +>(): BlogDataRef { + return blogPostData as BlogDataRef +} if (import.meta.webpackHot || import.meta.hot) { __VUE_HMR_RUNTIME__.updateBlogData = (data: BlogPostData) => { diff --git a/plugins/plugin-blog-data/src/client/config.ts b/plugins/plugin-blog-data/src/client/config.ts index 162c3523..c1f026b5 100644 --- a/plugins/plugin-blog-data/src/client/config.ts +++ b/plugins/plugin-blog-data/src/client/config.ts @@ -30,7 +30,7 @@ export default defineClientConfig({ value: blogPostData.value, }) }) - } + }, ) } }, diff --git a/plugins/plugin-blog-data/src/client/index.ts b/plugins/plugin-blog-data/src/client/index.ts index 40d69ccf..f07e6cc1 100644 --- a/plugins/plugin-blog-data/src/client/index.ts +++ b/plugins/plugin-blog-data/src/client/index.ts @@ -1,4 +1,5 @@ import type { BlogPostData, BlogPostDataItem } from '../shared/index.js' + export * from './composables/index.js' export type { BlogPostData, BlogPostDataItem } diff --git a/plugins/plugin-blog-data/src/node/plugin.ts b/plugins/plugin-blog-data/src/node/plugin.ts index a5b9fe83..db19a4b6 100644 --- a/plugins/plugin-blog-data/src/node/plugin.ts +++ b/plugins/plugin-blog-data/src/node/plugin.ts @@ -9,11 +9,11 @@ const __dirname = getDirname(import.meta.url) export type PluginOption = Omit -export const blogDataPlugin = ({ +export function blogDataPlugin({ include, exclude, ...pluginOptions -}: BlogDataPluginOptions = {}): Plugin => { +}: BlogDataPluginOptions = {}): Plugin { const pageFilter = createFilter(toArray(include), toArray(exclude), { resolve: false, }) @@ -26,7 +26,7 @@ export const blogDataPlugin = ({ ;(page.data as any).isBlogPost = true } }, - onPrepared: async (app) => + onPrepared: async app => await preparedBlogData(app, pageFilter, pluginOptions), onWatched(app, watchers) { const watcher = chokidar.watch('pages/**/*', { @@ -36,15 +36,15 @@ export const blogDataPlugin = ({ watcher.on( 'add', - async () => await preparedBlogData(app, pageFilter, pluginOptions) + async () => await preparedBlogData(app, pageFilter, pluginOptions), ) watcher.on( 'change', - async () => await preparedBlogData(app, pageFilter, pluginOptions) + async () => await preparedBlogData(app, pageFilter, pluginOptions), ) watcher.on( 'unlink', - async () => await preparedBlogData(app, pageFilter, pluginOptions) + async () => await preparedBlogData(app, pageFilter, pluginOptions), ) watchers.push(watcher) @@ -53,6 +53,7 @@ export const blogDataPlugin = ({ } function toArray(likeArr: string | string[] | undefined): string[] { - if (Array.isArray(likeArr)) return likeArr + if (Array.isArray(likeArr)) + return likeArr return likeArr ? [likeArr] : [] } diff --git a/plugins/plugin-blog-data/src/node/prepareBlogData.ts b/plugins/plugin-blog-data/src/node/prepareBlogData.ts index 445cb3ec..da91e40e 100644 --- a/plugins/plugin-blog-data/src/node/prepareBlogData.ts +++ b/plugins/plugin-blog-data/src/node/prepareBlogData.ts @@ -17,33 +17,30 @@ if (import.meta.hot) { } ` -const getTimestamp = (time: Date): number => { +function getTimestamp(time: Date): number { return new Date(time).getTime() } const EXCERPT_SPLIT = '' -export const preparedBlogData = async ( - app: App, - pageFilter: (id: string) => boolean, - options: PluginOption -): Promise => { +export async function preparedBlogData(app: App, pageFilter: (id: string) => boolean, options: PluginOption): Promise { let pages = app.pages.filter((page) => { return page.filePathRelative && pageFilter(page.filePathRelative) }) - if (options.pageFilter) { + if (options.pageFilter) pages = pages.filter(options.pageFilter) - } + if (options.sortBy) { pages = pages.sort((prev, next) => { if (options.sortBy === 'createTime') { - return getTimestamp(prev.frontmatter.createTime as Date) < - getTimestamp(next.frontmatter.createTime as Date) + return getTimestamp(prev.frontmatter.createTime as Date) + < getTimestamp(next.frontmatter.createTime as Date) ? 1 : -1 - } else { - return typeof options.sortBy === 'function' && - options.sortBy(prev, next) + } + else { + return typeof options.sortBy === 'function' + && options.sortBy(prev, next) ? 1 : -1 } @@ -52,9 +49,9 @@ export const preparedBlogData = async ( const blogData: BlogPostData = pages.map((page: Page) => { let extended: Partial = {} - if (typeof options.extendBlogData === 'function') { + if (typeof options.extendBlogData === 'function') extended = options.extendBlogData(page) - } + const data = { path: page.path, title: page.title, @@ -71,14 +68,13 @@ export const preparedBlogData = async ( let content = `\ export const blogPostData = JSON.parse(${JSON.stringify( - JSON.stringify(blogData) + JSON.stringify(blogData), )}) ` // inject HMR code - if (app.env.isDev) { + if (app.env.isDev) content += HMR_CODE - } await app.writeTemp('internal/blogData.js', content) } diff --git a/plugins/plugin-blog-data/tsconfig.build.json b/plugins/plugin-blog-data/tsconfig.build.json index 2f53b066..1c7921a2 100644 --- a/plugins/plugin-blog-data/tsconfig.build.json +++ b/plugins/plugin-blog-data/tsconfig.build.json @@ -1,13 +1,13 @@ { "extends": "../tsconfig.build.json", "compilerOptions": { - "rootDir": "./src", - "outDir": "./lib", "baseUrl": ".", + "rootDir": "./src", "paths": { "@internal/blogData": ["./src/client/blogPostData.d.ts"] }, - "types": ["@vuepress/client/types", "vite/client", "webpack-env"] + "types": ["@vuepress/client/types", "vite/client", "webpack-env"], + "outDir": "./lib" }, "include": ["./src"] } diff --git a/plugins/plugin-caniuse/README.md b/plugins/plugin-caniuse/README.md index e4e3fbdc..ab0905a6 100644 --- a/plugins/plugin-caniuse/README.md +++ b/plugins/plugin-caniuse/README.md @@ -10,7 +10,7 @@ yarn add @vuepress-plume/plugin-caniuse // .vuepress/config.js const { caniusePlugin } = require('@vuepress-plume/plugin-caniuse') module.exports = { - //... + // ... plugins: [ caniusePlugin({ mode: 'embed' }) ] diff --git a/plugins/plugin-caniuse/package.json b/plugins/plugin-caniuse/package.json index 28b20d04..30f1bab1 100644 --- a/plugins/plugin-caniuse/package.json +++ b/plugins/plugin-caniuse/package.json @@ -1,7 +1,18 @@ { "name": "@vuepress-plume/plugin-caniuse", + "type": "module", "version": "1.0.0-rc.5", "description": "The Plugin for VuePres 2, Support Can-I-Use feature", + "author": "pengzhanbo ", + "license": "MIT", + "homepage": "https://github.com/pengzhanbo/vuepress-theme-plume#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/pengzhanbo/vuepress-theme-plume.git" + }, + "bugs": { + "url": "https://github.com/pengzhanbo/vuepress-theme-plume/issues" + }, "keywords": [ "VuePress", "plugin", @@ -9,17 +20,6 @@ "can-i-use", "caniuse" ], - "homepage": "https://github.com/pengzhanbo/vuepress-theme-plume#readme", - "bugs": { - "url": "https://github.com/pengzhanbo/vuepress-theme-plume/issues" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/pengzhanbo/vuepress-theme-plume.git" - }, - "license": "MIT", - "author": "pengzhanbo ", - "type": "module", "exports": { ".": "./lib/node/index.js", "./client": "./lib/client/index.js", diff --git a/plugins/plugin-caniuse/src/client/clientConfig.ts b/plugins/plugin-caniuse/src/client/clientConfig.ts index 402e7541..962fa046 100644 --- a/plugins/plugin-caniuse/src/client/clientConfig.ts +++ b/plugins/plugin-caniuse/src/client/clientConfig.ts @@ -9,12 +9,12 @@ const mode = __CAN_I_USE_INJECT_MODE__ export default defineClientConfig({ enhance({ router }) { - if (__VUEPRESS_SSR__) return + if (__VUEPRESS_SSR__) + return - router.afterEach((to, from) => { - if (mode === 'embed') { + router.afterEach(() => { + if (mode === 'embed') resolveCanIUse() - } }) }, }) diff --git a/plugins/plugin-caniuse/src/client/resolveCanIUse.ts b/plugins/plugin-caniuse/src/client/resolveCanIUse.ts index e78bb8e7..1530b7aa 100644 --- a/plugins/plugin-caniuse/src/client/resolveCanIUse.ts +++ b/plugins/plugin-caniuse/src/client/resolveCanIUse.ts @@ -1,17 +1,18 @@ let isBind = false -export const resolveCanIUse = (): void => { - if (isBind) return +export function resolveCanIUse(): void { + if (isBind) + return isBind = true window.addEventListener('message', (message) => { const data = message.data - if (typeof data === 'string' && data.indexOf('ciu_embed') > -1) { + if (typeof data === 'string' && data.includes('ciu_embed')) { const [, feature, height] = data.split(':') const el = document.querySelector(`.ciu_embed[data-feature="${feature}"]`) if (el) { - const h = parseInt(height) + 30 - ;(el.childNodes[0] as any).height = h + 'px' + const h = Number.parseInt(height) + 30 + ;(el.childNodes[0] as any).height = `${h}px` } } }) diff --git a/plugins/plugin-caniuse/src/node/markdown-it-container.d.ts b/plugins/plugin-caniuse/src/node/markdown-it-container.d.ts index 84e449f7..44347be7 100644 --- a/plugins/plugin-caniuse/src/node/markdown-it-container.d.ts +++ b/plugins/plugin-caniuse/src/node/markdown-it-container.d.ts @@ -1,5 +1,6 @@ declare module 'markdown-it-container' { import type { PluginWithParams } from 'markdown-it' + const container: PluginWithParams export = container } diff --git a/plugins/plugin-caniuse/src/node/plugin.ts b/plugins/plugin-caniuse/src/node/plugin.ts index 496103b0..09d9b943 100644 --- a/plugins/plugin-caniuse/src/node/plugin.ts +++ b/plugins/plugin-caniuse/src/node/plugin.ts @@ -9,9 +9,9 @@ const __dirname = getDirname(import.meta.url) const modeMap: CanIUseMode[] = ['image', 'embed'] const isMode = (mode: CanIUseMode): boolean => modeMap.includes(mode) -export const caniusePlugin = ({ +export function caniusePlugin({ mode = modeMap[0], -}: CanIUsePluginOptions): Plugin => { +}: CanIUsePluginOptions): Plugin { mode = isMode(mode) ? mode : modeMap[0] const type = 'caniuse' const validateReg = new RegExp(`^${type}\\s+(.*)$`) @@ -32,7 +32,8 @@ export const caniusePlugin = ({ if (token.nesting === 1) { const feature = token.info.trim().slice(type.length).trim() || '' return feature ? resolveCanIUse(feature, mode) : '' - } else { + } + else { return '' } } diff --git a/plugins/plugin-caniuse/src/node/resolveCanIUse.ts b/plugins/plugin-caniuse/src/node/resolveCanIUse.ts index a9aac7e9..cf8ee547 100644 --- a/plugins/plugin-caniuse/src/node/resolveCanIUse.ts +++ b/plugins/plugin-caniuse/src/node/resolveCanIUse.ts @@ -1,6 +1,8 @@ import type { CanIUseMode } from '../shared/index.js' -export const resolveCanIUse = (feature: string, mode: CanIUseMode): string => { - if (!feature) return '' + +export function resolveCanIUse(feature: string, mode: CanIUseMode): string { + if (!feature) + return '' if (mode === 'image') { return ` diff --git a/plugins/plugin-copy-code/README.md b/plugins/plugin-copy-code/README.md index 9135f4ca..c868f9c6 100644 --- a/plugins/plugin-copy-code/README.md +++ b/plugins/plugin-copy-code/README.md @@ -9,7 +9,7 @@ yarn add @vuepress-plume/plugin-copy-code // .vuepress/config.js const { copyCodePlugin } = require('@vuepress-plume/plugin-copy-code') module.exports = { - //... + // ... plugins: [ copyCodePlugin() ] diff --git a/plugins/plugin-copy-code/package.json b/plugins/plugin-copy-code/package.json index 8a197e4d..c2cc8583 100644 --- a/plugins/plugin-copy-code/package.json +++ b/plugins/plugin-copy-code/package.json @@ -1,18 +1,18 @@ { "name": "@vuepress-plume/plugin-copy-code", + "type": "module", "version": "1.0.0-rc.5", "description": "The Plugin for VuePres 2", + "author": "pengzhanbo ", + "license": "MIT", "homepage": "https://github.com/pengzhanbo/vuepress-theme-plume#readme", - "bugs": { - "url": "https://github.com/pengzhanbo/vuepress-theme-plume/issues" - }, "repository": { "type": "git", "url": "git+https://github.com/pengzhanbo/vuepress-theme-plume.git" }, - "license": "MIT", - "author": "pengzhanbo ", - "type": "module", + "bugs": { + "url": "https://github.com/pengzhanbo/vuepress-theme-plume/issues" + }, "exports": { ".": "./lib/node/index.js", "./client": "./lib/client/index.js", diff --git a/plugins/plugin-copy-code/src/client/composables/copyToClipboard.ts b/plugins/plugin-copy-code/src/client/composables/copyToClipboard.ts index c48ae693..8cb0eed1 100644 --- a/plugins/plugin-copy-code/src/client/composables/copyToClipboard.ts +++ b/plugins/plugin-copy-code/src/client/composables/copyToClipboard.ts @@ -1,7 +1,7 @@ -export const copyToClipboard = (str: string): void => { +export function copyToClipboard(str: string): void { const selection = document.getSelection() - const selectedRange = - selection && selection.rangeCount > 0 ? selection.getRangeAt(0) : false + const selectedRange + = selection && selection.rangeCount > 0 ? selection.getRangeAt(0) : false const textEl = document.createElement('textarea') diff --git a/plugins/plugin-copy-code/src/client/composables/setup.ts b/plugins/plugin-copy-code/src/client/composables/setup.ts index 5795d03f..076d25d2 100644 --- a/plugins/plugin-copy-code/src/client/composables/setup.ts +++ b/plugins/plugin-copy-code/src/client/composables/setup.ts @@ -2,37 +2,40 @@ import { onMounted, watch } from 'vue' import { useRoute } from 'vue-router' import type { CopyCodeOptions } from '../../shared/index.js' import { copyToClipboard } from './copyToClipboard.js' + declare const __COPY_CODE_OPTIONS__: CopyCodeOptions const options = __COPY_CODE_OPTIONS__ -const isMobile = (): boolean => - navigator +function isMobile(): boolean { + return navigator ? /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/iu.test( - navigator.userAgent - ) + navigator.userAgent, + ) : false +} -export const setupCopyCode = (): void => { +export function setupCopyCode(): void { const route = useRoute() const insertBtn = (codeBlockEl: HTMLElement): void => { - if (codeBlockEl.hasAttribute('has-copy-code')) return + if (codeBlockEl.hasAttribute('has-copy-code')) + return const button = document.createElement('button') button.className = 'copy-code-button' button.addEventListener('click', () => { - copyToClipboard(codeBlockEl.innerText) + copyToClipboard(codeBlockEl.textContent || '') button.classList.add('copied') - options.duration && - setTimeout(() => { - button.classList.remove('copied') - }, options.duration) + options.duration + && setTimeout(() => { + button.classList.remove('copied') + }, options.duration) }) - if (codeBlockEl.parentElement) { + if (codeBlockEl.parentElement) codeBlockEl.parentElement.insertBefore(button, codeBlockEl) - } + codeBlockEl.setAttribute('has-copy-code', '') } @@ -41,7 +44,8 @@ export const setupCopyCode = (): void => { setTimeout(() => { if (typeof selector === 'string') { document.querySelectorAll(selector).forEach(insertBtn) - } else if (Array.isArray(selector)) { + } + else if (Array.isArray(selector)) { selector.forEach((item) => { document.querySelectorAll(item).forEach(insertBtn) }) @@ -50,16 +54,14 @@ export const setupCopyCode = (): void => { } onMounted(() => { - if (!isMobile() || options.showInMobile) { + if (!isMobile() || options.showInMobile) generateButton() - } }) watch( () => route.path, () => { - if (!isMobile() || options.showInMobile) { + if (!isMobile() || options.showInMobile) generateButton() - } - } + }, ) } diff --git a/plugins/plugin-copy-code/src/node/plugin.ts b/plugins/plugin-copy-code/src/node/plugin.ts index 02aae06a..5e1acc1d 100644 --- a/plugins/plugin-copy-code/src/node/plugin.ts +++ b/plugins/plugin-copy-code/src/node/plugin.ts @@ -11,9 +11,7 @@ const defaultOptions: CopyCodeOptions = { showInMobile: false, } - -export const copyCodePlugin = (options: CopyCodeOptions): Plugin => { - +export function copyCodePlugin(options: CopyCodeOptions): Plugin { options = Object.assign({}, defaultOptions, options) return { diff --git a/plugins/plugin-iconify/README.md b/plugins/plugin-iconify/README.md index e7b80342..b478d7ad 100644 --- a/plugins/plugin-iconify/README.md +++ b/plugins/plugin-iconify/README.md @@ -11,7 +11,7 @@ yarn add @vuepress-plume/plugin-iconify // .vuepress/config.js const iconifyPlugin = require('@vuepress-plume/plugin-iconify') module.exports = { - //... + // ... plugins: [ iconifyPlugin() ] @@ -30,7 +30,6 @@ interface IconifyOptions { color?: string size?: string | number } - ``` ## Component diff --git a/plugins/plugin-iconify/package.json b/plugins/plugin-iconify/package.json index 5c55c28b..a4529bf8 100644 --- a/plugins/plugin-iconify/package.json +++ b/plugins/plugin-iconify/package.json @@ -1,18 +1,18 @@ { "name": "@vuepress-plume/plugin-iconify", + "type": "module", "version": "1.0.0-rc.5", "description": "The Plugin for VuePres 2", + "author": "pengzhanbo ", + "license": "MIT", "homepage": "https://github.com/pengzhanbo/vuepress-theme-plume#readme", - "bugs": { - "url": "https://github.com/pengzhanbo/vuepress-theme-plume/issues" - }, "repository": { "type": "git", "url": "git+https://github.com/pengzhanbo/vuepress-theme-plume.git" }, - "license": "MIT", - "author": "pengzhanbo ", - "type": "module", + "bugs": { + "url": "https://github.com/pengzhanbo/vuepress-theme-plume/issues" + }, "exports": { ".": "./lib/node/index.js", "./client": "./lib/client/index.js", diff --git a/plugins/plugin-iconify/src/client/components/Iconify.vue b/plugins/plugin-iconify/src/client/components/Iconify.vue index a8130a9c..34df1bfb 100644 --- a/plugins/plugin-iconify/src/client/components/Iconify.vue +++ b/plugins/plugin-iconify/src/client/components/Iconify.vue @@ -15,7 +15,7 @@ const props = withDefaults( name: '', size: '', color: '', - } + }, ) const { name } = toRefs(props) @@ -24,9 +24,9 @@ const { icon, loaded } = useIconify(name) const size = computed(() => { const size = props.size || __VUEPRESS_PLUGIN_ICONIFY_DEFAULT_SIZE__ - if (String(Number(size)) === size) { + if (String(Number(size)) === size) return `${size}px` - } + return size }) const iconStyle = computed(() => { @@ -46,7 +46,7 @@ declare const __VUEPRESS_PLUGIN_ICONIFY_DEFAULT_COLOR__: string + diff --git a/theme/src/client/components/PageMeta.vue b/theme/src/client/components/PageMeta.vue index 66e73638..6ea516cb 100644 --- a/theme/src/client/components/PageMeta.vue +++ b/theme/src/client/components/PageMeta.vue @@ -15,9 +15,9 @@ const matter = usePageFrontmatter() const readingTime = useReadingTime() const createTime = computed(() => { - if (matter.value.createTime) { + if (matter.value.createTime) return matter.value.createTime.split(' ')[0].replace(/\//g, '-') - } + return '' }) @@ -26,14 +26,15 @@ const categoryList = computed(() => { }) const tags = computed(() => { - if (matter.value.tags) { + if (matter.value.tags) return matter.value.tags.slice(0, 4) - } + return [] }) const hasMeta = computed(() => readingTime.value.times || tags.value.length || createTime.value) +