feat: Fix parsing of ignored explanation, add to kanji view

This commit is contained in:
Dendy 2025-09-08 08:36:13 +02:00
parent 76f5f30a47
commit f5a65fbe05
2 changed files with 27 additions and 22 deletions

View File

@ -38,6 +38,7 @@ class KanjiController extends AbstractController
$file = fopen($path, 'r'); $file = fopen($path, 'r');
while (($kanji = fgets($file)) !== false) { while (($kanji = fgets($file)) !== false) {
$kanji = mb_trim($kanji); $kanji = mb_trim($kanji);
$ret[$kanji] = '';
if (mb_strlen($kanji) !== 1) throw new \Exception(sprintf( if (mb_strlen($kanji) !== 1) throw new \Exception(sprintf(
'Kanji expected, got "%s"', 'Kanji expected, got "%s"',
@ -45,7 +46,7 @@ class KanjiController extends AbstractController
)); ));
while (($explanation = fgets($file)) !== false) { while (($explanation = fgets($file)) !== false) {
if ($explanation === "\n") continue 2; if ($explanation === "\n") continue 2;
$ret[$kanji] = mb_trim(fgets($file)); $ret[$kanji] .= mb_trim($explanation);
} }
} }
@ -156,12 +157,13 @@ class KanjiController extends AbstractController
$ebookRef = require "$this->varBasepath/ebook-ref.php"; $ebookRef = require "$this->varBasepath/ebook-ref.php";
return $this->render(self::tmpl('view'), [ return $this->render(self::tmpl('view'), [
'char' => $charStr, 'ignored_text' => $this->getIgnoredList()[$charStr] ?? null,
'codepoint' => $codepoint, 'char' => $charStr,
'info' => $charInfo, 'codepoint' => $codepoint,
'terms' => $terms, 'info' => $charInfo,
'ref' => $ebookRef[$charStr] ?? [], 'terms' => $terms,
'jiten_href' => key_exists($charStr, $jiten) 'ref' => $ebookRef[$charStr] ?? [],
'jiten_href' => key_exists($charStr, $jiten)
? "https://kanji.jitenon.jp/kanji{$jiten[$charStr]}" ? "https://kanji.jitenon.jp/kanji{$jiten[$charStr]}"
: null : null
]); ]);

View File

@ -1,4 +1,4 @@
<div class="d-flex flex-column gap-2 p-3 align-items-start"> <div class="d-flex flex-column p-3 align-items-stretch">
<div class="d-flex gap-2 w-100"> <div class="d-flex gap-2 w-100">
<div class="card"> <div class="card">
@ -92,21 +92,24 @@
</div> </div>
<div class="d-flex flex-column"> {% if ignored_text is not null %}
<hr> <hr>
<h2>Terms</h2> <h2>Ignored</h2 >
{% for term in terms|slice(0,5) %} <div>{{ ignored_text }}</div>
<div> {% endif %}
<div class="text">{{ term.toAnkiVocabDef|ruby|raw }}</div>
</div>
{% endfor %}
<hr> <hr>
<h2>Appeareances</h2> <h2>Terms</h2>
{% for refname, refcount in ref %} {% for term in terms|slice(0,5) %}
<div>{{ refname|basename }}: {{ refcount }}</div> <div>{{ term.toAnkiVocabDef|ruby|raw }}</div>
{% endfor %} {% endfor %}
</div>
<hr>
<h2>Appeareances</h2>
{% for refname, refcount in ref %}
<div>{{ refname|basename }}: {{ refcount }}</div>
{% endfor %}
</div> </div>