-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
143 lines (124 loc) · 3.08 KB
/
Rakefile
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
require 'rubygems'
require 'rake/clean'
require 'date'
require 'fileutils'
require 'yaml'
CLEAN.include "_site"
desc "Create a new blog post"
task :blog do
print "Please enter in the title of the blog post: "
title = $stdin.gets.chomp.strip
name = title.gsub(/\s+/, '-')
name = name.gsub(/[^a-zA-Z0-9_-]/, "").downcase
time = Time.now.strftime("%Y-%m-%d")
File.open("_posts/#{time}-#{name}.md", "w+") do |file|
file.puts <<-EOF
---
layout: post
published: false
title: #{title}
date: #{Time.now.strftime('%c')}
---
EOF
end
puts "Created '_posts/#{time}-#{name}.md'"
sh "vim _links/#{time}-#{name}.md"
end
desc "Create a Link Post"
task :link do
print "Please enter in the link name: "
title = $stdin.gets.chomp.strip
print "Please enter in the link: "
link = $stdin.gets.chomp.strip
name = title.gsub(/\s+/, '-')
name = name.gsub(/[^a-zA-Z0-9_-]/, "").downcase
time = Time.now.strftime("%Y-%m-%d, %H-%M-%S")
if File.exists? "_links/#{name}.md"
break
end
File.open("_links/#{name}.md", "w+") do |file|
file.puts <<-EOF
---
layout: link
published: true
title: #{title}
link: #{link}
date: #{Time.now.strftime('%c')}
---
EOF
end
puts "Created '_links/#{name}.md'"
sh "vim _links/#{name}.md"
end
desc "Building Link List"
task :build do
index_content = []
count = 0
current_date = ""
Dir.glob('links/*').reject{|f|
f.gsub(/^(.*)\//, '') == 'index.html'
}.each do |f|
FileUtils.rm_rf(f)
end
Dir.glob('_links/*').map { |file|
f = File.open(file)
date = Time.now
f.each do |line|
if line =~ %r[^date\:(.*)$]i
date = Date.parse $1.strip!
break
end
end
[date, file]
}.sort.reverse.map { |file| file[1] }.each do |file|
title = file.gsub(/^(.*)\//, '').gsub(/(.*)\.(.*)$/, '\1')
ext = File.extname(file)
file = File.open(file, "rb")
contents = file.read
if contents =~ %r[^\-{3}(.*)\-{3}(.*)$]im
meta = YAML.load($1.strip!)
date = Date.parse meta['date']
parsed_date = date.strftime('%A, %d %b %Y')
content = $2.strip!
end
if meta['published'] != true
break
end
if current_date != parsed_date
index_content.push "<h4 class=\"date-seperator" + ((count < 1) ? " first" : "") + "\">#{parsed_date}</h4>"
current_date = parsed_date
end
index_content.push <<-HTML
<dl class="linklist">
<dt>
<a href="#{meta['link']}">#{meta['title']}</a>
<a href="/links/#{title}.html" class="permalink">a</a>
</dt>
<dd>
<p>#{content}</p>
</dd>
</dl>
HTML
FileUtils.cp(file.path, File.join('links', title+ext))
count += 1
end
file = File.open('links/index.html', "rb")
contents = file.read
File.open('links/index.html', 'w+') do |f|
if contents =~ %r[^\-{3}(.*)\-{3}(.*)$]im
f.puts <<-EOF
---
#{$1.strip!}
---
#{index_content * "\n"}
EOF
end
end
puts "Success!"
end
desc "Startup Jekyll"
task :start do
FileUtils.rm_rf('_site')
sh "jekyll --server 4000"
end
task :default => :start