fix rendering for various dicts

This commit is contained in:
polv committed 2026-02-24 16:47:39 +07:00
1 parent 8bd087b869
commit 69f931f2a1
4 files changed
+22 -21

No files matched your search

+1 -1
View File
@@ -64,7 +64,7 @@ impl YomitanDatabase {
LEFT JOIN yomitan.rule_sets r ON r.id = t.rules_id 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 LEFT JOIN yomitan.term_tag_sets tt ON tt.id = t.term_tags_id
WHERE t.term_norm GLOB ?1 {} t.reading GLOB ?2 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 LIMIT ?3 OFFSET ?4
"#, "#,
and_or and_or
+1 -1
View File
@@ -126,10 +126,10 @@ impl YomitanWriter {
self.conn.execute_batch( 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 dictionaries_lang ON dictionaries (lang);
CREATE INDEX IF NOT EXISTS terms_dict_id ON terms (dict_id); 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_reading ON terms (reading);
CREATE INDEX IF NOT EXISTS terms_term_reading_score ON terms(term, reading, score DESC); CREATE INDEX IF NOT EXISTS terms_term_reading_score ON terms(term, reading, score DESC);
+1 -1
View File
@@ -167,9 +167,9 @@ function App() {
<Card.Body> <Card.Body>
<div <div
style={{ style={{
gap: "1em",
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
whiteSpace: "pre-wrap",
}} }}
> >
{JSON.parse(glossary_json).map((g: any) => ( {JSON.parse(glossary_json).map((g: any) => (
+19 -18
View File
@@ -63,6 +63,8 @@ function StructuredContent({
node: any; node: any;
onTermClicked: (t: string) => void; onTermClicked: (t: string) => void;
}): any { }): any {
if (!node) return null;
if (typeof node === "string") { if (typeof node === "string") {
return node; return node;
} }
@@ -70,25 +72,28 @@ function StructuredContent({
if (Array.isArray(node)) { if (Array.isArray(node)) {
return ( return (
<> <>
{...node.map((n) => ( {...node.map((n, i) => (
<StructuredContent node={n} onTermClicked={onTermClicked} /> <StructuredContent key={i} node={n} onTermClicked={onTermClicked} />
))} ))}
</> </>
); );
} }
const tag = "tag" in node ? node.tag : null;
if (!tag) return null;
// Line break // Line break
if ("tag" in node && node.tag === "br") { if (tag === "br") {
return <br />; return <br />;
} }
// Image // Image
if ("tag" in node && node.tag === "img") { if (tag === "img") {
return <GlossaryImage {...node} />; return <GlossaryImage {...node} />;
} }
// Link // Link
if ("tag" in node && node.tag === "a") { if (tag === "a") {
const link = node as any; const link = node as any;
const { href, content } = link; const { href, content } = link;
@@ -101,9 +106,9 @@ function StructuredContent({
onClick={(ev) => { onClick={(ev) => {
if (isWebLink) return true; if (isWebLink) return true;
ev.preventDefault(); ev.preventDefault();
const querySearch = "?query="; const [, t] = href.split("query=");
if (href.startsWith(querySearch)) { if (t) {
onTermClicked(href.substring(querySearch.length)); onTermClicked(t.split("&")[0]);
} }
return false; return false;
}} }}
@@ -116,15 +121,11 @@ function StructuredContent({
} }
// Block/container elements (span, div, ol, ul, li, ruby, table, etc.) // 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( return h(
block.tag, tag,
{ style: block.style, title: block.title, open: block.open }, { style: block.style, title: block.title, open: block.open },
StructuredContent({ node: block.content, onTermClicked }), StructuredContent({ node: block.content, onTermClicked }),
); );
}
return null;
} }