fix(plugin-notes-data): 修复 不同系统的文件分隔符不同导致的正则匹配错误(#3)
This commit is contained in:
parent
7ebd7d73f3
commit
29faa9bdf3
@ -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",
|
||||
|
||||
@ -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) =>
|
||||
|
||||
@ -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, '/')
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user