-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathblog
executable file
·91 lines (86 loc) · 2.56 KB
/
blog
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
84
85
86
87
88
89
90
91
#!/usr/bin/env ruby
require 'thor'
def edit(file)
system "gedit #{file}" or system %{cmd /c "notepad #{file}"}
end
class Edit < Thor
include Thor::Actions
desc 'post', 'edits a post'
def post
#_posts = Dir['source/posts/*']
#for post in _posts
posts = []
Dir.entries('source/posts').select {|f| !File.directory? f}.each do |file|
posts.push file.sub('.html.markdown', '').gsub('-', ' ')
end
puts posts
name = ask 'What is the name of the post you would like to edit?', limited_to: posts
edit 'source/posts/' + name.gsub(' ', '-') + '.html.markdown'
if yes? 'Would you like to publish your post?'
MyCLI.new.invoke :publish
end
end
end
class New < Thor
include Thor::Actions
desc "post", "makes a new post"
def post
name = ask 'What is the name of the new post?'
clean_name = "source/posts/#{name.gsub(/[^0-9a-z ]/i, '').squeeze(' ').gsub(/\s/, '-').downcase}.html.markdown"
authors = []
getMoreAuthors = true
while getMoreAuthors
authors.push ask 'What is the name of the author?'
getMoreAuthors = yes? 'Is there another author?'
end
if authors.length == 1
author_string = "author: #{authors.first}"
else
author_string = "authors: #{authors.join(', ')}"
end
tags = []
if yes? 'does this post have any tags?'
getMoreTags = true
while getMoreTags
tags.push ask 'What is the tag?'
getMoreTags = yes? 'Is there another tag?'
end
end
create_file clean_name do
"---
title: #{name}
date: #{Time.now}
#{author_string}
tags: #{tags.join(', ')}
---"
end
edit clean_name
if yes? 'Would you like to publish your post?'
MyCLI.new.invoke :publish
end
end
end
class MyCLI < Thor
include Thor::Actions
desc 'edit SUBCOMMAND', 'some parent command'
subcommand 'edit', Edit
desc "new SUBCOMMAND", "Some Parent Command"
subcommand "new", New
desc 'publish', 'uploads the code to GitHub, to the real website'
def publish
`git checkout source | grep error`
`git add -A | grep error`
puts `git status | grep 'new file:'`
puts `git status | grep 'modified:'`
puts `git status | grep 'deleted:'`
commit_message = ask 'What changes have you made to the website?'
`git commit -am "#{commit_message}"`
`git pull origin source`
if yes? 'Are you sure you want to publish these changes?'
`git push origin source`
`rake publish -s`
`wget feedburner.google.com/fb/a/pingSubmit\?bloglink\=http%3A%2F%2Ffeeds.feedburner.com%2Fteam1432 -O /dev/null`
end
end
end
MyCLI.start(ARGV)