fix(build): `createContentLoader` generates invalid url when `srcDir` is set (#2578)

BREAKING CHANGE: `createContentLoader` will now resolve globs relative to `srcDir` instead of `root`
pull/2685/head
烽宁 1 year ago committed by GitHub
parent fb048a6f72
commit 74d9ba27b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -91,7 +91,7 @@ import { createContentLoader } from 'vitepress'
export default createContentLoader('posts/*.md', /* options */) export default createContentLoader('posts/*.md', /* options */)
``` ```
The helper takes a glob pattern relative to [project root](./routing#project-root), and returns a `{ watch, load }` data loader object that can be used as the default export in a data loader file. It also implements caching based on file modified timestamps to improve dev performance. The helper takes a glob pattern relative to the [source directory](./routing#source-directory), and returns a `{ watch, load }` data loader object that can be used as the default export in a data loader file. It also implements caching based on file modified timestamps to improve dev performance.
Note the loader only works with Markdown files - matched non-Markdown files will be skipped. Note the loader only works with Markdown files - matched non-Markdown files will be skipped.

@ -115,7 +115,7 @@ export function createContentLoader<T = ContentData[]>(
}) })
const url = const url =
'/' + '/' +
normalizePath(path.relative(config.root, file)).replace( normalizePath(path.relative(config.srcDir, file)).replace(
/\.md$/, /\.md$/,
config.cleanUrls ? '' : '.html' config.cleanUrls ? '' : '.html'
) )

Loading…
Cancel
Save