-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate.pl
executable file
·149 lines (125 loc) · 3.04 KB
/
generate.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/perl
use strict;
use warnings;
no warnings 'redefine';
use utf8;
use open ':std', ':encoding(UTF-8)';
use Template;
use File::Slurper 'read_lines';
use File::Basename qw(dirname fileparse);
use File::Copy;
use Digest::MD5::File qw(dir_md5_base64);
use Digest::CRC qw(crc32);
use Cwd;
use Getopt::Long;
use TeX::Hyphen;
sub TeX::Hyphen::visualize {
my ($self, $word, $separator) = (shift, shift, shift);
my $number = 0;
my $pos;
for $pos ($self->hyphenate($word)) {
substr($word, $pos + $number, 0) = $separator;
$number = $number + length($separator);;
}
return $word;
}
my @dir = split(/\//, getcwd);
my $dir = pop(@dir);
my $IN = 'src';
my $appname = 'Anglická slovíčka';
my $appshortname = 'Slovíčka';
my $appdesc = 'Základní anglická slovíčka';
my $domain = undef;
my $OUT = undef;
GetOptions (
"domain=s" => \$domain,
"out=s" => \$OUT,
)
or die("Error in command line arguments\n");
my @content = read_lines('3000.txt');
my $hypcz = new TeX::Hyphen 'file' => 'czhyph.tex',
'style' => 'czech', leftmin => 2,
rightmin => 2;
my $hypen = new TeX::Hyphen 'file' => 'ukhyphen.tex',
'style' => 'czech', leftmin => 2,
rightmin => 2;
my %abeceda;
my %pridat;
my %slovicka;
my $md5 = dir_md5_base64($IN);
my $cachebuster = crc32(join('', sort values %{$md5}));
my $cacheversion = scalar time;
my $wbr = '­';
foreach my $line (@content){
my ($en, $cz) = split /:/, $line;
my $fl = lc($en);
$fl =~ s/^(.).*/$1/;
if($abeceda{$fl}){
$abeceda{$fl}++;
}else{
$abeceda{$fl} = 1;
}
$slovicka{$fl}{$hypen->visualize($en, $wbr)} = $hypcz->visualize($cz, $wbr);
my $zbytek = $abeceda{$fl} % 6;
}
for my $pismeno (sort keys %abeceda) {
my $zbytek = $abeceda{$pismeno} % 6;
$pridat{$pismeno} = 6 - $zbytek;
}
my $t = Template->new({
INCLUDE_PATH => $IN,
ENCODING => 'utf8',
VARIABLES => {
version => 1,
cachebuster => $cachebuster,
cacheversion => $cacheversion,
appname => $appname,
appshortname => $appshortname,
appdesc => $appdesc,
dir => $dir,
domain => $domain,
},
});
for my $pismeno (sort keys %slovicka) {
$t->process('pismeno.html',
{
'title' => $appname . ' - '. uc $pismeno,
'slovicka' => $slovicka{$pismeno},
'pismeno' => $pismeno,
'pridat' => \%pridat,
},
"$OUT/$pismeno.html",
{ binmode => ':utf8' }) or die $t->error;
}
$t->process('index.html',
{
'title' => $appname,
'abeceda' => \%abeceda,
},
"$OUT/index.html",
{ binmode => ':utf8' }) or die $t->error;
$t->process('404.html',
{
'title' => 'Stránka nenalezena',
},
"$OUT/404.html",
{ binmode => ':utf8' }) or die $t->error;
my @files = (
'slovicka.css',
'browserconfig.xml',
'manifest.json',
'slovicka.js',
'sw.js',
'app.js',
);
for my $file (@files){
$t->process($file ,{
'abeceda' => \%abeceda,
},
"$OUT/$cachebuster-$file",
{ binmode => ':utf8' }) or die $t->error;
}
foreach my $file (glob("$IN/img/*")){
my ($name,$path) = fileparse($file);
copy("$path$name", "$OUT/$cachebuster-$name");
}