ATQQ / sugar-blog

✍️📚我写博客的地方🤪🤪🤪记录随笔与学习笔记,仓库包含:博客内容,博客主题、博客模板、vitepress离线全文搜索插件、VitePress RSS 支持插件;a blog theme use vitepress
https://sugarat.top
MIT License
330 stars 61 forks source link

vitepress-plugin-pagefind: v0.4.4 breaks rendering #256

Closed slusarz closed 2 months ago

slusarz commented 2 months ago

https://github.com/ATQQ/sugar-blog/commit/b47b21350ee0106df7241f255545f4ef92af98f8 introduced this code:

if (!code.includes(options?.ssr ? '_push(`' : '_createElementBlock("div", null')) {

// ...

return code.replace('_createElementBlock("div", null', `_createElementBlock("div", ${stringify(attrs)}`)

This code assumes the Vue rendering code is of the format _createElementBlock("div", null, [ ... ]).

However, on out system, the rendering code is simply outputting a single, empty DIV tag. This uses the simplified function signature _createElementBlock("div"). Example:

function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return (_openBlock(), _createElementBlock("div"))
}

This results in every page issuing this warning:

[plugin:vitepress-plugin-pagefind] [plugin vitepress-plugin-pagefind] docs/core/admin/index.md: Client /foo/docs/core/admin/index.md may not be a valid file, will not be indexed, please contact the author for assistance

And the second replace call fails.

Solution: Replace code needs to check for both function signatures.

ATQQ commented 2 months ago

Sure, thank you for the feedback. I will work on it in the next two days. In the meantime, you can revert back to the previous version and use 0.4.3.

ATQQ commented 2 months ago

Can you provide a demo? I'll try to reproduce it. Is this related to the VitePress version?

slusarz commented 2 months ago

Our installation should be up-to-date, using VitePress 1.2.3: https://github.com/dovecot/documentation/blob/ced4a60d804d414dc2c1dec56e0745aab16fbbac/package.json

I don't think we're doing anything too crazy with the config either: https://github.com/dovecot/documentation/blob/ced4a60d804d414dc2c1dec56e0745aab16fbbac/.vitepress/config.js

Running npm run docs:build command. Dump of the code variable in the transform() function gives:

export const __pageData = JSON.parse("{\"title\":\"Administration\",\"description\":\"\",\"frontmatter\":{\"title\":\"Administration\",\"exclude\":true,\"order\":110},\"headers\":[],\"relativePath\":\"core/admin/index.md\",\"filePath\":\"core/admin/index.md\",\"lastUpdated\":1719485127000}")
const _sfc_main = {name:"core/admin/index.md"}
import { openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"

function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return (_openBlock(), _createElementBlock("div"))
}

import _export_sfc from 'plugin-vue:export-helper'
export default /*#__PURE__*/_export_sfc(_sfc_main, [['render',_sfc_render]])
ATQQ commented 2 months ago

Probably located the cause of the problem. This problem occurs when there is only frontMatter and no content in the document.

image

I'll make it compatible with this scene.

slusarz commented 2 months ago

Ah, yes, that's probably a bit unique to our setup as we use an auto sidebar generator, where these empty MD files are used to insert/configure sidebar stuff without creating an actual page.

Thanks for tracking this down.

ATQQ commented 2 months ago

Does that mean that it's possible not to index those pages without content?

slusarz commented 2 months ago

There's nothing to index, so I would have no problem with the pagefind plugin code just skipping that page.

ATQQ commented 2 months ago

you can try vitepress-plugin-pagefind@0.4.5