dimples 6.1.0 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dimples.rb +7 -3
- data/lib/dimples/archive.rb +64 -0
- data/lib/dimples/feed.rb +14 -0
- data/lib/dimples/pager.rb +25 -0
- data/lib/dimples/site.rb +72 -120
- data/lib/dimples/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6afbd71e5416934a021d53ad883b21c5b3e7d919
|
4
|
+
data.tar.gz: 342eb97cfe1817bfb00e910582710b49c99a25fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa79976d760b83d9cb8f6125b38ffd6fd71adee6e9cbdfaae730407933e38743a19da11f5e8783af938901313f3f8ce99226f27661520af6b6357751ca5e4ead
|
7
|
+
data.tar.gz: 2e3df64946baed2bdf1a8837f25ee0f709c00a0f0f3b9d8e972964d4957a34c7e60570a2d591fddd2ebc211980edc175cb7d63ac1d62ec6cc955a3e85e29ac16
|
data/lib/dimples.rb
CHANGED
@@ -8,12 +8,16 @@ require 'yaml'
|
|
8
8
|
|
9
9
|
require 'dimples/frontable'
|
10
10
|
|
11
|
+
require 'dimples/archive'
|
11
12
|
require 'dimples/category'
|
12
13
|
require 'dimples/configuration'
|
13
14
|
require 'dimples/errors'
|
14
|
-
require 'dimples/page'
|
15
15
|
require 'dimples/pager'
|
16
|
-
require 'dimples/post'
|
17
16
|
require 'dimples/renderer'
|
18
|
-
|
17
|
+
|
18
|
+
require 'dimples/page'
|
19
|
+
require 'dimples/feed'
|
20
|
+
require 'dimples/post'
|
19
21
|
require 'dimples/template'
|
22
|
+
|
23
|
+
require 'dimples/site'
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dimples
|
4
|
+
# A collection of posts, organised by date.
|
5
|
+
class Archive
|
6
|
+
def initialize
|
7
|
+
@years = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_post(post)
|
11
|
+
year(post.year)[:posts] << post
|
12
|
+
month(post.year, post.month)[:posts] << post
|
13
|
+
day(post.year, post.month, post.day)[:posts] << post
|
14
|
+
end
|
15
|
+
|
16
|
+
def years
|
17
|
+
@years.keys
|
18
|
+
end
|
19
|
+
|
20
|
+
def months(year)
|
21
|
+
year(year)[:months].keys
|
22
|
+
end
|
23
|
+
|
24
|
+
def days(year, month)
|
25
|
+
month(year, month)[:days].keys
|
26
|
+
end
|
27
|
+
|
28
|
+
def posts_for_date(year, month = nil, day = nil)
|
29
|
+
if day
|
30
|
+
day_posts(year, month, day)
|
31
|
+
elsif month
|
32
|
+
month_posts(year, month)
|
33
|
+
else
|
34
|
+
year_posts(year)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def year_posts(year)
|
39
|
+
year(year)[:posts]
|
40
|
+
end
|
41
|
+
|
42
|
+
def month_posts(year, month)
|
43
|
+
month(year, month)[:posts]
|
44
|
+
end
|
45
|
+
|
46
|
+
def day_posts(year, month, day)
|
47
|
+
day(year, month, day)[:posts]
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def year(year)
|
53
|
+
@years[year.to_s] ||= { months: {}, posts: [] }
|
54
|
+
end
|
55
|
+
|
56
|
+
def month(year, month)
|
57
|
+
year(year)[:months][month.to_s] ||= { days: {}, posts: [] }
|
58
|
+
end
|
59
|
+
|
60
|
+
def day(year, month, day)
|
61
|
+
month(year, month)[:days][day.to_s] ||= { posts: [] }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/dimples/feed.rb
ADDED
data/lib/dimples/pager.rb
CHANGED
@@ -13,6 +13,31 @@ module Dimples
|
|
13
13
|
attr_reader :page_count
|
14
14
|
attr_reader :item_count
|
15
15
|
|
16
|
+
def self.paginate(site, posts, path, layout, context = {})
|
17
|
+
pager = Pager.new(
|
18
|
+
path.sub(site.paths[:destination], '') + '/',
|
19
|
+
posts,
|
20
|
+
site.config.pagination
|
21
|
+
)
|
22
|
+
|
23
|
+
pager.each do |index|
|
24
|
+
page = Page.new(site)
|
25
|
+
page.layout = layout
|
26
|
+
|
27
|
+
page_prefix = site.config.pagination.page_prefix
|
28
|
+
page_path = if index == 1
|
29
|
+
path
|
30
|
+
else
|
31
|
+
File.join(path, "#{page_prefix}#{index}")
|
32
|
+
end
|
33
|
+
|
34
|
+
page.write(
|
35
|
+
page_path,
|
36
|
+
context.merge(pagination: pager.to_context)
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
16
41
|
def initialize(url, posts, options = {})
|
17
42
|
@url = url
|
18
43
|
@posts = posts
|
data/lib/dimples/site.rb
CHANGED
@@ -9,7 +9,7 @@ module Dimples
|
|
9
9
|
attr_reader :paths
|
10
10
|
attr_reader :posts
|
11
11
|
attr_reader :pages
|
12
|
-
attr_reader :
|
12
|
+
attr_reader :archive
|
13
13
|
attr_reader :templates
|
14
14
|
attr_reader :latest_post
|
15
15
|
|
@@ -57,7 +57,7 @@ module Dimples
|
|
57
57
|
private
|
58
58
|
|
59
59
|
def prepare
|
60
|
-
@
|
60
|
+
@archive = Dimples::Archive.new
|
61
61
|
|
62
62
|
@categories = {}
|
63
63
|
@templates = {}
|
@@ -69,11 +69,14 @@ module Dimples
|
|
69
69
|
@latest_post = nil
|
70
70
|
end
|
71
71
|
|
72
|
+
def read_files(path)
|
73
|
+
Dir.glob(File.join(path, '**', '*.*')).sort
|
74
|
+
end
|
75
|
+
|
72
76
|
def read_templates
|
73
77
|
@templates = {}
|
74
|
-
template_glob = File.join(@paths[:templates], '**', '*.*')
|
75
78
|
|
76
|
-
|
79
|
+
read_files(@paths[:templates]).each do |path|
|
77
80
|
basename = File.basename(path, File.extname(path))
|
78
81
|
dir_name = File.dirname(path)
|
79
82
|
|
@@ -86,11 +89,9 @@ module Dimples
|
|
86
89
|
end
|
87
90
|
|
88
91
|
def read_posts
|
89
|
-
|
90
|
-
|
91
|
-
@posts = Dir.glob(post_glob).sort.map do |path|
|
92
|
+
@posts = read_files(@paths[:posts]).map do |path|
|
92
93
|
Post.new(self, path).tap do |post|
|
93
|
-
|
94
|
+
@archive.add_post(post)
|
94
95
|
categorise_post(post)
|
95
96
|
end
|
96
97
|
end.reverse
|
@@ -99,14 +100,7 @@ module Dimples
|
|
99
100
|
end
|
100
101
|
|
101
102
|
def read_pages
|
102
|
-
|
103
|
-
@pages = Dir.glob(page_glob).sort.map { |path| Page.new(self, path) }
|
104
|
-
end
|
105
|
-
|
106
|
-
def add_archive_post(post)
|
107
|
-
archive_year(post.year)[:posts] << post
|
108
|
-
archive_month(post.year, post.month)[:posts] << post
|
109
|
-
archive_day(post.year, post.month, post.day)[:posts] << post
|
103
|
+
@pages = read_files(@paths[:pages]).map { |path| Page.new(self, path) }
|
110
104
|
end
|
111
105
|
|
112
106
|
def categorise_post(post)
|
@@ -137,15 +131,7 @@ module Dimples
|
|
137
131
|
end
|
138
132
|
|
139
133
|
def publish_posts
|
140
|
-
@posts.each
|
141
|
-
path = File.join(
|
142
|
-
@paths[:destination],
|
143
|
-
post.date.strftime(@config.paths.posts),
|
144
|
-
post.slug
|
145
|
-
)
|
146
|
-
|
147
|
-
post.write(path)
|
148
|
-
end
|
134
|
+
@posts.each { |post| publish_post(post) }
|
149
135
|
|
150
136
|
if @config.generation.main_feed
|
151
137
|
publish_feeds(@posts, @paths[:destination])
|
@@ -153,45 +139,58 @@ module Dimples
|
|
153
139
|
|
154
140
|
return unless @config.generation.paginated_posts
|
155
141
|
|
156
|
-
|
142
|
+
Dimples::Pager.paginate(
|
143
|
+
self,
|
157
144
|
@posts,
|
158
145
|
File.join(@paths[:destination], @config.paths.paginated_posts),
|
159
146
|
@config.layouts.paginated_post
|
160
147
|
)
|
161
148
|
end
|
162
149
|
|
150
|
+
def publish_post(post)
|
151
|
+
path = File.join(
|
152
|
+
@paths[:destination],
|
153
|
+
post.date.strftime(@config.paths.posts),
|
154
|
+
post.slug
|
155
|
+
)
|
156
|
+
|
157
|
+
post.write(path)
|
158
|
+
end
|
159
|
+
|
163
160
|
def publish_pages
|
164
|
-
@pages.each
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
161
|
+
@pages.each { |page| publish_page(page) }
|
162
|
+
end
|
163
|
+
|
164
|
+
def publish_page(page)
|
165
|
+
path = if page.path
|
166
|
+
File.dirname(page.path).sub(
|
167
|
+
@paths[:pages],
|
171
168
|
@paths[:destination]
|
172
|
-
|
169
|
+
)
|
170
|
+
else
|
171
|
+
@paths[:destination]
|
172
|
+
end
|
173
173
|
|
174
|
-
|
175
|
-
end
|
174
|
+
page.write(path)
|
176
175
|
end
|
177
176
|
|
178
177
|
def publish_archives
|
179
|
-
@
|
180
|
-
|
178
|
+
@archive.years.each do |year|
|
179
|
+
publish_archive(year)
|
181
180
|
next unless @config.generation.month_archives
|
182
181
|
|
183
|
-
|
184
|
-
|
182
|
+
@archive.months(year).each do |month|
|
183
|
+
publish_archive(year, month)
|
185
184
|
next unless @config.generation.day_archives
|
186
185
|
|
187
|
-
|
188
|
-
|
186
|
+
@archive.days(year, month).each do |day|
|
187
|
+
publish_archive(year, month, day)
|
189
188
|
end
|
190
189
|
end
|
191
190
|
end
|
192
191
|
end
|
193
192
|
|
194
|
-
def
|
193
|
+
def publish_archive(year, month = nil, day = nil)
|
195
194
|
date_type = if day
|
196
195
|
'day'
|
197
196
|
elsif month
|
@@ -200,106 +199,59 @@ module Dimples
|
|
200
199
|
'year'
|
201
200
|
end
|
202
201
|
|
202
|
+
posts = @archive.posts_for_date(year, month, day)
|
203
|
+
|
203
204
|
date_parts = [year, month, day].compact
|
204
205
|
path = File.join(@paths[:destination], @config.paths.archives, date_parts)
|
206
|
+
layout = @config.layouts.date_archive
|
205
207
|
|
206
|
-
|
207
|
-
|
208
|
-
paginate_posts(
|
209
|
-
posts.reverse,
|
210
|
-
path,
|
211
|
-
@config.layouts.date_archive,
|
208
|
+
data = {
|
212
209
|
page: {
|
213
210
|
title: posts[0].date.strftime(@config.date_formats[date_type]),
|
214
211
|
archive_date: posts[0].date,
|
215
212
|
archive_type: date_type
|
216
213
|
}
|
217
|
-
|
214
|
+
}
|
215
|
+
|
216
|
+
Dimples::Pager.paginate(self, posts.reverse, path, layout, data)
|
218
217
|
end
|
219
218
|
|
220
219
|
def publish_categories
|
221
|
-
@categories.each_value
|
222
|
-
path = File.join(
|
223
|
-
@paths[:destination],
|
224
|
-
@config.paths.categories,
|
225
|
-
category.slug
|
226
|
-
)
|
227
|
-
|
228
|
-
category_posts = category.posts.reverse
|
229
|
-
context = { page: { title: category.name, category: category } }
|
230
|
-
|
231
|
-
paginate_posts(
|
232
|
-
category_posts,
|
233
|
-
path,
|
234
|
-
@config.layouts.category,
|
235
|
-
context
|
236
|
-
)
|
237
|
-
|
238
|
-
publish_feeds(category_posts, path, context)
|
239
|
-
end
|
220
|
+
@categories.each_value { |category| publish_category(category) }
|
240
221
|
end
|
241
222
|
|
242
|
-
def
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
223
|
+
def publish_category(category)
|
224
|
+
path = File.join(
|
225
|
+
@paths[:destination],
|
226
|
+
@config.paths.categories,
|
227
|
+
category.slug
|
247
228
|
)
|
248
229
|
|
249
|
-
|
250
|
-
|
251
|
-
page.layout = layout
|
252
|
-
|
253
|
-
page_prefix = @config.pagination.page_prefix
|
254
|
-
page_path = if index == 1
|
255
|
-
path
|
256
|
-
else
|
257
|
-
File.join(path, "#{page_prefix}#{index}")
|
258
|
-
end
|
259
|
-
|
260
|
-
page.write(
|
261
|
-
page_path,
|
262
|
-
context.merge(pagination: pager.to_context)
|
263
|
-
)
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
def publish_feeds(posts, path, context = {})
|
268
|
-
@config.feed_formats.each do |feed_format|
|
269
|
-
feed_layout = "feeds.#{feed_format}"
|
270
|
-
next unless @templates.key?(feed_layout)
|
271
|
-
|
272
|
-
page = Page.new(self)
|
230
|
+
category_posts = category.posts.reverse
|
231
|
+
context = { page: { title: category.name, category: category } }
|
273
232
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
233
|
+
Dimples::Pager.paginate(
|
234
|
+
self,
|
235
|
+
category_posts,
|
236
|
+
path,
|
237
|
+
@config.layouts.category,
|
238
|
+
context
|
239
|
+
)
|
278
240
|
|
279
|
-
|
280
|
-
end
|
241
|
+
publish_feeds(category_posts, path, context)
|
281
242
|
end
|
282
243
|
|
283
|
-
def
|
284
|
-
|
285
|
-
|
286
|
-
elsif month
|
287
|
-
archive_month(year, month)
|
288
|
-
else
|
289
|
-
archive_year(year)
|
244
|
+
def publish_feeds(posts, path, context = {})
|
245
|
+
@config.feed_formats.each do |format|
|
246
|
+
publish_feed(format, posts, path, context)
|
290
247
|
end
|
291
248
|
end
|
292
249
|
|
293
|
-
def
|
294
|
-
|
295
|
-
end
|
296
|
-
|
297
|
-
def archive_month(year, month)
|
298
|
-
archive_year(year)[:month][month.to_s] ||= { day: {}, posts: [] }
|
299
|
-
end
|
250
|
+
def publish_feed(format, posts, path, context = {})
|
251
|
+
feed = Feed.new(self, format)
|
300
252
|
|
301
|
-
|
302
|
-
|
253
|
+
feed.feed_posts = posts.slice(0, @config.pagination.per_page)
|
254
|
+
feed.write(path, context)
|
303
255
|
end
|
304
256
|
end
|
305
257
|
end
|
data/lib/dimples/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dimples
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Bogan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -178,9 +178,11 @@ extra_rdoc_files: []
|
|
178
178
|
files:
|
179
179
|
- bin/dimples
|
180
180
|
- lib/dimples.rb
|
181
|
+
- lib/dimples/archive.rb
|
181
182
|
- lib/dimples/category.rb
|
182
183
|
- lib/dimples/configuration.rb
|
183
184
|
- lib/dimples/errors.rb
|
185
|
+
- lib/dimples/feed.rb
|
184
186
|
- lib/dimples/frontable.rb
|
185
187
|
- lib/dimples/page.rb
|
186
188
|
- lib/dimples/pager.rb
|