-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.rb
183 lines (148 loc) · 4.33 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
###
# Helpers
###
activate :dotenv
# Automatic image dimensions on image_tag helper
activate :automatic_image_sizes
activate :directory_indexes
# Methods defined in the helpers block are available in templates
helpers do
def gravatar_for(email, size=120)
hash = Digest::MD5.hexdigest(email.chomp.downcase)
"https://www.gravatar.com/avatar/#{hash}?s=#{size}"
end
def nav_active(page)
return if current_page.data.body_class.blank?
'active' if current_page.data.body_class.split(' ').include? page
end
def tag_list(tags)
if tags.count
tags.map{ |tag| link_to(tag, blog_url_for(tag_path(tag))) }.join(', ')
else
"Post not tagged"
end
end
def web_url_for(url)
if environment == :build
"#{web_url}#{url}"
else
url
end
end
def blog_url_for(url)
if environment == :build
url.sub(/^\/blog/, blog_url)
else
url
end
end
def stars_and_forks_count(repository)
c = Curl::Easy.new("https://api.github.com/repos/#{repository}?client_id=#{ENV['GITHUB_CLIENT_ID']}&client_secret=#{ENV['GITHUB_CLIENT_SECRET']}") do |curl|
curl.headers["User-Agent"] = "diacode-website"
end
c.perform
res = JSON.parse c.body_str
{
stars_count: res['stargazers_count'],
forks_count: res['forks_count']
}
rescue
{
stars_count: 0,
forks_count: 0
}
end
end
# Use LiveReload
activate :livereload
# Sass base
activate :bourbon
activate :neat
# Compass configuration
set :css_dir, 'stylesheets'
set :js_dir, 'javascripts'
set :images_dir, 'images'
set :markdown_engine, :redcarpet
set :markdown, tables: true, autolink: true, gh_blockcode: false, fenced_code_blocks: true, with_toc_data: false, disable_indented_code_blocks: false
set :haml, format: :html5, ugly: true
# Production settings
set :web_url, 'https://diacode.com'
set :blog_url, 'https://blog.diacode.com'
###
# Blog settings
###
# Time.zone = "UTC"
activate :blog do |blog|
blog.prefix = "blog"
# blog.permalink = ":year/:month/:day/:title.html"
blog.permalink = ":title"
# blog.sources = ":year-:month-:day-:title.html"
blog.taglink = "tags/:tag.html"
blog.layout = "layout"
# blog.summary_separator = /(READMORE)/
# blog.summary_length = 250
# blog.year_link = ":year.html"
# blog.month_link = ":year/:month.html"
# blog.day_link = ":year/:month/:day.html"
# blog.default_extension = ".markdown"
blog.tag_template = "/blog/tag.html"
# blog.calendar_template = "calendar.html"
blog.paginate = true
blog.per_page = 10
# blog.page_link = "page/:num"
# Custom summary generator. First it checks the excerpt and if it isn't present
# it summarize the content by getting the first paragraph
require 'middleman-blog/truncate_html'
blog.summary_generator = Proc.new do |article|
if article.data.excerpt
article.data.excerpt
else
doc = Nokogiri::HTML(article.body)
paragraphs = doc.xpath('//p')
first_paragrah = paragraphs.first
TruncateHTML.truncate_html(first_paragrah.content, 140, " ...")
end
end
end
ready do
blog.tags.each do |tag, articles|
page "/blog/tags/#{tag.downcase.tr(' ', '_')}/feed.xml", proxy: "/blog/feed.xml", layout: false do
@tagname = tag
@articles = articles[0..15]
end
end
end
page '/blog/*', layout: 'blog'
page "/feed.xml", layout: false
# Build-specific configuration
configure :build do
ignore 'images/*.psd'
ignore 'stylesheets/lib/*'
ignore 'stylesheets/vendor/*'
ignore 'javascripts/lib/*'
ignore 'javascripts/vendor/*'
# For example, change the Compass output style for deployment
activate :minify_css
# Minify Javascript on build
activate :minify_javascript
# Enable cache buster
activate :cache_buster
# Use relative URLs
activate :relative_assets
# activate :minify_html
# Compress PNGs after build
# First: gem install middleman-smusher
require "middleman-smusher"
activate :smusher
# Or use a different image path
# set :http_path, "/Content/images/"
end
activate :deploy do |deploy|
deploy.method = :rsync
deploy.host = 'diacode.com'
deploy.path = '/var/www/diacode.com'
deploy.build_before = true
deploy.clean = true # remove orphaned files on remote host, default: false
deploy.user = 'deployer'
deploy.flags = '-avz --chmod=Du=rwx,Dg=rxs,Fu=rw,Fg=r'
end