Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(recentUpdates): path parsing error #380

Merged
merged 3 commits into from
Jan 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions packages/vitepress-plugin-index/src/vitepress/recentUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export function createRecentUpdatesLoader(options?: RecentUpdatesContentLoaderOp

return {
async load() {
const files = await glob(join(opts.dir, '**/*.md'), {
const files = await glob(join(opts.dir, '**/*.md').replaceAll('\\', '/'), {
absolute: true,
cwd: cwd(),
ignore: opts.ignores,
Expand Down Expand Up @@ -215,24 +215,27 @@ export function createRecentUpdatesLoader(options?: RecentUpdatesContentLoaderOp
}
}

let url = relative(cwd(), file)
if (url.endsWith('.md')) {
if (url.endsWith('index.md')) {
url = url.replace(/index\.md$/, 'index.html')
let url = ''
const fileRelativePath = relative(cwd(), file)

if (fileRelativePath.endsWith('.md')) {
if (fileRelativePath.endsWith('index.md')) {
url = fileRelativePath.replace(/index\.md$/, 'index.html')
}
else {
url = url.replace(/\.md$/, '.html')
url = fileRelativePath.replace(/\.md$/, '.html')
}
}

for (const rewrite of opts.rewrites) {
url = url.replace(rewrite.from, rewrite.to)
}
url = `/${url}`

const entry = {
title,
lastUpdated: lastUpdatedTimestamp,
filePath: relative(cwd(), file),
filePath: fileRelativePath,
category: '',
url,
}
Expand Down
Loading