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');
while (($kanji = fgets($file)) !== false) {
$kanji = mb_trim($kanji);
$ret[$kanji] = '';
if (mb_strlen($kanji) !== 1) throw new \Exception(sprintf(
'Kanji expected, got "%s"',
@ -45,7 +46,7 @@ class KanjiController extends AbstractController
));
while (($explanation = fgets($file)) !== false) {
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";
return $this->render(self::tmpl('view'), [
'char' => $charStr,
'codepoint' => $codepoint,
'info' => $charInfo,
'terms' => $terms,
'ref' => $ebookRef[$charStr] ?? [],
'jiten_href' => key_exists($charStr, $jiten)
'ignored_text' => $this->getIgnoredList()[$charStr] ?? null,
'char' => $charStr,
'codepoint' => $codepoint,
'info' => $charInfo,
'terms' => $terms,
'ref' => $ebookRef[$charStr] ?? [],
'jiten_href' => key_exists($charStr, $jiten)
? "https://kanji.jitenon.jp/kanji{$jiten[$charStr]}"
: 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="card">
@ -92,21 +92,24 @@
</div>
<div class="d-flex flex-column">
<hr>
{% if ignored_text is not null %}
<hr>
<h2>Terms</h2>
{% for term in terms|slice(0,5) %}
<div>
<div class="text">{{ term.toAnkiVocabDef|ruby|raw }}</div>
</div>
{% endfor %}
<h2>Ignored</h2 >
<div>{{ ignored_text }}</div>
{% endif %}
<hr>
<hr>
<h2>Appeareances</h2>
{% for refname, refcount in ref %}
<div>{{ refname|basename }}: {{ refcount }}</div>
{% endfor %}
</div>
<h2>Terms</h2>
{% for term in terms|slice(0,5) %}
<div>{{ term.toAnkiVocabDef|ruby|raw }}</div>
{% endfor %}
<hr>
<h2>Appeareances</h2>
{% for refname, refcount in ref %}
<div>{{ refname|basename }}: {{ refcount }}</div>
{% endfor %}
</div>