feat: Link kanjis to jitenon

This commit is contained in:
Dendy 2025-09-02 08:00:14 +02:00
parent b2f7990876
commit fe68c07e2c
2 changed files with 30 additions and 9 deletions

View File

@ -34,6 +34,10 @@ class KanjiController extends AbstractController
$taiwan = $this->charList->getList('taiwan'); $taiwan = $this->charList->getList('taiwan');
$jiten = json_decode(file_get_contents(
"{$this->getParameter('kernel.project_dir')}/data/kanken-links.json",
), true);
$chars = []; $chars = [];
foreach (range(intval("{$start}0", 16), intval("{$end}f", 16)) as $codepoint) { foreach (range(intval("{$start}0", 16), intval("{$end}f", 16)) as $codepoint) {
$charStr = mb_chr($codepoint, 'UTF-8'); $charStr = mb_chr($codepoint, 'UTF-8');
@ -47,6 +51,9 @@ class KanjiController extends AbstractController
'unicode' => in_array($charStr, $unicodeKanji, true), 'unicode' => in_array($charStr, $unicodeKanji, true),
'taiwan' => key_exists($charStr, $taiwan['chars']), 'taiwan' => key_exists($charStr, $taiwan['chars']),
], ],
'jiten_href' => key_exists($charStr, $jiten)
? "https://kanji.jitenon.jp/kanji{$jiten[$charStr]}"
: null
]; ];
} }

View File

@ -8,12 +8,6 @@
<div class="d-flex flex-wrap m-2"> <div class="d-flex flex-wrap m-2">
{% for char in characters %} {% for char in characters %}
<div style="width: calc(100% / 16);"> <div style="width: calc(100% / 16);">
<a
target="_blank"
href="{{ path('app_kanji_register', {
codepoint: char.codepoint
}) }}"
>
<div <div
class="border text-center rounded" class="border text-center rounded"
style=" style="
@ -31,16 +25,36 @@
{{ char.lists.sln ? 'bg-danger text-white' : '' }} {{ char.lists.sln ? 'bg-danger text-white' : '' }}
{{ char.lists.sn ? 'bg-warning text-black' : '' }} {{ char.lists.sn ? 'bg-warning text-black' : '' }}
"> ">
{{- char.str -}} {% if char.jiten_href != null %}
<a
target="_blank"
href="{{- char.jiten_href -}}"
class="border-bottom"
>
{{- char.str -}}
</a>
{% else %}
{{- char.str -}}
{% endif %}
</div> </div>
<div style=" <div style="
font-size: 0.5em; font-size: 0.5em;
padding-bottom: 2px; padding-bottom: 2px;
"> ">
{{ char.codepoint }} {% if not char.lists.unicode %}
<a
target="_blank"
href="{{ path('app_kanji_register', {
codepoint: char.codepoint
}) }}"
>
{{ char.codepoint }}
</a>
{% else %}
{{ char.codepoint }}
{% endif %}
</div> </div>
</div> </div>
</a>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>