Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Show block attributes in mobile search results https://github.com/siyuan-note/siyuan/issues/19317

Daniel4f2b9c5009c5
diff --git a/app/src/mobile/menu/search.ts b/app/src/mobile/menu/search.ts
index 958bf94ac2..5080e6ada2 100644
--- a/app/src/mobile/menu/search.ts
+++ b/app/src/mobile/menu/search.ts
@@ -1,5 +1,6 @@
import {closePanel} from "../util/closePanel";
import {buildSearchRequest} from "../../search/config";
+import {getAttr} from "../../search/attrs";
import type {APICallbackResponse, APIPOSTRoutes} from "../../types/api";
import {getCurrentEditor, openMobileFileById} from "../editor";
import {Constants} from "../../constants";
@@ -198,6 +199,7 @@ ${getFileTreeIconHTML(getNotebookIcon(item.box), "notebook", "b3-list-item__grap
<svg class="b3-list-item__graphic"><use xlink:href="#${getIconByType(childItem.type)}"></use></svg>
${unicode2Emoji(childItem.ial.icon, "b3-list-item__graphic", true)}
<span class="b3-list-item__text">${childItem.content}</span>
+${getAttr(childItem)}
${childItem.tag ? `<span class="b3-list-item__meta b3-list-item__meta--ellipsis">${childItem.tag.replace(/#/g, "")}</span>` : ""}
</div>`;
});
@@ -216,6 +218,7 @@ ${childItem.tag ? `<span class="b3-list-item__meta b3-list-item__meta--ellipsis"
<svg class="b3-list-item__graphic"><use xlink:href="#${getIconByType(item.type)}"></use></svg>
${unicode2Emoji(item.ial.icon, "b3-list-item__graphic", true)}
<span class="b3-list-item__text">${item.content}</span>
+ ${getAttr(item)}
</div>
<div class="fn__flex">
${item.tag ? `<span class="b3-list-item__meta b3-list-item__meta--ellipsis">${item.tag.replace(/#/g, "")}</span><span class="fn__space"></span>` : ""}
diff --git a/app/src/search/attrs.ts b/app/src/search/attrs.ts
new file mode 100644
index 0000000000..413bb659a8
--- /dev/null
+++ b/app/src/search/attrs.ts
@@ -0,0 +1,13 @@
+export const getAttr = (block: Pick<IBlock, "name" | "alias" | "memo">) => {
+ let attrHTML = "";
+ if (block.name) {
+ attrHTML += `<span class="b3-list-item__meta fn__flex" style="max-width: 30%"><svg class="b3-list-item__hinticon"><use xlink:href="#iconN"></use></svg><span class="b3-list-item__hinttext">${block.name}</span></span>`;
+ }
+ if (block.alias) {
+ attrHTML += `<span class="b3-list-item__meta fn__flex" style="max-width: 30%"><svg class="b3-list-item__hinticon"><use xlink:href="#iconA"></use></svg><span class="b3-list-item__hinttext">${block.alias}</span></span>`;
+ }
+ if (block.memo) {
+ attrHTML += `<span class="b3-list-item__meta fn__flex" style="max-width: 30%"><svg class="b3-list-item__hinticon"><use xlink:href="#iconM"></use></svg><span class="b3-list-item__hinttext">${block.memo}</span></span>`;
+ }
+ return attrHTML;
+};
diff --git a/app/src/search/util.ts b/app/src/search/util.ts
index 5df47efb74..647c767ad8 100644
--- a/app/src/search/util.ts
+++ b/app/src/search/util.ts
@@ -1,4 +1,5 @@
import type {FileTreeGetDocRequestInput} from "../types/api";
+import {getAttr} from "./attrs";
import type {APICallbackResponse, APIPOSTRoutes, BlockQueryRequestInput} from "../types/api";
import {getAllModels} from "../layout/getAll";
/// #if !BROWSER
@@ -1553,19 +1554,7 @@ export const inputEvent = (element: Element, config: Config.IUILayoutTabSearchCo
});
};
-export const getAttr = (block: IBlock) => {
- let attrHTML = "";
- if (block.name) {
- attrHTML += `<span class="b3-list-item__meta fn__flex" style="max-width: 30%"><svg class="b3-list-item__hinticon"><use xlink:href="#iconN"></use></svg><span class="b3-list-item__hinttext">${block.name}</span></span>`;
- }
- if (block.alias) {
- attrHTML += `<span class="b3-list-item__meta fn__flex" style="max-width: 30%"><svg class="b3-list-item__hinticon"><use xlink:href="#iconA"></use></svg><span class="b3-list-item__hinttext">${block.alias}</span></span>`;
- }
- if (block.memo) {
- attrHTML += `<span class="b3-list-item__meta fn__flex" style="max-width: 30%"><svg class="b3-list-item__hinticon"><use xlink:href="#iconM"></use></svg><span class="b3-list-item__hinttext">${block.memo}</span></span>`;
- }
- return attrHTML;
-};
+export {getAttr} from "./attrs";
const onSearch = (data: IBlock[], edit: Protyle, element: Element, config: Config.IUILayoutTabSearchConfig,
focusId?: {