-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
127 lines (102 loc) · 3.34 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
require 'rubygems'
require 'bundler'
Bundler.require
require 'time'
task :default => [:run_server]
desc "run server"
task :run_server do
system "bin/middleman serve"
end
desc "build pages"
task :build do
system "bin/middleman build --verbose"
end
desc "deploy to gh-pages with bump"
task :deploy, [:bump] do |_, args|
args.with_defaults(bump: 'patch')
now = Time.now.strftime("%Y-%m-%d-%H-%M")
system %{
cd build/ &&
git pull &&
cd ../ &&
bumpversion #{args.bump} &&
git push &&
middleman build &&
cd build/ &&
git add . &&
git commit -m "release #{now}" &&
git push &&
cd ../
}
puts "Deployed..."
end
VALID_LANGUAGES = ["tr", "en"]
BLOG_TIME_FORMAT = "%b %d, %Y %H:%M"
BLOG_FRONTMATTER_DATE_FORMAT = "%Y-%m-%d %H:%M"
BLOG_FILE_DATE_FORMAT = "%Y-%m-%d"
namespace :new do
desc "new page"
task :page, [:title, :language] do |_, args|
args.with_defaults(language: "tr")
abort "please enter page title!..." unless args.title
abort "please set valid language: #{VALID_LANGUAGES.join(",")}. #{args.language} is not a valid" unless VALID_LANGUAGES.include?(args.language)
blog_name = {en: "english", tr: "turkish"}
page_val = {en: "page", tr: "sayfa"}
output = []
output << '---'
output << "title: #{args.title}"
output << "locale: #{args.language}"
output << '# subtitle: ""'
output << "# blog: #{blog_name[args.language.to_sym]}"
output << "layout: #{args.language}/layout-common"
output << "# layout: #{args.language}/layout-common-markdown"
output << '# cover: ""'
output << '# cover_title: ""'
output << '# cover_subtitle: ""'
output << '# og_image: ""'
output << '# og_image_dir: ""'
output << 'comments: false'
output << '---'
save_file = "source/pages/#{args.language}/#{args.title.to_url}.html.md.erb"
# File.open(save_file, "w") do |f|
# f.write output.join("\n")
# end
puts "New page is ready at: #{save_file}"
puts "now add this proxy to your config.rb:"
puts "proxy_page \"/#{page_val[args.language.to_sym]}/#{args.language}/#{args.title.to_url}/index.html\", \"/pages/#{args.language}/#{args.title.to_url}.html.md.erb\", locals: {locale: \"#{args.language}\"}, ignore: true"
end
desc "new blog post"
task :post, [:title, :language, :publish_date] do |_, args|
now = Time.now
publish_date = Time.parse(args.publish_date || now.strftime(BLOG_TIME_FORMAT))
file_date = publish_date.strftime(BLOG_FILE_DATE_FORMAT)
args.with_defaults(language: "tr", publish_date: publish_date)
abort "please enter post title!..." unless args.title
abort "please set valid language: #{VALID_LANGUAGES.join(",")}. #{args.language} is not a valid" unless VALID_LANGUAGES.include?(args.language)
frontmatter_date = publish_date.strftime(BLOG_FRONTMATTER_DATE_FORMAT)
output = <<-END
---
title: "#{args.title}"
locale: #{args.language}
# subtitle: ""
date: #{frontmatter_date}
# cover: ""
# cover_title: ""
# cover_subtitle: ""
# og_image: ""
# og_image_dir: ""
# tags: tag1,tag2
comments: false
---
END
save_file = "source/blog/#{args.language}/#{file_date}-#{args.title.to_url}.html.md.erb"
File.open(save_file, "w") do |f|
f.write output
end
puts "new post is ready at: #{save_file}"
end
end
desc "print now"
task :now do
system "date +'%Y-%M-%d %H:%M'"
end