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

[功能请求]优化标签搜索「tags是占位符的模板」不能正常使用的问题。 #66

Closed
YanCore opened this issue Nov 12, 2024 · 4 comments

Comments

@YanCore
Copy link

YanCore commented Nov 12, 2024

这个问题应该比较容易解决,希望早点修复。最简单的方式,只处理数组、字符串类型的tags。

复现方式

  1. 新建一个模板 tags字段是{{}}的模板。
    image

  2. 使用标签搜索任意标签。
    image

日志

image

@YanCore
Copy link
Author

YanCore commented Nov 12, 2024

我在原有的基础上修改一行代码,可以成功搜索。

tagArray = Array.isArray(tags) ? tags : (typeof tags === 'string' ? tags.split(",").filter((p) => p).map((p) => p.trim()) : []);
function getFileTagArray(file) {
  var _a, _b, _c, _d;
  let tags = ((_b = (_a = app.metadataCache.getFileCache(file)) == null ? void 0 : _a.frontmatter) == null ? void 0 : _b.tags) || ((_d = (_c = app.metadataCache.getFileCache(file)) == null ? void 0 : _c.frontmatter) == null ? void 0 : _d.tag), tagArray;
  if (tags)
    tagArray = Array.isArray(tags) ? tags : (typeof tags === 'string' ? tags.split(",").filter((p) => p).map((p) => p.trim()) : []);
  return tagArray;
}

@YanCore
Copy link
Author

YanCore commented Nov 12, 2024

顺带一提,有点不清楚getFileTagArray函数里面下面这行代码tags、tagArray的关系。

  let tags = ((_b = (_a = app.metadataCache.getFileCache(file)) == null ? void 0 : _a.frontmatter) == null ? void 0 : _b.tags) || ((_d = (_c = app.metadataCache.getFileCache(file)) == null ? void 0 : _c.frontmatter) == null ? void 0 : _d.tag), tagArray;

是BUG吗?

let tags = "得到一个tags数组",tagArray;

提到这个,是因为我得到的搜索结果是「关键词和标签的并集」,而不是我想要的「关键词和标签的交集」,我刚开始使用这插件,不确定是不是正确的逻辑。

image

@lazyloong
Copy link
Owner

tags是得到的原始数据,可能是字符串,也可能是数组

// 得到数组
tags:
  - a
  - b

// 得到字符串
tags: a, b

要统一处理成数组的形式方便后续使用,就是tagArray

但是你今天给我开了眼了,tags: {{abc}} 竟然是个对象😂
image
也就是 ob 认为正确的形式是这样的是这样的 tags: { "{abc}":"a" },后面没有值所以是 null

貌似 ob 没有加入对象里的东西,我干脆判断是对象就跳过了

@lazyloong
Copy link
Owner

哦,关于交并集的部分确实写错了,都在 2.27.7 版里改了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants