This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Rakefile
91 lines (77 loc) · 2.73 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
require 'bundler'
Bundler.setup(:default)
require 'date'
require 'html-proofer'
def slugify(title)
"#{Time.now.strftime('%Y-%m-%d')}-#{title.gsub(/[^\w]+/, '-')}"
end
def get_filename(slug)
File.join File.dirname(__FILE__), '_posts', "#{slug}.md"
end
def make_image_dir(slug)
new_dir = File.join File.dirname(__FILE__), 'images', slug
Dir.mkdir new_dir
end
desc 'Create an unpublished post'
task :post, :title, :with_images do |_t, args|
args.with_defaults title: 'New Post', with_images: false
title = args.title
slug = slugify title
File.open get_filename(slug), 'w' do |f|
f << <<-EOS.gsub(/^ /, '')
---
title: #{title}
excerpt:
layout: post
date: #{Date.today.to_time}
author:
published: false
---
EOS
end
make_image_dir slug if args.with_images
end
desc 'Create an image directory'
task :image_dir, :title do |_t, args|
args.with_defaults title: 'New Post'
title = args.title
slug = slugify title
make_image_dir slug
end
namespace :serve do
desc 'Runs a local server *with* draft posts and watches for changes'
task :drafts do
puts 'Starting the server locally on http://127.0.0.1:4000'
sh 'open http://127.0.0.1:4000'
sh 'bundle exec jekyll serve --watch --drafts --port 4000'
end
desc 'Runs a local server *without* draft posts and watches for changes'
task :published do
puts 'Starting the server locally on http://127.0.0.1:4000'
sh 'open http://127.0.0.1:4000'
sh 'bundle exec jekyll serve --watch --port 4000'
end
end
desc 'Runs a local server with draft posts and watches for changes'
task serve: 'serve:drafts'
task default: :serve
desc 'Test build'
task :test do
sh 'bundle exec jekyll doctor'
sh 'bundle exec jekyll build --config _config.yml,_config_test.yml'
HTMLProofer.check_directory('./_site', url_ignore: [
/relishapp.com/, # blacklisted?
/nike.com/, # blacklisted?
/cognitive.cisco.com/, # blacklisted?
/www.oracle.com/, # blacklisted? getting 403
/www.akamai.com/, # blacklisted? getting 403
/https:\/\/blog.apiary.io\/20/, # Prevent checking for unpublished articles
/https:\/\/github\.com\/search/, # Prevent 429 limiting
/https:\/\/signalvnoise\.com/, # Prevent TLS issue
],
typhoeus: {
headers: {
'User-Agent' => 'ApiaryBlogBot/1.0'
}
}).run
end