Skip to content

Commit 54e4b70

Browse files
committed
Restores original file
Which I deleted for no reason.
1 parent 4139909 commit 54e4b70

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

apps/aux/git-hooks.pl

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,50 @@
44
use warnings;
55
use v5.14;
66
use Git::Hooks;
7+
use File::Slurp qw(read_file write_file);
8+
9+
my $layout_preffix=<<EOT;
10+
---
11+
layout: index
12+
---
13+
14+
EOT
715

816
POST_COMMIT {
917
my ($git) = @_;
1018
my $branch = $git->command(qw/rev-parse --abbrev-ref HEAD/);
1119
if ( $branch =~ /master/ ) {
12-
if ( $git->command(qw/show --name-status/) =~ /testeando.ad/ ) {
13-
#Now change branch and process
14-
#Inspired by http://stackoverflow.com/questions/15214762/how-can-i-sync-documentation-with-github-pages
15-
$git->command(qw/checkout gh-pages/);
16-
$git->command( 'checkout', 'master', '--', 'testeando.ad' );
17-
`asciidoc --backend deckjs testeando.ad -o index.html`;
18-
$git->command('commit','-a', '-m', "Generando diapos en gh-pages");
20+
my $changed = $git->command(qw/show --name-status/);
21+
my @changed_files = ($changed =~ /\s\w\s+(\S+)/g);
22+
my @mds = grep ( /\.md/, @changed_files );
23+
#Now change branch and process
24+
#Inspired by http://stackoverflow.com/questions/15214762/how-can-i-sync-documentation-with-github-pages
25+
$git->command(qw/checkout gh-pages/);
26+
for my $f ( @mds ) {
27+
$git->command( 'checkout', 'master', '--', $f );
28+
my $file_content = read_file( $f );
29+
$file_content =~ s/\.md\)/\)/g; # Change links
30+
$file_content = $layout_preffix.$file_content;
31+
if ( $f ne 'README.md' ) {
32+
write_file($f, $file_content);
33+
$git->command('add', $f );
34+
} else {
35+
write_file('index.md', $file_content );
36+
$git->command('add', 'index.md' );
37+
unlink('README.md');
1938
}
20-
$git->command(qw/checkout master/); #back to original
39+
$git->command('commit','-a', '-m', "Sync $f from master to gh-pages");
40+
say "Processing $f";
41+
}
42+
$git->command(qw/checkout master/); #back to original branch
2143
}
2244
};
2345

2446
run_hook($0, @ARGV);
2547

2648
=head1 NAME
2749
28-
git-hooks.pl - Genera diapos en otra rama.
50+
git-hooks.pl - post-commit hooks to sync markdown files with GitHub pages
2951
3052
=head2 SYNOPSIS
3153

0 commit comments

Comments
 (0)