feat: Implement export of ebook references with path to the files

This commit is contained in:
Dendy 2025-09-04 17:07:50 +02:00
parent 7fb8bbe79d
commit 043f936497
1 changed files with 12 additions and 4 deletions

View File

@ -12,12 +12,14 @@ use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\VarExporter\VarExporter;
#[AsCommand('app:extract', 'Create list recursively from path')]
class KanjiExtractCommand extends Command
{
public function __construct()
{
public function __construct(
private string $varBasepath,
) {
parent::__construct();
}
@ -52,15 +54,21 @@ class KanjiExtractCommand extends Command
$kanjiStr = Japanese::getOnlyKanji($line);
foreach (Japanese::mbIterate($kanjiStr) as $char) {
if (!key_exists($char, $kanji)) {
$kanji[$char] ??= 0;
$kanji[$char] ??= [];
echo $char;
if (count($kanji) % 40 === 0) echo "\n";
}
$kanji[$char]++;
if (count($kanji[$char]) < 50) {
$kanji[$char][$fileinfo->getPathname()] ??= 0;
$kanji[$char][$fileinfo->getPathname()]++;
}
}
}
}
file_put_contents("$this->varBasepath/ebook-ref.php", '<?php return ' . VarExporter::export($kanji) . ';');
// ------------------------------------------------- Actual parsing ---
fprintf(