fix(plugin-notes-data): 修复 不同系统的文件分隔符不同导致的正则匹配错误(#3)

This commit is contained in:
pengzhanbo 2023-06-28 18:30:15 +08:00
parent 7ebd7d73f3
commit 29faa9bdf3
4 changed files with 13 additions and 6 deletions

View File

@ -20,6 +20,9 @@
},
"main": "lib/node/index.js",
"types": "./lib/node/index.d.ts",
"files": [
"lib"
],
"scripts": {
"build": "pnpm run clean && pnpm run copy && pnpm run ts",
"clean": "rimraf lib *.tsbuildinfo",

View File

@ -9,7 +9,7 @@ import type {
NotesSidebar,
NotesSidebarItem,
} from '../shared/index.js'
import { ensureArray } from './utils.js'
import { ensureArray, normalizePath } from './utils.js'
const HMR_CODE = `
if (import.meta.webpackHot) {
@ -37,10 +37,11 @@ export const prepareNotesData = async (
{ include, exclude, notes, dir, link }: NotesDataOptions
) => {
if (!notes || notes.length === 0) return
dir = normalizePath(dir)
const filter = createFilter(ensureArray(include), ensureArray(exclude), {
resolve: false,
})
const DIR_PATTERN = new RegExp(`^${path.join(dir, '/')}`)
const DIR_PATTERN = new RegExp(`^${normalizePath(path.join(dir, '/'))}`)
const notesPageList: NotePage[] = app.pages
.filter(
(page) =>

View File

@ -3,3 +3,7 @@ export function ensureArray<T>(thing: T | T[] | null | undefined): T[] {
if (thing === null || thing === undefined) return []
return [thing]
}
export function normalizePath(str: string) {
return str.replace(/\\+/g, '/')
}

View File

@ -36,13 +36,12 @@ export default function autoFrontmatter(
const notes = localeOption.locales?.[locale].notes
if (!notes) return ''
const dir = notes.dir
console.log(locale, dir)
return dir ? path.join(locale, dir).replace(/^\//, '') : ''
return dir
? path.join(locale, dir).replace(/\\+/g, '/').replace(/^\//, '')
: ''
})
.filter(Boolean)
console.log('locales notes dirs', Object.keys(locales), localesNotesDirs)
const baseFormatter: FormatterObject = {
author(author: string) {
if (author) return author