Tue, 14 Jul 2009 02:07:18 +0100
Add initial jorvick utility to manage posts and build the site
13
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 | #!/usr/bin/env lua |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 | |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 | require "jorvick.util" |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 | |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 | local commands = {}; |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 | |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 | function commands.build() |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 | require "jorvick.build"; |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 | end |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 | |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 | function commands.create(...) |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 | local title = table.concat({...}, " "); |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 | if #title == 0 then |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 | title = os.date("New Post %Y-%m-%d"); |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 | end |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 | |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 | local filename = make_short_title(title); |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 | print(posts_dir..filename) |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 | local f = io.open(posts_dir..filename..".markdown", "r"); |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 | if f then print("File already exists or is unreable"); return; end |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 | f = io.open(posts_dir..filename..".markdown", "w+"); |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 | if not f then |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 | print("File not writeable"); |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 | end |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 | |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 | -- YAML |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 | --f:write(" |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 | end |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 | |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 | function commands.help() |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 | print "Jorvick - Blog Generator" |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 | print "" |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 | print "Commands:" |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 | print " create - Create a new blank post with a title" |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 | print " publish - Mark a post as published and stamp it with a date" |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 | print " build - Generate the HTML files and feed for all posts" |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 | print "" |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 | end |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 | |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 | local command = arg[1] or "help"; |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 | table.remove(arg, 1); |
39add8e7fa99
Add initial jorvick utility to manage posts and build the site
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 | (commands[command] or commands.help)(unpack(arg)); |