From 69f931f2a1325ab7cb05fda962b36a8b62c27631 Mon Sep 17 00:00:00 2001 From: polv Date: Tue, 24 Feb 2026 16:47:39 +0700 Subject: [PATCH] fix rendering for various dicts --- src-core/src/db/yomitan.rs | 2 +- src-core/src/db/yomitan_writer.rs | 2 +- src-react/src/App.tsx | 2 +- src-react/src/components/Glossary.tsx | 37 ++++++++++++++------------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src-core/src/db/yomitan.rs b/src-core/src/db/yomitan.rs index bf42824..3b3ec8d 100644 --- a/src-core/src/db/yomitan.rs +++ b/src-core/src/db/yomitan.rs @@ -64,7 +64,7 @@ impl YomitanDatabase { LEFT JOIN yomitan.rule_sets r ON r.id = t.rules_id LEFT JOIN yomitan.term_tag_sets tt ON tt.id = t.term_tags_id WHERE t.term_norm GLOB ?1 {} t.reading GLOB ?2 - ORDER BY tr.max_score DESC + ORDER BY tr.max_score DESC, d.sort_order DESC LIMIT ?3 OFFSET ?4 "#, and_or diff --git a/src-core/src/db/yomitan_writer.rs b/src-core/src/db/yomitan_writer.rs index e383f64..fe53157 100644 --- a/src-core/src/db/yomitan_writer.rs +++ b/src-core/src/db/yomitan_writer.rs @@ -126,10 +126,10 @@ impl YomitanWriter { self.conn.execute_batch( " + CREATE INDEX IF NOT EXISTS dictionaries_sort_order ON dctionaries (sort_order DESC); CREATE INDEX IF NOT EXISTS dictionaries_lang ON dictionaries (lang); CREATE INDEX IF NOT EXISTS terms_dict_id ON terms (dict_id); - CREATE INDEX IF NOT EXISTS terms_term_LOWER ON terms (LOWER(term)); CREATE INDEX IF NOT EXISTS terms_reading ON terms (reading); CREATE INDEX IF NOT EXISTS terms_term_reading_score ON terms(term, reading, score DESC); diff --git a/src-react/src/App.tsx b/src-react/src/App.tsx index fcc5d8c..5584557 100644 --- a/src-react/src/App.tsx +++ b/src-react/src/App.tsx @@ -167,9 +167,9 @@ function App() {
{JSON.parse(glossary_json).map((g: any) => ( diff --git a/src-react/src/components/Glossary.tsx b/src-react/src/components/Glossary.tsx index 5cc9eb1..19d8be0 100644 --- a/src-react/src/components/Glossary.tsx +++ b/src-react/src/components/Glossary.tsx @@ -63,6 +63,8 @@ function StructuredContent({ node: any; onTermClicked: (t: string) => void; }): any { + if (!node) return null; + if (typeof node === "string") { return node; } @@ -70,25 +72,28 @@ function StructuredContent({ if (Array.isArray(node)) { return ( <> - {...node.map((n) => ( - + {...node.map((n, i) => ( + ))} ); } + const tag = "tag" in node ? node.tag : null; + if (!tag) return null; + // Line break - if ("tag" in node && node.tag === "br") { + if (tag === "br") { return
; } // Image - if ("tag" in node && node.tag === "img") { + if (tag === "img") { return ; } // Link - if ("tag" in node && node.tag === "a") { + if (tag === "a") { const link = node as any; const { href, content } = link; @@ -101,9 +106,9 @@ function StructuredContent({ onClick={(ev) => { if (isWebLink) return true; ev.preventDefault(); - const querySearch = "?query="; - if (href.startsWith(querySearch)) { - onTermClicked(href.substring(querySearch.length)); + const [, t] = href.split("query="); + if (t) { + onTermClicked(t.split("&")[0]); } return false; }} @@ -116,15 +121,11 @@ function StructuredContent({ } // Block/container elements (span, div, ol, ul, li, ruby, table, etc.) - if ("tag" in node) { - const block = node as any; + const block = node as any; - return h( - block.tag, - { style: block.style, title: block.title, open: block.open }, - StructuredContent({ node: block.content, onTermClicked }), - ); - } - - return null; + return h( + tag, + { style: block.style, title: block.title, open: block.open }, + StructuredContent({ node: block.content, onTermClicked }), + ); }