Publish
file: potd.p6
1: #!/usr/bin/env perl6
2:
3: use File::HomeDir;
4:
5: sub MAIN ( $file, Int :$offset = 1, Bool :$local ) {
6: die "No such file $file" unless $file.IO.e;
7:
8: my $date = Date.today + $offset;
9:
10: my $ok = prompt "Creating POTD for $date, ok? ";
11: exit if $ok ~~ m:i/^n/;
12:
13: my $home = File::HomeDir.new.my_home.IO;
14: my $blio = $home.child( 'privat/domm.plix.at' );
15: my $target_img = $blio.child( 'src/potd/' ~ $date ~ '.jpg' );
16: my $target_txt = $blio.child( 'src/potd/' ~ $date ~ '.txt' );
17: my $archive = $home.child( 'media/fotos/2015/potd/' ~ $date ~ '.jpg' );
18:
19: my $template = template( $date );
20: spurt $target_txt, $template, :createonly;
21: shell "vim $target_txt";
22:
23: shell "potd_handle_image.pl $file $target_img $archive";
24:
25: publish( $target_img, $target_txt, $date );
26:
27: build_local( $blio ) if $local;
28: }
29:
30: sub template ( Date $date ) {
31: my $publish_datetime = $date ~ 'T10:00:00';
32: return qq:to/EOBLIO/;
33: title:
34: tweet:
35: date: $publish_datetime
36: converter: textile
37: template: potd.tt
38:
39:
40: EOBLIO
41: }
42:
43: sub publish ( $target_img, $target_txt, $basename ) {
44: chdir $target_img.dirname;
45: my @commands =
46: "git add $target_img $target_txt",
47: "git commit -m 'potd $basename'",
48: "git push";
49: for @commands -> $command {
50: shell $command;
51: }
52: }
53:
54: sub build_local ( $blio ) {
55: chdir $blio;
56: say "starting to build local website";
57: shell './build_t430 --nosched > /dev/null';
58: say "done building local website";
59: }
60: