mirror of
https://github.com/KanjiVG/kanjivg.git
synced 2026-04-20 04:20:44 +02:00
Add an index and a file which generates it
This commit is contained in:
25248
kvg-index.json
Normal file
25248
kvg-index.json
Normal file
File diff suppressed because it is too large
Load Diff
31
make-index.pl
Executable file
31
make-index.pl
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/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';
|
||||
my %index;
|
||||
my @files = <$Bin/kanji/*.svg>;
|
||||
for my $file (@files) {
|
||||
my ($kanji, $ex) = file_to_kanji ($file);
|
||||
if (! $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;
|
||||
}
|
||||
Reference in New Issue
Block a user