forked from UCL/research-computing-with-cpp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathliquify.rb
54 lines (41 loc) · 912 Bytes
/
liquify.rb
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
inpath = ARGV[0]
require 'rubygems'
require 'liquid'
require 'yaml'
require_relative '_plugins/idio'
require_relative '_plugins/figurepath'
require 'ostruct'
# Liquid::Template.error_mode = :strict Removed for older liquid compatibility
content = File.read(inpath)
if ARGV[1] == "slides"
slides = true
latex = false
else
slides = false
latex = true
end
front = YAML.load(content[/\A---(.|\n)*?---/])
if latex
content.gsub!(/\A---(.|\n)*?---/,'')
if inpath.include?("index.md")
content="\n\n# #{front["title"]}\n" + content
end
end
@template = Liquid::Template.parse(content)
site = OpenStruct.new
site.config={
"idio" => {
"fence" => true
},
"absolute_figures" => latex,
"latex" => latex
}
page = {
"path" => inpath
}
registers = {
:site => site,
:page => page
}
context = Liquid::Context.new({}, {"site"=>site.config}, registers)
print @template.render(context)