-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.rb
81 lines (67 loc) · 1.75 KB
/
config.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
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
set :css_dir, 'stylesheets'
set :js_dir, 'javascripts'
set :images_dir, 'images'
ignore '/courses/_template*'
ignore '/courses/**/*.rb'
ignore '**/*.rb'
activate :directory_indexes
activate :livereload
activate :syntax
set(:markdown_engine, :redcarpet)
set(
:markdown,
fenced_code_blocks: true,
smartypants: true,
tables: true,
autolink: true,
gh_blockcode: true,
)
configure :build do
activate :minify_css
activate :minify_javascript
activate :relative_assets
set :relative_links, true
end
I18n.enforce_available_locales = false
helpers do
def nav_link(link_text, url, options = {})
options[:class] ||= ""
options[:class] << " active" if url.end_with?(current_page.path)
link_to(link_text, url_for(url), options)
end
def ruby_file(filename)
file(filename, 'ruby')
end
def file(relative_path, format = nil)
require 'pathname'
require 'middleman'
course_dir = Pathname.new(caller_locations(1, 1).first.path).dirname
disk_path = course_dir.join(relative_path)
url_path = relative_path
code = File.read(disk_path).strip
%{
<div class="code-filename"><a href="#{url_path}">#{relative_path}</a></div>
```#{format}
#{code}
```
}
end
def streams
published_resources.map{|page| page.data.stream }.uniq.compact
end
def course_pages(stream)
unsorted_course_pages(stream).sort_by{|page| page.data.order.to_i }
end
private
def published_resources
sitemap.resources.reject{|page| page.data.published == false }
end
def unsorted_course_pages(stream)
sitemap.resources.select do |page|
page.data.stream == stream &&
page.data.published != false &&
page.path.start_with?('courses/') &&
File.basename(page.source_file).start_with?('index')
end
end
end