diff --git a/theme/src/node/pages/autoCategory.ts b/theme/src/node/pages/autoCategory.ts index 476a3e2d..31f8cc7d 100644 --- a/theme/src/node/pages/autoCategory.ts +++ b/theme/src/node/pages/autoCategory.ts @@ -1,6 +1,7 @@ import type { Page } from 'vuepress/core' import type { PostsCategoryItem, ThemePageData } from '../../shared/index.js' -import { ensureEndingSlash, ensureLeadingSlash, removeLeadingSlash } from '@vuepress/helper' +import { ensureEndingSlash, ensureLeadingSlash } from '@vuepress/helper' +import { path } from 'vuepress/utils' import { findCollection } from '../collections/index.js' import { hash } from '../utils/index.js' @@ -21,11 +22,11 @@ export function autoCategory(page: Page): void { if (page.data.type || !pagePath || collection.categories === false) return + const collectionDir = ensureEndingSlash(path.join(page.pathLocale, collection.dir)) const list = ensureLeadingSlash(pagePath) - .slice(page.pathLocale.length + ensureEndingSlash(removeLeadingSlash(collection.dir)).length) + .slice(collectionDir.length) .split('/') .slice(0, -1) - const categoryList: PostsCategoryItem[] = list .map((category, index) => { const match = category.match(RE_CATEGORY) || [] diff --git a/theme/src/node/prepare/preparePostsData.ts b/theme/src/node/prepare/preparePostsData.ts index 670b2af0..4a5f9f5e 100644 --- a/theme/src/node/prepare/preparePostsData.ts +++ b/theme/src/node/prepare/preparePostsData.ts @@ -6,9 +6,9 @@ import type { ThemePosts, ThemePostsItem, } from '../../shared/index.js' -import fs from 'node:fs' import { removeLeadingSlash } from '@vuepress/helper' import dayjs from 'dayjs' +import { fs, path } from 'vuepress/utils' import { getThemeConfig } from '../loadConfig/index.js' import { createMatcher, logger, perf, resolveContent, withBase, writeTemp } from '../utils/index.js' import { isEncryptPage } from './prepareEncrypt.js' @@ -97,10 +97,11 @@ export async function preparedPostsData(app: App): Promise { continue for (const { include, exclude, dir } of collections.filter(item => item.type === 'post')) { const source = app.dir.source(removeLeadingSlash(withBase(dir, locale))) - const isMatched = createMatcher(include, exclude, source) - + const isMatched = createMatcher(include, exclude) postsData[withBase(dir, locale)] = pages - .filter(({ filePath }) => filePath?.startsWith(source) && isMatched(filePath)) + .filter(({ filePath }) => { + return filePath?.startsWith(source) && isMatched(path.relative(source, filePath!)) + }) .sort(sortPage) .map(page => processPostData(page, isBuild, encrypt)) }