-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_new_post.pl
83 lines (73 loc) · 2.22 KB
/
create_new_post.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl
use strict;
use Cwd;
use POSIX qw(strftime);
my $cwd = getcwd();
my $projectpath = $cwd."/tips-tutorials";
my $input;
my $datestring = strftime "%Y-%m-%d %H:%M:%S", localtime;
my $date = strftime "%Y-%m-%d", localtime;
$datestring = $datestring."+0100";
print "Folder: $projectpath \n";
print "Do you want to change the current jekeyll project folder (Y/N):\n";
$input = <STDIN>; #read stdin
chomp ($input);
if ($input eq 'Y' or $input eq 'y')
{
$projectpath = <STDIN>;
chomp ($projectpath);
}
print "Please enter the title of the new post:\n";
my $title = <STDIN>; #read stdin
chomp ($title);
my $newtitle = $title;
# replace ' ' with '-'
$newtitle=~s/ /-/g;
print "The title was pepared to:\n";
print $newtitle;
print "\n";
print "Please enter a description of the new post:\n";
my $description = <STDIN>; #read stdin
chomp ($description);
print "Please enter the tags of the new post (seperated by ,):\n";
my $tags = <STDIN>; #read stdin
chomp ($tags);
my $imgfolder = $projectpath."/img/".$date."-".$newtitle;
my $imgfoldershort = "/img/".$date."-".$newtitle;
my $mdfile = $projectpath."/_posts/".$date."-".$newtitle.".md";
# Use the open() function to create the file.
unless(open FILE, '>'.$mdfile) {
# Die with error message
# if we can't open it.
die "\nUnable to create $mdfile\n";
}
#Use mkdir() function to create folder
unless(-e $imgfolder or mkdir $imgfolder) {
die "Unable to create $imgfolder\n";
}
print FILE "---\n";
print FILE "layout: post\n";
print FILE "title: $title \n";
print FILE "description: $description.\n";
print FILE "date: $datestring\n";
print FILE "date_modified: $datestring\n";
print FILE "categories: [$tags]\n";
print FILE "tags:\n";
my @values = split(',', $tags);
foreach my $val (@values) {
print FILE " - $val\n";
}
print FILE "author: wechris\n";
print FILE "image:\n";
print FILE " path: $imgfoldershort/postpreview.jpg\n";
print FILE " width: 629\n";
print FILE " height: 600\n";
print FILE "---\n";
# close the file.
close FILE;
print "Successfully created the new post template:\n";
print "Image folder: ".$imgfoldershort."\n";
print "Markdown file: ".$mdfile."\n";
open(OUT,$mdfile) || errout();
while(<OUT>) { print ; }
close(OUT);