1
0
mirror of https://github.com/KanjiVG/kanjivg.git synced 2026-01-12 01:43:06 +01:00
Files
kanjivg/make-index.pl
2024-02-18 10:31:06 +09:00

34 lines
761 B
Perl
Executable File

#!/usr/bin/env perl
use warnings;
use strict;
use utf8;
use FindBin '$Bin';
use v5.32;
no warnings qw(experimental::signatures);
use feature qw(signatures say);
# Requires install. "cpanm JSON::Create"
use JSON::Create 'write_json';
# The index we write to the file.
my %index;
my @files = <$Bin/kanji/*.svg>;
for my $file (@files) {
my ($kanji, $ex) = file_to_kanji ($file);
if (! defined $kanji) {
next;
}
my $tfile = $file;
$tfile =~ s!.*/!!;
push @{$index{$kanji}}, $tfile;
}
write_json ("$Bin/kvg-index.json", \%index, indent => 1, sort => 1);
exit;
sub file_to_kanji ($file) {
if ($file !~ m!([0-9a-f]{5})(-.*)?\.svg!) {
warn "Could not get kanji from $file";
return (undef, undef);
}
return chr (hex ($1)), $2;
}