Skip to content

Instantly share code, notes, and snippets.

@chadluo
Last active August 29, 2015 14:01
Show Gist options
  • Save chadluo/04069be14d4c8ed1edfb to your computer and use it in GitHub Desktop.
Save chadluo/04069be14d4c8ed1edfb to your computer and use it in GitHub Desktop.
generate new Jekyll post with CLI arguments
#!/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