jekyll-itafroma-archive 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll/itafroma/archive.rb +1 -0
- data/lib/jekyll/itafroma/archive_generator.rb +48 -19
- data/lib/jekyll/itafroma/archive_page.rb +13 -16
- metadata +29 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80c55e7cff0aca89064cc7d9da5c9c43deb346bb
|
4
|
+
data.tar.gz: 58160aa10a21f01d43611d5768c651999d1829f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf02a340506e699b16f41034b6a00d7a3dad51c762bd97df86abaa0754c79e8314b3c3e59815c0fa1346b0a91b6e8a8adf5edba84b00006bff0d8fff5adf38c6
|
7
|
+
data.tar.gz: 683a3360166b583128226564d92b1055d80812579fa10201158843e59d011e7e5d096308fef15ff25beaab14ae4fef1a8765ccb077d8b89c74fc294ea928dabe
|
@@ -5,7 +5,7 @@
|
|
5
5
|
# contains a post.
|
6
6
|
#
|
7
7
|
# Author:: Mark Trapp
|
8
|
-
# Copyright: Copyright (c) 2013-
|
8
|
+
# Copyright: Copyright (c) 2013-2015 Mark Trapp
|
9
9
|
# License:: MIT
|
10
10
|
|
11
11
|
module Jekyll
|
@@ -15,21 +15,51 @@ module Jekyll
|
|
15
15
|
# This generator is safe from arbitrary code execution.
|
16
16
|
safe true
|
17
17
|
|
18
|
+
DEFAULT_LAYOUT = 'archive'
|
19
|
+
DEFAULT_PATH = '/'
|
20
|
+
DEFAULT_TITLE = 'Blog archive'
|
21
|
+
DEFAULT_INCLUSIONS = {}
|
22
|
+
DEFAULT_EXCLUSIONS = {}
|
23
|
+
|
18
24
|
# Generate archive pages.
|
19
25
|
#
|
20
26
|
# site - The site.
|
21
27
|
#
|
22
28
|
# Returns nothing.
|
23
29
|
def generate(site)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
30
|
+
archives = site.config['archive'] || []
|
31
|
+
|
32
|
+
if archives.is_a? Hash
|
33
|
+
warn 'The configuration format used for Jekyll Archive Generator is deprecated. Please see README for the new format.'
|
34
|
+
archives = [archives]
|
35
|
+
end
|
36
|
+
|
37
|
+
archives.each do |archive|
|
38
|
+
layout = archive['layout'] || DEFAULT_LAYOUT
|
39
|
+
if site.layouts.key? layout
|
40
|
+
path = archive['path'] || DEFAULT_PATH
|
41
|
+
title = archive['title'] || DEFAULT_TITLE
|
42
|
+
|
43
|
+
inclusions = archive['include'] || DEFAULT_INCLUSIONS
|
44
|
+
posts = if inclusions.empty?
|
45
|
+
site.posts
|
46
|
+
else
|
47
|
+
site.posts.select do |post|
|
48
|
+
inclusions.any? do |key, inclusion|
|
49
|
+
(post[key] & inclusion).any?
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
exclusions = archive['exclude'] || DEFAULT_EXCLUSIONS
|
55
|
+
exclusions.each do |key, exclusion|
|
56
|
+
posts.reject! do |post|
|
57
|
+
(post[key] & exclusion).any?
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
site.pages += generate_archive_pages(site, posts, layout, path, title)
|
29
62
|
end
|
30
|
-
site.pages += generate_archive_pages(site, posts, '%Y/%m/%d')
|
31
|
-
site.pages += generate_archive_pages(site, posts, '%Y/%m')
|
32
|
-
site.pages += generate_archive_pages(site, posts, '%Y')
|
33
63
|
end
|
34
64
|
end
|
35
65
|
|
@@ -39,20 +69,19 @@ module Jekyll
|
|
39
69
|
#
|
40
70
|
# site - The site.
|
41
71
|
# posts - The Posts to include in the archive.
|
42
|
-
#
|
72
|
+
# layout - The layout to use for the archive page
|
73
|
+
# path - The path to use for the archive page
|
74
|
+
# title - The tokenized title to use for the archive page
|
43
75
|
#
|
44
76
|
# Returns an Array of archive Pages.
|
45
|
-
def generate_archive_pages(site, posts,
|
77
|
+
def generate_archive_pages(site, posts, layout, path, title)
|
46
78
|
pages = []
|
47
79
|
|
48
|
-
collate(posts,
|
49
|
-
pages << ArchivePage.new(site, site.source,
|
80
|
+
collate(posts, path).each do |_, collated_posts|
|
81
|
+
pages << ArchivePage.new(site, site.source, layout, path, title, collated_posts)
|
50
82
|
end
|
51
83
|
|
52
84
|
pages.each_with_index do |page, index|
|
53
|
-
# Deprecated: will be removed in 0.4.0 or later
|
54
|
-
page.pager = ArchivePager.new(site, index + 1, pages, pages.size)
|
55
|
-
|
56
85
|
page.data['archive'].merge!({'paginator' => ArchivePager.new(site, index + 1, pages, pages.size)})
|
57
86
|
end
|
58
87
|
|
@@ -62,13 +91,13 @@ module Jekyll
|
|
62
91
|
# Collate an Array of Posts by a date pattern.
|
63
92
|
#
|
64
93
|
# posts - The Posts to collate
|
65
|
-
#
|
94
|
+
# path - The path slug to collate the Posts on
|
66
95
|
#
|
67
96
|
# Returns a collated Hash of Posts.
|
68
|
-
def collate(posts,
|
97
|
+
def collate(posts, path)
|
69
98
|
collated = {}
|
70
99
|
posts.each do |post|
|
71
|
-
key = post.
|
100
|
+
key = ArchiveSubstitution.new(post).translate(path)
|
72
101
|
collated[key] ||= []
|
73
102
|
collated[key] << post
|
74
103
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# An archive listing page.
|
3
3
|
#
|
4
4
|
# Author:: Mark Trapp
|
5
|
-
# Copyright: Copyright (c) 2013-
|
5
|
+
# Copyright: Copyright (c) 2013-2015 Mark Trapp
|
6
6
|
# License:: MIT
|
7
7
|
# Acknowledgements:: Inspired by the work done by nlindley and ilkka on Github:
|
8
8
|
# https://gist.github.com/nlindley/6409459
|
@@ -18,52 +18,50 @@ module Jekyll
|
|
18
18
|
#
|
19
19
|
# site - The site.
|
20
20
|
# base - The path to the site's root
|
21
|
+
# layout - The layout to use for the archive page
|
22
|
+
# path - The path to use for the archive page
|
23
|
+
# title - The tokenized title to use for the archive page
|
21
24
|
# date_pattern - The pattern of the date the posts are collated on
|
22
25
|
# posts - The posts to be added to the ArchivePage.
|
23
|
-
def initialize(site, base,
|
26
|
+
def initialize(site, base, layout, path, title, posts)
|
24
27
|
@site = site
|
25
|
-
@config = site.config['archive']
|
26
28
|
@posts = posts
|
27
29
|
|
28
|
-
@
|
30
|
+
@layout = layout
|
31
|
+
@path = path
|
32
|
+
@title = title
|
29
33
|
@base = base
|
30
34
|
@dir = dir
|
31
35
|
@name = 'index.html'
|
32
36
|
|
33
37
|
process(@name)
|
34
38
|
|
35
|
-
|
36
|
-
read_yaml(File.join(base, '_layouts'), "#{layout}.html")
|
39
|
+
read_yaml(File.join(base, '_layouts'), "#{@layout}.html")
|
37
40
|
|
38
41
|
populate_data!
|
39
42
|
end
|
40
43
|
|
41
44
|
# Generate the start date of the archive.
|
42
45
|
#
|
43
|
-
#
|
44
|
-
# converted to a string using `@date_pattern`. Doing this will clear any
|
45
|
-
# precision beyond what's specified in `@date_pattern`.
|
46
|
+
# The date of the first post is used for the start date.
|
46
47
|
#
|
47
48
|
# Returns a DateTime containing the archive's start date.
|
48
49
|
def date
|
49
|
-
|
50
|
-
DateTime.strptime(date_string, @date_pattern)
|
50
|
+
@posts.first.date
|
51
51
|
end
|
52
52
|
|
53
53
|
# Generate the ArchivePage title.
|
54
54
|
#
|
55
55
|
# Returns a String containing the ArchivePage title.
|
56
56
|
def title
|
57
|
-
|
58
|
-
tokenized_title.gsub(':date', date.strftime(@date_pattern))
|
57
|
+
ArchiveSubstitution.new(@posts.first).translate(@title)
|
59
58
|
end
|
60
59
|
|
61
60
|
# Generate the ArchivePage url.
|
62
61
|
#
|
63
62
|
# Returns a String containing the ArchivePage url.
|
64
63
|
def url
|
65
|
-
|
66
|
-
File.join(base, date.strftime(@date_pattern), 'index.html')
|
64
|
+
File.join(ArchiveSubstitution.new(@posts.first).url(@path).to_s, 'index.html')
|
67
65
|
end
|
68
66
|
|
69
67
|
# Add the ArchivePage-specific data to the regular Page data.
|
@@ -73,7 +71,6 @@ module Jekyll
|
|
73
71
|
data.merge!('date' => date,
|
74
72
|
'title' => title,
|
75
73
|
'archive' => {
|
76
|
-
'date_pattern' => @date_pattern,
|
77
74
|
'posts' => @posts
|
78
75
|
})
|
79
76
|
end
|
metadata
CHANGED
@@ -1,16 +1,40 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-itafroma-archive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Trapp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2015-01-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
27
|
+
description: |2
|
28
|
+
Jekyll Archive Generator creates a set of archive pages for a Jekyll
|
29
|
+
website.
|
30
|
+
|
31
|
+
Oddly, Jekyll doesn't include a date-based archive for posts out of the box.
|
32
|
+
For example, if you have a permalink structure like `blog/2014/01/01/title,
|
33
|
+
URL hacking won't work because going to `blog/2014` will return 404 Page Not
|
34
|
+
Found.
|
35
|
+
|
36
|
+
Jekyll Archive Generator fixes that by generating all the necessary archive
|
37
|
+
pages for each part your blog URL structure.
|
14
38
|
email: mark@marktrapp.com
|
15
39
|
executables: []
|
16
40
|
extensions: []
|
@@ -32,7 +56,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
32
56
|
requirements:
|
33
57
|
- - ">="
|
34
58
|
- !ruby/object:Gem::Version
|
35
|
-
version:
|
59
|
+
version: 2.0.0
|
36
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
61
|
requirements:
|
38
62
|
- - ">="
|