From 53bca6a680d4eb3296802fe33e2ba424138cedfb Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Sat, 1 Jul 2023 16:06:45 +0800 Subject: [PATCH] fix: auto frontmatter fail --- .../plugin-auto-frontmatter/src/node/index.ts | 6 ++--- .../src/node/plugin.ts | 24 ++++++++--------- .../src/shared/index.ts | 12 ++++----- packages/theme/src/client/config.ts | 4 +-- .../theme/src/client/styles/normalize.scss | 22 ++++++++++------ packages/theme/src/client/styles/vars.scss | 8 +++--- packages/theme/src/node/autoFrontmatter.ts | 26 +++++++++---------- 7 files changed, 54 insertions(+), 48 deletions(-) diff --git a/packages/plugin-auto-frontmatter/src/node/index.ts b/packages/plugin-auto-frontmatter/src/node/index.ts index 8efa6479..290e03c2 100644 --- a/packages/plugin-auto-frontmatter/src/node/index.ts +++ b/packages/plugin-auto-frontmatter/src/node/index.ts @@ -1,12 +1,12 @@ import type { AutoFrontmatterOptions, - FormatterArray, - FormatterObject, + FrontmatterArray, + FrontmatterObject, } from '../shared/index.js' import { autoFrontmatterPlugin } from './plugin.js' export * from './plugin.js' -export { AutoFrontmatterOptions, FormatterArray, FormatterObject } +export { AutoFrontmatterOptions, FrontmatterArray, FrontmatterObject } export default autoFrontmatterPlugin diff --git a/packages/plugin-auto-frontmatter/src/node/plugin.ts b/packages/plugin-auto-frontmatter/src/node/plugin.ts index ef036117..ff5d7ef1 100644 --- a/packages/plugin-auto-frontmatter/src/node/plugin.ts +++ b/packages/plugin-auto-frontmatter/src/node/plugin.ts @@ -6,8 +6,8 @@ import grayMatter from 'gray-matter' import jsonToYaml from 'json2yaml' import type { AutoFrontmatterOptions, - FormatterArray, - FormatterObject, + FrontmatterArray, + FrontmatterObject, MarkdownFile, } from '../shared/index.js' import { readMarkdown, readMarkdownList } from './readFiles.js' @@ -16,27 +16,27 @@ import { ensureArray, isEmptyObject } from './utils.js' export const autoFrontmatterPlugin = ({ include = ['**/*.{md,MD}'], exclude = ['.vuepress/**/*', 'node_modules'], - formatter = {}, + frontmatter = {}, }: AutoFrontmatterOptions = {}): Plugin => { include = ensureArray(include) exclude = ensureArray(exclude) const globFilter = createFilter(include, exclude, { resolve: false }) - const matterFormatter: FormatterArray = Array.isArray(formatter) - ? formatter - : [{ include: '*', formatter }] + const matterFrontmatter: FrontmatterArray = Array.isArray(frontmatter) + ? frontmatter + : [{ include: '*', frontmatter }] - const globFormatter: FormatterObject = - matterFormatter.find(({ include }) => include === '*')?.formatter || {} + const globFormatter: FrontmatterObject = + matterFrontmatter.find(({ include }) => include === '*')?.frontmatter || {} - const otherFormatters = matterFormatter + const otherFormatters = matterFrontmatter .filter(({ include }) => include !== '*') - .map(({ include, formatter }) => { + .map(({ include, frontmatter }) => { return { include, filter: createFilter(ensureArray(include), [], { resolve: false }), - formatter, + frontmatter, } }) @@ -44,7 +44,7 @@ export const autoFrontmatterPlugin = ({ const { filepath, relativePath } = file const current = otherFormatters.find(({ filter }) => filter(relativePath)) - const formatter = current?.formatter || globFormatter + const formatter = current?.frontmatter || globFormatter const { data, content } = grayMatter(file.content) for (const key in formatter) { diff --git a/packages/plugin-auto-frontmatter/src/shared/index.ts b/packages/plugin-auto-frontmatter/src/shared/index.ts index 221824d1..7c4597c1 100644 --- a/packages/plugin-auto-frontmatter/src/shared/index.ts +++ b/packages/plugin-auto-frontmatter/src/shared/index.ts @@ -7,19 +7,19 @@ export interface MarkdownFile { stats: fs.Stats } -export type FormatterFn = ( +export type FrontmatterFn = ( value: T, file: MarkdownFile, data: K ) => T | PromiseLike -export type FormatterObject = { - [P: string]: FormatterFn +export type FrontmatterObject = { + [P: string]: FrontmatterFn } -export type FormatterArray = { +export type FrontmatterArray = { include: string | string[] - formatter: FormatterObject + frontmatter: FrontmatterObject }[] export interface AutoFrontmatterOptions { @@ -37,5 +37,5 @@ export interface AutoFrontmatterOptions { * } * } */ - formatter?: FormatterArray | FormatterObject + frontmatter?: FrontmatterArray | FrontmatterObject } diff --git a/packages/theme/src/client/config.ts b/packages/theme/src/client/config.ts index 6c29a50f..6a0589cf 100644 --- a/packages/theme/src/client/config.ts +++ b/packages/theme/src/client/config.ts @@ -1,3 +1,5 @@ +import './styles/index.scss' + import { defineClientConfig } from '@vuepress/client' import { h } from 'vue' import Badge from './components/global/Badge.vue' @@ -5,8 +7,6 @@ import { setupDarkMode, useScrollPromise } from './composables/index.js' import Layout from './layouts/Layout.vue' import NotFound from './layouts/NotFound.vue' -import './styles/index.scss' - export default defineClientConfig({ enhance({ app, router }) { // global component diff --git a/packages/theme/src/client/styles/normalize.scss b/packages/theme/src/client/styles/normalize.scss index 4da9cea0..d7750a26 100644 --- a/packages/theme/src/client/styles/normalize.scss +++ b/packages/theme/src/client/styles/normalize.scss @@ -5,9 +5,15 @@ } html { - line-height: 1.4; font-size: 16px; +} + +body { -webkit-text-size-adjust: 100%; + font-synthesis: none; + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; } html.dark { @@ -21,16 +27,16 @@ body { min-height: 100vh; line-height: 24px; font-family: var(--vp-font-family-base); - font-size: 16px; font-weight: 400; + direction: ltr; +} + +html, +body { color: var(--vp-c-text-1); background-color: var(--vp-c-bg); - direction: ltr; - font-synthesis: none; - text-rendering: optimizeLegibility; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; - transition: all 0.25s; + transition: var(--t-color); + transition-property: color, background-color; } main { diff --git a/packages/theme/src/client/styles/vars.scss b/packages/theme/src/client/styles/vars.scss index 588debe7..951e3cae 100644 --- a/packages/theme/src/client/styles/vars.scss +++ b/packages/theme/src/client/styles/vars.scss @@ -113,7 +113,7 @@ --c-brand: var(--vp-c-brand); } -.dark { +html.dark { --vp-c-bg: #1e1e20; --vp-c-bg-elv: #252529; @@ -242,7 +242,7 @@ --vp-code-tab-active-bar-color: var(--vp-c-brand); } -.dark { +html.dark { --vp-code-block-bg: #161618; } @@ -282,7 +282,7 @@ --vp-button-sponsor-active-bg: transparent; } -.dark { +html.dark { --vp-button-sponsor-border: var(--vp-c-gray-dark-1); --vp-button-sponsor-text: var(--vp-c-text-dark-2); } @@ -415,7 +415,7 @@ } :root { - --t-color: 0.25s; + --t-color: 250ms ease; --code-tabs-nav-bg-color: var(--vp-code-tab-b); --code-bg-color: var(--vp-code-block-bg); --medium-zoom-bg-color: var(--vp-c-bg); diff --git a/packages/theme/src/node/autoFrontmatter.ts b/packages/theme/src/node/autoFrontmatter.ts index 46ac8690..c8a94e01 100644 --- a/packages/theme/src/node/autoFrontmatter.ts +++ b/packages/theme/src/node/autoFrontmatter.ts @@ -4,8 +4,8 @@ import type { App } from '@vuepress/core' import { resolveLocalePath } from '@vuepress/shared' import type { AutoFrontmatterOptions, - FormatterArray, - FormatterObject, + FrontmatterArray, + FrontmatterObject, } from '@vuepress-plume/vuepress-plugin-auto-frontmatter' import type { NotesItem } from '@vuepress-plume/vuepress-plugin-notes-data' import { format } from 'date-fns' @@ -44,7 +44,7 @@ export default function autoFrontmatter( }) .filter(Boolean) - const baseFormatter: FormatterObject = { + const baseFrontmatter: FrontmatterObject = { author(author: string) { if (author) return author return localeOption.avatar?.name || pkg.author || '' @@ -86,21 +86,21 @@ export default function autoFrontmatter( } return { include: ['**/*.md'], - formatter: [ + frontmatter: [ localesNotesDirs.length ? { // note 首页链接 include: localesNotesDirs.map((dir) => normalizePath(path.join(dir, '**/{readme,README,index}.md')) ), - formatter: { + frontmatter: { title(title: string, { filepath }) { if (title) return title const note = findNote(filepath) if (note?.text) return note.text return getCurrentDirname(note, filepath) || '' }, - ...baseFormatter, + ...baseFrontmatter, permalink(permalink: string, { filepath }) { if (permalink) return permalink const locale = resolveLocale(filepath) @@ -121,15 +121,15 @@ export default function autoFrontmatter( localesNotesDirs.length ? { include: localesNotesDirs.map((dir) => - normalizePath(path.join(dir, '**/**.md').replace(/\\+/g, '/')) + normalizePath(path.join(dir, '**/**.md')) ), - formatter: { + frontmatter: { title(title: string, { filepath }) { if (title) return title const basename = path.basename(filepath, '.md') return basename }, - ...baseFormatter, + ...baseFrontmatter, permalink(permalink: string, { filepath }) { if (permalink) return permalink const locale = resolveLocale(filepath) @@ -150,17 +150,17 @@ export default function autoFrontmatter( : '', { include: '**/{readme,README,index}.md', - formatter: {}, + frontmatter: {}, }, { include: '*', - formatter: { + frontmatter: { title(title: string, { filepath }) { if (title) return title const basename = path.basename(filepath, '.md') return basename }, - ...baseFormatter, + ...baseFrontmatter, permalink(permalink: string, { filepath }) { if (permalink) return permalink const locale = resolveLocale(filepath) @@ -170,6 +170,6 @@ export default function autoFrontmatter( }, }, }, - ].filter(Boolean) as FormatterArray, + ].filter(Boolean) as FrontmatterArray, } }