-
Notifications
You must be signed in to change notification settings - Fork 25
/
Rakefile
101 lines (85 loc) · 3.02 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
require 'rubygems'
require 'rake'
require 'fileutils'
# usage rake newpost[my-new-post] or rake newpost['my new post'] or rake newpost (defaults to "new-post")
desc "Begin a new post in _posts"
task :newpost, :title do |t, args|
mkdir_p "./_posts"
args.with_defaults(:title => 'new-post')
title = args.title
filename = "./_posts/#{Time.now.strftime('%Y-%m-%d')}-#{title}.markdown"
if File.exist?(filename)
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
end
puts "Creating new post: #{Time.now.strftime('%Y-%m-%d')}-#{title}"
open(filename, 'w') do |post|
post.puts "---"
post.puts "layout: post"
post.puts "title: \"#{title.gsub(/&/,'&')}\""
post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
post.puts "comments: true"
post.puts "categories: "
post.puts "---"
end
end
## Scraping publications
desc "Scrape Google Scholar"
task :scrape do
Rake::Task
puts "## Scraping Google Scholar for publications"
system "ruby -I _rubyscholarrepo/lib/ ./_rubyscholarrepo/bin/rubyscholar --config _rubyscholarconfig.yaml --output _includes/publications.html"
puts "##Scraping Done."
end
## Building ###
desc "Build the site to _site"
task :build => [ :setlocale, :scrape] do
puts "##Building now."
system "jekyll build"
end
desc "ReBuild the site to _site without rescraping"
task :rebuild => [ :setlocale] do
puts "##Building now."
system "jekyll build"
end
### Previewing ###
desc "Scrape, build and preview the site"
task :preview => [ :setlocale, :build] do
system "jekyll serve --watch"
end
task :default => :start
desc "Remove accents and funky chars if needed."
task :translit do
puts "## Transliterating from utf-8 to ascii"
system "find . -type f -name '*.markdown' -print -exec iconv -f utf-8 -t ascii//translit {} -o {} \\;"
system "find . -type f -name '*.html' -print -exec iconv -f utf-8 -t ascii//translit {} -o {} \\;"
system "find . -type f -name '*.md' -print -exec iconv -f utf-8 -t ascii//translit {} -o {} \\;"
puts "## Transliterating Done."
end
task :setlocale do
puts "## Setting locale to en_US.UTF-8"
system "LANG=\"en_US.UTF-8\""
system "LC_ALL=\"en_US.UTF-8\""
puts "## Locale set to en_US.UTF-8."
end
task :uploadToPoulet do
system "lftp -e 'mirror --ignore-time -R _site/ /httpdocs' -u yannick taho.p4x.net"
end
task :validate_website do
require 'anemone'
Anemone.crawl("http://wurmlab.github.io/") do |anemone|
anemone.on_every_page do |page|
next unless page.headers['content-type'][0] =~ %r{text/html}
next if page.code == 301 # skip permenently redirected urls
puts "#### #{page.code} => #{page.url}\n"
if page.code == 200
require 'open-uri'
require 'html_validation'
h = PageValidations::HTMLValidation.new
v = h.validation(open(page.url.to_s).read, 'Wurmlab')
puts "# HTML Validation: #{v.valid?}"
puts v.exceptions unless v.valid?
end
puts "\n\n"
end
end
end