This repository has been archived by the owner on Apr 20, 2021. It is now read-only.
/
Rakefile
53 lines (46 loc) · 1.53 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
def system!(cmd)
raise "Command #{cmd} failed" unless system(cmd)
end
task :build do
system!('rm -rf _site')
system!('bundle exec jekyll build')
end
task :serve do
system!("bundle exec jekyll serve --watch --drafts")
end
task :dev_watch do
system!('bundle exec jekyll build --watch -d ../wisecash/public/help')
end
# reduce size of images using imageoptim
# https://imageoptim.com/command-line.html
# there are other solutions, but this is not intrusive and works nicely
task :optimize do
app = "/Applications/ImageOptim.app/Contents/MacOS/ImageOptim"
system! "#{app} _assets/images/*.*"
end
# I could not find how to automatically build the slug based on the title.
# Even using "slug" in the front-matter did not work. This works, though.
task :auto_slug do
require 'yaml'
require 'jekyll/utils'
require 'active_support/inflector'
Dir.chdir('_posts') do
Dir['*.md'].each do |filename|
content = IO.read(filename)
config = YAML.load(content)
# avoid "amp" to end up in the slug
title = config['title'].titleize
config['title'] = title
title = title.gsub("&", "and")
slug = Jekyll::Utils.slugify(title)
new_filename = "2000-01-01-#{slug}.md"
if new_filename != filename
puts "Renaming #{filename} to #{new_filename}..."
#system!("git mv #{filename} #{new_filename}")
end
# previous attempt, keeping this in case it's useful later
content.gsub!(/^\-{3}.*^\-{3}$/m, config.to_yaml + "---")
IO.write(filename, content)
end
end
end