forked from ScPo-CompEcon/CoursePack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
98 lines (80 loc) · 3.02 KB
/
Copy pathRakefile
File metadata and controls
98 lines (80 loc) · 3.02 KB
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
require 'fileutils'
Dir.chdir "Notebooks"
SOURCE_FILES = Rake::FileList.new("*.ipynb")
# puts SOURCE_FILES
task :default => :all
task :all => [:html, :pdf]
task :clean => [:clean_md,:clean_slides,:clean_html,:clean_pdf]
task :html => SOURCE_FILES.ext("html")
task :slides => SOURCE_FILES.ext("slides.html")
task :pdf => SOURCE_FILES.ext("pdf")
task :md => SOURCE_FILES.ext("md")
# task :offline => :slides
task :clean_md do
sh "rm -rf *.md"
sh "rm -rf ../Markdown/*.md"
end
task :clean_html do
sh "rm -rf *.html"
sh "rm -rf ../Html/*.html"
sh "rm -rf ../index.html"
end
task :clean_slides do
sh "rm -rf *.slides.html"
sh "rm -rf ../Slides/*.html"
end
task :clean_pdf do
sh "rm -rf *.pdf"
sh "rm -rf ../Pdfs/*.pdf"
end
task :offline => :slides do
Dir.chdir "../OfflineSlides"
# puts Dir.pwd
puts "substituting all https libs to local copies"
sh "find ./ -type f -exec sed -i '' s,https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js,require.js/require.js, {} +;"
sh "find ./ -type f -exec sed -i '' s,https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js,jquery.js/jquery.js, {} +;"
# sh "find ./ -type f -exec sed -i '' s#https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML#MathJax.js/Mathjax.js?config=TeX-AMS_HTML# {} +;"
sh "find ./ -type f -exec sed -i '' s,//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.css,font-awesome-4.7.0/css/font-awesome.css, {} +;"
# change reveal.js theme to x
sh "find ./ -type f -exec sed -i '' s,reveal.js/css/theme/simple.css,reveal.js/css/theme/solarized.css, {} +;"
Dir.chdir "../Notebooks"
end
rule ".html" => ".ipynb" do |t|
sh "jupyter-nbconvert --to html #{t.source}"
if "#{t.name}" == "Index.html"
FileUtils.mv("#{t.name}", "../index.html")
else
FileUtils.mv("#{t.name}", "../Html/#{t.name}")
end
end
# special rule for .slides.html file ending!
rule( /\.slides\.html$/ => [
proc {|task_name| task_name.sub(/\.slides\.html$/, '.ipynb') }
]) do |t|
sh "jupyter-nbconvert --to slides #{t.source} --reveal-prefix=reveal.js"
# sh "jupyter-nbconvert --to slides #{t.source} "
FileUtils.cp("#{t.name}", File.join("..","Slides",File.basename("#{t.name}",".slides.html")+".html"))
FileUtils.cp("#{t.name}", File.join("..","OfflineSlides",File.basename("#{t.name}",".slides.html")+".html"))
Dir.chdir "../Slides"
# sh "find ./ -type f -exec sed -i '' s,reveal.js/css/theme/simple.css,reveal.js/css/theme/solarized.css, {} +;"
Dir.chdir "../Notebooks"
sh "rm -rf #{t.name}"
end
rule ".pdf" => ".ipynb" do |t|
sh "jupyter-nbconvert --to pdf #{t.source}"
FileUtils.mv("#{t.name}", "../Pdfs/#{t.name}")
end
rule ".md" => ".ipynb" do |t|
sh "jupyter-nbconvert --to markdown #{t.source}"
FileUtils.mv("#{t.name}", "../Markdown/#{t.name}")
end
# task :publish => :build do
# puts "publishing repo to github"
# end
# task :slides do
# puts "Making Slides from Notebooks"
# Rake::FileList['*.ipynb'].each
# end
# task :build => [:slides, :pdf, :markdown, :html] do
# puts "Build entire CoursePack: Slides, pdf, Markdown and Html"
# end