-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
67 lines (58 loc) · 2 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
require 'rubygems'
require 'rake'
require 'yaml'
require 'time'
require 'pry'
require './_lib/asset'
require 'cloudinary'
include Asset
SOURCE = '.'.freeze
CONFIG = {
'posts' => File.join(SOURCE, '_posts'),
'post_ext' => 'md'
}.freeze
meses = {
'January' => 'Janeiro', 'February' => 'Fevereiro', 'March' => 'Março', 'April' => 'Abril', 'May' => 'Maio', 'June' => 'Junho',
'July' => 'Julho', 'August' => 'Agosto', 'September' => 'Setembro', 'October' => 'Outubro', 'November' => 'Novembro', 'December' => 'Dezembro'
}
# Usage: rake post title="A Title" [date="2012-02-09"] [tags=[tag1,tag2]] [category="category"]
desc 'rake post title="A Title"'
task :post do
abort("rake aborted: '#{CONFIG['posts']}' directory not found.") unless FileTest.directory?(CONFIG['posts'])
title = ENV['title'] || 'new-post'
slug = title.downcase.strip.tr(' ', '_').gsub(/[^\w-]/, '')
post_count = Dir["#{CONFIG['posts']}/*.md"].size
date = Time.now.strftime('%Y-%m-%d')
project_month = Time.now.strftime('%B')
ano = Time.now.strftime('%Y')
filename = File.join(CONFIG['posts'], "#{date}-#{slug}.#{CONFIG['post_ext']}")
abort("post já existe!!") if File.exist?(filename)
cdn_data = process_upload_cdn(title)
puts "Creating new post: #{filename}"
open(filename, 'w') do |post|
post.puts '---'
post.puts 'layout: default'
post.puts "thumb_url: \"#{cdn_data[:thumb_url]}\""
post.puts "optimized_url: \"#{cdn_data[:optimized_url]}\""
post.puts "modal_id: #{post_count + 1}\n"
post.puts "date: #{date}"
post.puts "title: \"#{title}\""
post.puts 'subtitle: '
post.puts "img: \"#{slug}\""
post.puts 'link: '
post.puts "project_date: #{meses[project_month]} de #{ano}"
post.puts "prioridade: 0"
post.puts 'client: '
post.puts 'categories : []'
post.puts 'description: '
post.puts '---'
end
end # task :post
namespace :assets do
desc 'optimize png'
task :optimize do
Asset.optimize
end
end
# Load custom rake scripts
Dir['./_lib/rake/*.rake'].each { |r| load r }