Last active
August 29, 2015 14:01
-
-
Save chadluo/04069be14d4c8ed1edfb to your computer and use it in GitHub Desktop.
generate new Jekyll post with CLI arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use POSIX qw(strftime); | |
my $category = "chatter"; | |
my $permalink = ""; | |
if (scalar @ARGV == 1) { | |
$permalink = $ARGV[0]; | |
} elsif (scalar @ARGV == 2) { | |
$category = $ARGV[0]; | |
$permalink = $ARGV[1]; | |
} else { | |
die "invalid parameters."; | |
} | |
my ($date,$time) = split / /,(strftime "%Y-%m-%d %H:%M:%S", localtime); | |
my $name = "./_posts/".$date."-".$permalink.".textile"; | |
die "file exists.\n" if -e $name; | |
open FILE,">".$name or die "failed to open file"; | |
print FILE <<eof; | |
--- | |
layout: post | |
title: \"\" | |
category: $category | |
date: $date $time | |
--- | |
eof | |
close FILE; | |
print $name."\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment