ATQQ/sugar-blog

vitepress-plugin-pagefind: v0.4.4 broke dynamic route pages

slusarz opened this issue · 3 comments

Pages created via dynamic routes (https://vitepress.dev/guide/routing#dynamic-routes) are broken with v0.4.4.

Problem is that new frontmatter code that looks for index exclusion config tries to load non-existent source files.

Example:

build error:
[vitepress-plugin-pagefind] ENOENT: no such file or directory, open '/home/foo/docs/release_notes/3.x/3.0.0.md'

This file is auto generated by vitepress from the /home/foo/docs/release_notes/3.x/[version].md and /home/foo/docs/release_notes/3.x/[version].paths.js files.

Possible solution (verified working): wrap load code in try/catch, and ignore file if it doesn't exist in source.

From https://github.com/ATQQ/sugar-blog/blob/master/packages/vitepress-plugin-pagefind/src/index.ts#L92:

if (id.endsWith('.md')) {
  let fileContent
  try {
    fileContent = await fs.promises.readFile(id, 'utf-8')
  } catch (err) {
    if (err.code === 'ENOENT') {
      return code
    }
    throw(err)
  }
  const { data: frontmatter, content } = grayMatter(fileContent, {
    excerpt: true
  })
ATQQ commented

Understood the issue. I plan to refactor this part later as there are indeed quite a few problems at the moment.

ATQQ commented

you can try vitepress-plugin-pagefind@0.4.7

ATQQ commented

now latest is vitepress-plugin-pagefind@0.4.9

I'm sure it's compatible with the use of dynamic routing