forked from TLINDEN/Quietly-Confident
/
qc
executable file
·3279 lines (3133 loc) · 164 KB
/
qc
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
# "Quietly Confident
# plain simple git-aware static site generator
# by TLINDEN <tlinden@cpan.org>
# http://www.daemon.de/QuietlyConfident
our $VERSION = '0.10';
package Quietly::Confident::Role;
use Moo::Role;
sub path2public {
# convert a given physical source path
# to output path without numbering, special chars etc
my ($self, $isfile) = @_;
my @out;
my $path = $self->ioall->name;
$path =~ s/^\.\///; # remove ./
foreach my $part (split /\//, $path) {
$part =~ s/^\d*[\.\-_ ]*//; # remove leading number
# replace some known german umlauts by its 7bit
# counterparts
$part =~ s/ä/ae/gi;
$part =~ s/ö/oe/gi;
$part =~ s/ü/ue/gi;
$part =~ s/Ã/ae/gi;
$part =~ s/([^\w\.])/_/g; # non word to dash
$part =~s/([A-Z])/lc($1)/ge; # lowercase for urls
push @out, $part;
}
my $normalized = join '/', @out;
if($isfile) {
$normalized =~ s/index\.[a-zA-Z]*$//;
$normalized =~ s/\.[a-zA-Z]*$/\//;
}
return $normalized;
}
sub caption {
my $self = shift;
my $cap = $self->ioall->name;
$cap =~ s/.*\///; # remove leading path parts
$cap =~ s/\.[^\.]*$//; # remove suffix
$cap =~ s/^\d*[\.\-_ ]*//; # remove leading number
$cap =~ s/[\.\-_ ]*/ /; # punctuation to space
$cap =~ s/^\s*//;
chomp $cap;
return Encode::decode_utf8($cap);
}
has ioall => ( is => 'rw' );
has config => ( is => 'rw' );
1;
##########################
package Quietly::Confident::Dir;
use Moo;
use Sub::Quote;
use Data::Dumper;
use IO::All -utf8;
use Encode;
with('Quietly::Confident::Role');
has hasindex => ( is => 'rw' );
has hasfiles => ( is => 'rw' );
has level => ( is => 'rw' );
has hasdirs => ( is => 'rw' );
has files => ( is => 'rw' );
has dirs => ( is => 'rw' );
sub dstpath {
my $self = shift;
return $self->path2public();
}
sub htmlpath {
my $self = shift;
return $self->path2public() . '/';
}
sub indexpath {
# only used for nonexistent index.html outputs
my $self = shift;
return $self->dstpath . '/index.html';
}
sub menu {
my $self = shift;
my @objects = @{$self->dirs};
push @objects, grep { ! $_->isindex } @{$self->files};
my @menu = map { { href => $_->htmlpath, cap => $_->caption } } sort { $a->ioall->name cmp $b->ioall->name } @objects;
return @menu;
}
1;
#####################################
package Quietly::Confident::File;
use Moo;
use Sub::Quote;
use Text::Markdown 'markdown';
use Pod::Html;
use IO::All -utf8;
use URI::Encode;
with('Quietly::Confident::Role');
has type => ( is => 'rw' );
has date => ( is => 'rw' );
has by => ( is => 'rw' );
has raw => ( is => 'rw' );
has isindex => ( is => 'rw' );
sub realpath {
my $self = shift;
return io->catfile($self->config->{repository}, $self->ioall->name);
}
sub filename {
my $self = shift;
return $self->ioall->filename;
}
sub cleanhtml {
# remove headers and styling
my ($self, $html) = @_;
$html =~ s/<head>.*?<\/head>//sig;
$html =~ s/<(span|font|html|body).*?>//sig;
$html =~ s/<\/(font|span|html|body)>//sig;
$html =~ s/(style|class|id)=(\"|\').*?(\"|\')//sig;
$html =~ s/<\?xml.*?\?>//sig;
$html =~ s/<!DOCTYPE.*?>//sig;
# remove Microsoft artifacts
$html =~ s/<o:p>[^<]*<\/o:p>//sig;
$html =~ s/<p\s*>\s*<\/p>//sig;
# <![if !supportLists]>
$html =~ s/<\!?\[[^\]]*\]>//sig;
# try to remove redundant linebreaks
my($para);
$html =~ s{(?<=<p>)(.*?)(?=<\/p>)}
{
$para = $1;
if ($para !~ /<pre>/) {
# not preformatted
$para =~ s#<br[^>]*?># #gs;
$para =~ s#<br># #gs;
}
$para;
}exgs;
return $html;
}
sub content {
my $self = shift;
my ($html, $raw);
if($self->raw) {
$raw = $self->raw;
}
else {
$raw = io($self->realpath)->slurp;
$self->raw($raw);
}
if($self->type eq 'markdown') {
$html = markdown($raw);
}
elsif($self->type eq 'html') {
$html = $self->cleanhtml($raw);
}
elsif($self->type eq 'pod') {
my $raw = io("pod2html " . $self->realpath . "|")->slurp;
$html = $self->cleanhtml($raw);
}
else {
$html = $raw;
}
my $uri = URI::Encode->new( { encode_reserved => 0 } );
my %img;
while ($html =~ /(<img[^>]*>)/gsi) {
my $imgcode = $1;
#print "IMG: orig: $imgcode\n";
if($imgcode =~ /src="(?<!http)([^"]*)"/is) {
my $imguri = $1;
#print "IMG: processing $imguri\n";
my $imgpath = $uri->decode($imguri);
$imgpath =~ s/.*\///;
my $thu = $self->config->{mediapath} . "thumb" . $imgpath;
my $newimgcode = $imgcode;
$newimgcode =~ s/(width|height)="[^"]*"//gs;
if(-e $thu) {
#print "IMG: is thumb\n";
$newimgcode =~ s/\Q$imguri\E/$self->config->{media} . "thumb" . $uri->encode($imgpath)/es;
$newimgcode = "<a href=\"" . $self->config->{media} . $imgpath . "\">$newimgcode<\/a>";
}
else {
#print "IMG: no thumb\n";
$newimgcode =~ s/\Q$imguri\E/$self->config->{media} . $imgpath/es;
}
$img{$imgcode} = $newimgcode;
}
}
foreach my $orig (keys %img) {
#print "IMG2: replacing $orig\n";
#print " with $img{$orig}\n";
$html =~ s/\Q$orig\E/$img{$orig}/ges;
}
return $html;
}
sub description {
my $self = shift;
my $html = $self->content;
my $des = "";
if($html =~ /<p>([^<]*)<\/p>/s) {
$des = $1;
$des =~ s/<\/?[^>]*//s;
}
return $des;
}
sub keywords {
my $self = shift;
my $des = $self->description;
my @words = grep { length($_) > 5 } split /\s\s*/, $des;
return join ',', @words;
}
sub dstpath {
# physical destination file
my $self = shift;
my $out = $self->path2public(1);
return $out . "index.html";
}
sub htmlpath {
# used for links
my $self = shift;
return $self->path2public(1);
}
sub blogpath {
# used for blog entries
my $self = shift;
my $out = $self->path2public(1);
$out =~ s/^blog[^\/]*//;
$out =~ s/\///g;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($self->date);
$mon++;
$year += 1900;
$out = sprintf "blog/%04d/%02d/%02d/$out/", $year, $mon, $mday;
return $out;
}
sub dstblogpath {
# physical destination file
my $self = shift;
my $out = $self->blogpath;
return $out . "index.html";
}
sub basepath {
# dir one level above
my $self = shift;
my $out = $self->path2public(1);
$out =~ s/\/[^\/]*\/$/\//;
return $out;
}
#####################################
package main;
use Git::Repository;
use Git::Repository 'Log';
use Config::General qw(ParseConfig);
use File::Path qw(make_path);
use Template;
use Data::Dumper;
use HTTP::Server::Brick;
use POSIX qw( WNOHANG setsid );
use IO::All -utf8;
my %types = qw(jpg image png image jpeg image gif image txt markdown md markdown html html htm html pod pod xhtml html);
my %config;
my %menu;
my @images;
my $git;
my $command = shift || '';
my $workdir = shift || '';
my $param = shift || '';
if(! $command) {
$command = "usage";
}
if (! $param && $workdir =~ /^[\d\.:]*$/) {
# workdir is host:port
$param = $workdir;
$workdir = '';
}
if ($workdir) {
if (! -d $workdir) {
print STDERR "workdir $workdir does not exist or is not accessible!\n";
exit 1;
}
else {
$workdir = io($workdir);
$workdir->chdir;
}
}
else {
$workdir = io->curdir->absolute;
&log("workdir: $workdir");
}
if (-e "qc.conf") {
%config = ParseConfig(-ConfigFile => "qc.conf", -AutoTrue => 1);
}
else {
if ($command ne "init") {
die "Could not open config file qc.conf!\nConsider running $0 init\n";
}
}
no strict "refs";
my @allowed = qw(watch daemon init generate serve);
if (! grep { $command eq $_ } @allowed) {
print "Unknown command $command!\n";
print "$@\n";
&usage;
}
&$command;
# main end
sub generate {
eval {
$git = Git::Repository->new( work_tree => $config{repository} );
};
if ($@) {
if (! $config{local}) {
die $@;
} else {
$@ = '';
}
}
chdir $config{repository};
my $root = &iterate(io('.'), 1);
$workdir->chdir;
make_path($config{mediapath}, { mode => 0755, verbose => 1 });
foreach my $img (@images) {
my $src = $img->realpath;
my $dst = $config{mediapath} . $img->filename;
my $thu = $config{mediapath} . "thumb" . $img->filename;
if (! -e $dst ) {
&cpimg($src, $dst, $thu);
}
else {
my $mtime = (stat($dst))[9];
if ($img->date > $mtime) {
&cpimg($src, $dst, $thu);
}
}
}
&genmenus($root);
&process($root);
}
sub cpimg {
my($src, $dst, $thu) = @_;
&log( "Copying image $src => $dst\n");
system("cp \"$src\" \"$dst\"");
open ID, "identify \"$src\"|";
my $id = <ID>;
close ID;
if ($id =~ / (\d+?)x(\d+?) /) {
my $width = $1;
my $height= $2;
if ($width > 500) {
&log("Image is too big ($width x $height), resizing");
system("convert -size 500x500 \"$src\" -resize 500x500 \"$thu\"");
}
}
}
sub genmenus {
require Encode;
my $gitdir = shift;
my $level = $gitdir->level;
my @menu = $gitdir->menu;
my $path = $gitdir->htmlpath;
if ($path eq '/') {
$path = "root";
}
if ($gitdir->dstpath =~ /^blog/) {
$menu{$path} = [];
return;
}
$menu{$path} = \@menu;
foreach my $dir (@{$gitdir->dirs}) {
&genmenus($dir);
}
}
sub processblog {
my $gitdir = shift;
my @posts = sort { $b->date <=> $a->date } @{$gitdir->files};
my $max = 5;
my @pages;
if (scalar @posts > $max) {
while (@posts) {
my $curlen = scalar @posts;
my @page;
if ($curlen >= $max) {
@page = splice(@posts, 0, $max);
} else {
@page = splice(@posts, 0);
}
push @pages, \@page;
}
} else {
push @pages, \@posts;
}
my $t = Template->new({
OUTPUT_PATH => $config{public},
INCLUDE_PATH => $config{templates},
INTERPOLATE => 1 }) || die "$Template::ERROR\n";
my $pagenum = 0;
foreach my $page (@pages) {
my $dir = $gitdir->dstpath;
if ($pagenum > 0) {
$dir .= "/page/$pagenum";
}
if (! -d "$config{public}/$dir" ) {
make_path("$config{public}/$dir", { mode => 0755, verbose => 1 });
}
my $file = $dir . "/index.html";
my $prev = "page/" . ($pagenum - 1) . "/";
my $next = "page/" . ($pagenum + 1) . "/";
if ($pagenum == 0) {
$prev = "";
}
if ($pagenum == $#pages) {
$next = "";
}
if ($pagenum == 1) {
$prev = "../..";
}
&log( "Processing: blog index page $pagenum => $file in $dir");
$t->process( 'blog.tpl', { config => \%config,
posts => $page,
prev => $prev,
next => $next,
menu => \%menu,
level => $gitdir->level,
basepath => $gitdir->htmlpath,
keywords => $page->[0]->keywords,
description => $page->[0]->description,
title => $page->[0]->caption }, $file) or die $t->error() . "\n";
if ($pagenum == 0) {
$dir .= "/feed/";
$file = $dir . "atom.xml";
&log( "Processing: blog feed => $file in $dir");
$t->process( 'atom.tpl', { config => \%config,
posts => $page,
updated => $page->[0]->date,
}, $file) or die $t->error() . "\n";
}
foreach my $post (@{$page}) {
&log( "Processing: blog post page " . $post->blogpath);
$t->process( 'post.tpl', { config => \%config,
post => $post,
menu => \%menu,
level => $gitdir->level,
basepath => $post->basepath,
keywords => $post->keywords,
description => $post->description,
title => $post->caption }, $post->dstblogpath) or die $t->error() . "\n";
}
$pagenum++;
}
}
sub process {
my $gitdir = shift;
my $dir = "$config{public}/" . $gitdir->dstpath;
if (! -d "$dir" ) {
make_path("$dir", { mode => 0755, verbose => 1 });
}
if ($gitdir->dstpath =~ /^blog/) {
&processblog($gitdir);
return;
}
my $t = Template->new({
OUTPUT_PATH => $config{public},
INCLUDE_PATH => $config{templates},
INTERPOLATE => 1 }) || die "$Template::ERROR\n";
foreach my $gitfile (@{$gitdir->files}) {
my $title = $gitfile->caption;
if ($gitdir->level == 1 && $gitfile->isindex) {
$title = $config{sitetitle};
} elsif ($gitfile->isindex) {
$title = $gitdir->caption;
}
&log( "Processing: " . $gitfile->htmlpath . " => " . $gitfile->dstpath);
$t->process( 'page.tpl', { config => \%config,
basepath => $gitfile->basepath,
level => $gitdir->level,
menu => \%menu,
content => $gitfile->content,
keywords => $gitfile->keywords,
description => $gitfile->description,
title => $title }, $gitfile->dstpath, { binmode => ':utf8' }) or die $t->error() . "\n";
}
if (! $gitdir->hasindex) {
&log( "Processing: " . $gitdir->indexpath );
$t->process( 'page.tpl', { config => \%config,
basepath => $gitdir->htmlpath,
level => $gitdir->level,
menu => \%menu,
content => '',
title => $gitdir->caption }, $gitdir->indexpath, { binmode => ':utf8' }) or die $t->error() . "\n";
}
if ( $gitdir->hasdirs) {
foreach my $dir (@{$gitdir->dirs}) {
&process($dir);
}
}
}
sub type {
my $file = shift;
if ($file =~ /\.([^\.]*)$/i) {
my $suffix = $1;
if (exists $types{$suffix}) {
return $types{$suffix};
}
}
return 'unknown';
}
sub iterate {
my($dir, $level) = @_;
printf "Iterating in %s\n", $dir->name;
my $gitdir = Quietly::Confident::Dir->new(
files => [],
dirs => [],
hasindex => 0,
hasdirs => 0,
hasfiles => 0,
level => $level );
$gitdir->ioall( $dir );
foreach my $file ($dir->all) {
my $path = "$file";
$path =~ s/^\.\///;
$file = io($path);
if ( $file->is_dir ) {
push @{$gitdir->{dirs}}, &iterate($file, $level + 1);
$gitdir->hasdirs(1);
}
else {
my $log;
eval { ($log) = Git::Repository->log( '-1', $file ) };
$@ = '';
my $gitfile;
if ($log) {
$gitfile = Quietly::Confident::File->new( ioall => $file,
config => \%config,
type => &type($file),
date => $log->committer_localtime,
by => $log->committer_name );
}
else {
# not part of git, but use it if local option is set
if ($config{local}) {
$gitfile = Quietly::Confident::File->new( ioall => $file,
config => \%config,
type => &type($file),
date => $file->mtime,
by => (getpwuid($file->uid))[0] );
#print "ioall file: " . $file->absolute->pathname ."\n";
}
}
if ($gitfile) {
$gitdir->hasfiles(1);
if ($file =~ /^index\.(md|html|htm)$/) {
$gitdir->hasindex(1);
$gitfile->isindex(1);
}
if ($gitfile->type eq 'image') {
push @images, $gitfile;
}
else {
push @{$gitdir->{files}}, $gitfile;
}
}
}
}
return $gitdir;
}
sub usage {
print qq(
Usage: $0 <command> [<working directory>]
Avalable commands are:
init - initialize a new site
generate - generate static content from repository
serve [[ip]:port] - serve site via HTTP. defaults to $hostname:8080
daemon - detach from terminal and run in background
watch - watch for updates, same as daemon but in forreground
);
exit 1;
}
sub init {
print "Creating qc.conf\n";
open C, ">qc.conf" or die "Could not open qc.conf: $!\n";
print C qq(
#
# config file for qc tool
repository = source
public = public_html
templates = templates
sitetitle = Quietly Confitent Static Site
baseuri = /
media = /images/
mediapath = public_html/images/
local = yes
);
close C;
print "Creating directories\n";
foreach my $dir (qw(source public_html templates public_html)) {
make_path($dir, { mode => 0755, verbose => 1 });
}
print "Creating basic templates\n";
my $data = join "", <DATA>;
$data =~ s/^begin \d{3} IGNORE\n//;
$data =~ s/end$//;
my $zipfile = unpack("u", $data);
open Z, ">init.zip" or die "Could not extract initialization data: $!\n";
print Z $zipfile;
close Z;
system("unzip -q init.zip") and die "Could not unzip init data: $!\n";
unlink "init.zip";
print "Creating static site\n";
%config = ParseConfig(-ConfigFile => 'qc.conf', -AutoTrue => 1);
}
sub serve {
my $host = '';
my $port = '8080';
if ($param) {
($host, $port) = split /:/, $param;
}
my $httpd = HTTP::Server::Brick->new(host => $host, port => $port);
$httpd->mount('/' => { path => $config{public}});
$httpd->start;
}
sub daemon {
$workdir->chdir;
my $git;
$System::Command::QUIET = 1;
open LOG, ">> $workdir/qc.log" or die "Could not open daemon logfile $workdir/qc.log: $!\n";
$SIG{CHLD} = \&REAPER;
my $pid = fork();
if ($pid) {
$SIG{CHLD} = \&REAPER;
print "Forked with PID $pid\n";
exit 0;
}
# child here
setsid();
setpgrp();
my $pidfile = "$workdir/qc.pid";
if ($config{pidfile}) {
$pidfile = $config{pidfile};
}
open P, ">$pidfile" or die "Could not open $pidfile: $!\n";
print P "$$\n";
close P;
$SIG{INT} = sub { &log("finishing on request"); exit; };
$SIG{HUP} = sub { &log("got SIGHUP, reloading"); exec(qw($0 daemon $workdir)); exit; };
select LOG;
open ERRLOG, ">$workdir/qc.stderr";
open STDERR, ">&", \*ERRLOG;
$| = 1;
&log("$0 started in daemon mode in $workdir with pid $$");
&watch();
}
sub watch {
my ($git) = @_;
my $gitmode = 1;
if (! $git) {
$git = eval { Git::Repository->new( work_tree => $config{repository} ); };
&log("\$\@: <$@>");
if ($@ || ! -d "$config{repository}/.git") {
print STDERR "$config{repository} is not a git repository!\n";
print STDERR "Watching in filesystem mode.\n";
$gitmode = 0;
}
}
if ($gitmode) {
&log("gitwatch");
&gitwatch($git);
}
else {
&log("fswatch");
&fswatch();
}
}
sub setlast {
open LAST, ">${workdir}/.last" or die "Could not write to ${workdir}/.last: $!\n";
print LAST "0\n";
close LAST;
}
sub fswatch {
if (! -e "${workdir}/.last") {
&setlast;
}
while (1) {
open FIND, "find $config{repository} -newer $workdir/.last|" or die "Could not execute find: $!\n";
my $found = <FIND>;
close FIND;
if ($found) {
&log("observed changes in $config{repository}, generating site");
&generate;
&setlast;
}
sleep 60;
}
}
sub gitwatch {
my ($git) = @_;
while (1) {
eval { $git->run(qw(remote update)); };
if ($@) {
&log("git remote update failed: $@");
}
else {
my $status;
eval { $status = $git->run(qw(diff master origin/master)); };
if ($@) {
&log("git diff master origin/master failed: $@");
}
else {
if ($status =~ /diff \-\-git/) {
&log("observed changes in $config{repository} on master, pulling");
eval {$git->run(qw(pull));};
if (! $@) {
&log("git pull done. generating site");
&generate;
}
else {
&log("git pull failed with: $@");
}
}
}
}
sleep 60;
}
}
sub log {
my $msg = shift;
chomp $msg;
if ($command eq 'daemon') {
my $time = scalar localtime;
print "$time [$$] $msg\n";
}
else {
print "$msg\n";
}
}
no strict 'subs';
my %Kid_Status;
sub REAPER {
my $child;
while (($child = waitpid(-1,WNOHANG)) > 0) {
$Kid_Status{$child} = $?;
}
$SIG{CHLD} = \&REAPER; # still loathe SysV
}
__DATA__
begin 644 IGNORE
M4$L#!`H``````#I284$````````````````,`!P`<'5B;&EC7VAT;6PO550)
M``-`/I)0/]FD4'5X"P`!!.D#```$Z0,``%!+`P0*```````Z4F%!````````
M````````$``<`'!U8FQI8U]H=&UL+V-S<R]55`D``T`^DE`_V:10=7@+``$$
MZ0,```3I`P``4$L#!!0`"``(`#I284$``````````.0W```H`!P`<'5B;&EC
M7VAT;6PO8W-S+V)O;W1S=')A<"UR97-P;VYS:79E+F-S<U54"0`#0#Z24+"(
MHE!U>`L``03I`P``!.D#``#M6]^/W+81?O=?P9QA('9/.I*B1'&-&&[3/`0(
M^M#V+<B#=J6[%:R5!$EWMW:0_[U#_5A)Y$B[YPW:%,@EL+WBQX_#X7`XGXY[
M]^Z;5^0=^5M1-'53127Y9U*715ZG3PEYXBYU/6C6B.^+\G.5/NP;PBGCY-_/
M:=,DU2WY,=_IYI_279+724P>\SBI2+-/R%_+:`=_]2TMFT;NFZ;<W-T]/S^[
M48M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