Skip to content

Instantly share code, notes, and snippets.

@mudler
Created May 22, 2017 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mudler/807f8f71a88cace91a8fbbbd5faf01f3 to your computer and use it in GitHub Desktop.
Save mudler/807f8f71a88cace91a8fbbbd5faf01f3 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# PODNAME: generate-md
use lib './lib';
use Mojo::Util qw(spurt);
use Pod::POM;
use Pod::POM::View::Pod;
use Pod::Markdown::Github;
use File::Find;
use constant SUBMODULE_DIR => "../docs/";
use constant LIBS_DIR => "./lib/";
use constant BASE_URL => "example.com";
use feature 'say';
use DateTime;
use constant DATE => DateTime->now->hms . " " . DateTime->now->dmy('/');
use feature 'say';
sub modulepod2markdown {
my $pod = Pod::POM->new();
my $pom = $pod->parse_file( $_[0] ) || die $pod->error();
my $markdown;
my $parser = Pod::Markdown::Github->new( perldoc_url_prefix =>
BASE_URL );
$parser->output_string( \$markdown );
$parser->parse_string_document( Pod::POM::View::Pod->print($pom) );
spurt( $markdown, SUBMODULE_DIR . $_[1] ) if $markdown =~ /[a-zA-Z]/g;
}
sub pull {
my $b = shift;
system("git pull");
system("git merge origin " . $b );
system("git submodule update");
}
sub commit {
chdir(SUBMODULE_DIR);
system("git checkout master");
system("git add --all .");
system( "git commit -am 'Documentation automatic snapshot - "
. DATE
. "'; git push -u origin master" );
chdir("../");
system(
"git commit -am 'Documentation automatic snapshot - " . DATE . "'" );
}
pull( $ARGV[0] ) if $ARGV[0];
chdir(LIBS_DIR);
find(
{ wanted => sub {
my $file = $_;
next if ( !/\.pm$/ );
s/\.\///;
s/\.pm/\.md/;
modulepod2markdown( $file, s/\//::/reg );
},
no_chdir => 1
},
"."
);
commit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment