From 78cea01c889555ea694c33e95c75e6859d8d4cfe Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Thu, 29 Jun 2023 18:11:15 +0800 Subject: [PATCH] fix: normalize path posix --- .../src/node/prepareNotesData.ts | 12 +++++----- packages/theme/src/node/autoFrontmatter.ts | 22 +++++++++++++------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/packages/plugin-notes-data/src/node/prepareNotesData.ts b/packages/plugin-notes-data/src/node/prepareNotesData.ts index 204c1aba..8be7d609 100644 --- a/packages/plugin-notes-data/src/node/prepareNotesData.ts +++ b/packages/plugin-notes-data/src/node/prepareNotesData.ts @@ -59,7 +59,7 @@ export const prepareNotesData = async ( const notesData: NotesData = {} notes.forEach((note) => { - notesData[path.join('/', link, note.link)] = initSidebar( + notesData[normalizePath(path.join('/', link, note.link))] = initSidebar( note, notesPageList.filter((page) => page.relativePath.startsWith(note.dir.trim().replace(/^\/|\/$/g, '')) @@ -160,7 +160,7 @@ function initSidebarByConfig( link: item.link || '', text: item.text || '', sidebar: item.items, - dir: path.join(dir, item.dir || ''), + dir: normalizePath(path.join(dir, item.dir || '')), }, pages ), @@ -178,16 +178,16 @@ function findNotePage( return notePageList.find((page) => { const relative = page.relativePath return ( - relative === path.join(dir, 'README.md') || - relative === path.join(dir, 'index.md') + relative === normalizePath(path.join(dir, 'README.md')) || + relative === normalizePath(path.join(dir, 'index.md')) ) }) } else { return notePageList.find((page) => { const relative = page.relativePath return ( - relative === path.join(dir, sidebar) || - relative === path.join(dir, sidebar + '.md') || + relative === normalizePath(path.join(dir, sidebar)) || + relative === normalizePath(path.join(dir, sidebar + '.md')) || page.link === sidebar ) }) diff --git a/packages/theme/src/node/autoFrontmatter.ts b/packages/theme/src/node/autoFrontmatter.ts index 95208041..d12a1bda 100644 --- a/packages/theme/src/node/autoFrontmatter.ts +++ b/packages/theme/src/node/autoFrontmatter.ts @@ -22,6 +22,10 @@ const getPackage = () => { return pkg } +const normalizePath = (dir: string) => { + return dir.replace(/\\+/g, '/') +} + export default function autoFrontmatter( app: App, localeOption: PlumeThemeLocaleOptions @@ -127,12 +131,14 @@ export default function autoFrontmatter( const locale = resolveLocale(filepath) const note = findNote(filepath) const notes = notesByLocale(locale) - return path.join( - locale, - notes?.link || '', - note?.link || getCurrentDirname(note, filepath), - nanoid(), - '/' + return normalizePath( + path.join( + locale, + notes?.link || '', + note?.link || getCurrentDirname(note, filepath), + nanoid(), + '/' + ) ) }, }, @@ -154,7 +160,9 @@ export default function autoFrontmatter( permalink(permalink: string, { filepath }) { if (permalink) return permalink const locale = resolveLocale(filepath) - return path.join(locale, articlePrefix, nanoid(), '/') + return normalizePath( + path.join(locale, articlePrefix, nanoid(), '/') + ) }, }, },