summaryrefslogtreecommitdiff
path: root/packages/frontend/lib
diff options
context:
space:
mode:
authorsyuilo <4439005+syuilo@users.noreply.github.com>2025-04-07 17:03:43 +0900
committersyuilo <4439005+syuilo@users.noreply.github.com>2025-04-07 17:03:43 +0900
commit3a8d015194e13224edc37650665c71e2087698b3 (patch)
tree82a3af620c4fdedb3fee13b68defd9286b77b12d /packages/frontend/lib
parentMerge branch 'develop' of https://github.com/misskey-dev/misskey into develop (diff)
downloadmisskey-3a8d015194e13224edc37650665c71e2087698b3.tar.gz
misskey-3a8d015194e13224edc37650665c71e2087698b3.tar.bz2
misskey-3a8d015194e13224edc37650665c71e2087698b3.zip
enhance(frontend): improve search index
Diffstat (limited to 'packages/frontend/lib')
-rw-r--r--packages/frontend/lib/vite-plugin-create-search-index.ts31
1 files changed, 26 insertions, 5 deletions
diff --git a/packages/frontend/lib/vite-plugin-create-search-index.ts b/packages/frontend/lib/vite-plugin-create-search-index.ts
index a0a98b2d3e..a1093cacb5 100644
--- a/packages/frontend/lib/vite-plugin-create-search-index.ts
+++ b/packages/frontend/lib/vite-plugin-create-search-index.ts
@@ -227,10 +227,11 @@ function extractElementText2Inner(node: TemplateChildNode, processingNodeName: s
// region extractUsageInfoFromTemplateAst
/**
- * SearchLabelとSearchKeywordを探して抽出する関数
+ * SearchLabel/SearchKeyword/SearchIconを探して抽出する関数
*/
-function extractLabelsAndKeywords(nodes: TemplateChildNode[]): { label: string | null, keywords: string[] } {
+function extractSugarTags(nodes: TemplateChildNode[]): { label: string | null, keywords: string[], icon: string | null } {
let label: string | null | undefined = undefined;
+ let icon: string | null | undefined = undefined;
const keywords: string[] = [];
logger.info(`Extracting labels and keywords from ${nodes.length} nodes`);
@@ -253,14 +254,32 @@ function extractLabelsAndKeywords(nodes: TemplateChildNode[]): { label: string |
keywords.push(content);
}
return;
+ case 'SearchIcon':
+ if (icon !== undefined) {
+ logger.warn(`Duplicate SearchIcon found, ignoring the second one at ${node.loc.start.line}`);
+ break; // 2つ目のSearchIconは無視
+ }
+
+ if (node.children.length !== 1) {
+ logger.error(`SearchIcon must have exactly one child at ${node.loc.start.line}`);
+ return;
+ }
+
+ const iconNode = node.children[0];
+ if (iconNode.type !== NodeTypes.ELEMENT) {
+ logger.error(`SearchIcon must have a child element at ${node.loc.start.line}`);
+ return;
+ }
+ icon = getStringProp(findAttribute(iconNode.props, 'class'));
+ return;
}
return;
});
// デバッグ情報
- logger.info(`Extraction completed: label=${label}, keywords=[${keywords.join(', ')}]`);
- return { label: label ?? null, keywords };
+ logger.info(`Extraction completed: label=${label}, keywords=[${keywords.join(', ')}, icon=${icon}]`);
+ return { label: label ?? null, keywords, icon: icon ?? null };
}
function getStringProp(attr: AttributeNode | DirectiveNode | null): string | null {
@@ -354,10 +373,12 @@ function extractUsageInfoFromTemplateAst(
// SearchLabelとSearchKeywordを抽出 (AST全体を探索)
{
- const extracted = extractLabelsAndKeywords(node.children);
+ const extracted = extractSugarTags(node.children);
if (extracted.label && markerInfo.label) logger.warn(`Duplicate label found for ${markerId} at ${id}:${node.loc.start.line}`);
+ if (extracted.icon && markerInfo.icon) logger.warn(`Duplicate icon found for ${markerId} at ${id}:${node.loc.start.line}`);
markerInfo.label = extracted.label ?? markerInfo.label ?? '';
markerInfo.keywords = [...extracted.keywords, ...markerInfo.keywords];
+ markerInfo.icon = extracted.icon ?? markerInfo.icon ?? undefined;
}
if (!markerInfo.label) {