jekyll-itafroma-archive 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab0d1eafe7e7202e6ade0f08785acff15d18817b
|
4
|
+
data.tar.gz: 924cacc3a7c34d321a0aa5b5f86f54bda6c76132
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55ac6cf9979f3041f4689cdd8ad16fb751758be7616de616de40c71e0010560b8af9799542ec9a081d199df4ef3b7f4a297454b4b18663e5ac824a5c01734e31
|
7
|
+
data.tar.gz: 05c833f81b8cfe010fc198e2a1220ba0e11a3876467b3b1cacae093b592dcab25e56472bc6b9dd9880da5e8d2843b7dcec144fa90218cba1d4d975f68f45914d
|
@@ -10,9 +10,16 @@
|
|
10
10
|
|
11
11
|
module Jekyll
|
12
12
|
module Itafroma
|
13
|
+
# Generator for archive listings.
|
13
14
|
class ArchiveGenerator < Generator
|
15
|
+
# This generator is safe from arbitrary code execution.
|
14
16
|
safe true
|
15
17
|
|
18
|
+
# Generate archive pages.
|
19
|
+
#
|
20
|
+
# site - The site.
|
21
|
+
#
|
22
|
+
# Returns nothing.
|
16
23
|
def generate(site)
|
17
24
|
layout = site.config['archive']['layout'] || 'archive'
|
18
25
|
if site.layouts.key? layout
|
@@ -28,14 +35,33 @@ module Jekyll
|
|
28
35
|
|
29
36
|
private
|
30
37
|
|
38
|
+
# Generate an archive page group.
|
39
|
+
#
|
40
|
+
# site - The site.
|
41
|
+
# posts - The Posts to include in the archive.
|
42
|
+
# pattern - The date pattern to collate the archive on
|
43
|
+
#
|
44
|
+
# Returns an Array of archive Pages.
|
31
45
|
def generate_archive_pages(site, posts, pattern)
|
32
46
|
pages = []
|
47
|
+
|
33
48
|
collate(posts, pattern).each do |_, collated_posts|
|
34
49
|
pages << ArchivePage.new(site, site.source, pattern, collated_posts)
|
35
50
|
end
|
51
|
+
|
52
|
+
pages.each_with_index do |page, index|
|
53
|
+
page.pager = ArchivePager.new(site, index + 1, pages, pages.size)
|
54
|
+
end
|
55
|
+
|
36
56
|
pages
|
37
57
|
end
|
38
58
|
|
59
|
+
# Collate an Array of Posts by a date pattern.
|
60
|
+
#
|
61
|
+
# posts - The Posts to collate
|
62
|
+
# pattern - The date pattern to collate the Posts on
|
63
|
+
#
|
64
|
+
# Returns a collated Hash of Posts.
|
39
65
|
def collate(posts, pattern)
|
40
66
|
collated = {}
|
41
67
|
posts.each do |post|
|
@@ -12,44 +12,70 @@
|
|
12
12
|
|
13
13
|
module Jekyll
|
14
14
|
module Itafroma
|
15
|
-
##
|
16
15
|
# Represents an archive listing page.
|
17
|
-
|
18
16
|
class ArchivePage < Page
|
19
|
-
|
17
|
+
# Initalize a new ArchivePage.
|
18
|
+
#
|
19
|
+
# site - The site.
|
20
|
+
# base - The path to the site's root
|
21
|
+
# date_pattern - The pattern of the date the posts are collated on
|
22
|
+
# posts - The posts to be added to the ArchivePage.
|
23
|
+
def initialize(site, base, date_pattern, posts)
|
20
24
|
@site = site
|
25
|
+
@config = site.config['archive']
|
26
|
+
@posts = posts
|
27
|
+
|
28
|
+
@date_pattern = date_pattern
|
21
29
|
@base = base
|
22
|
-
@dir =
|
30
|
+
@dir = dir
|
23
31
|
@name = 'index.html'
|
24
|
-
@config = site.config['archive']
|
25
32
|
|
26
33
|
process(@name)
|
27
34
|
|
28
35
|
layout = @config['layout'] || 'archive'
|
29
36
|
read_yaml(File.join(base, '_layouts'), "#{layout}.html")
|
30
37
|
|
31
|
-
|
32
|
-
data['date'] = {
|
33
|
-
'value' => posts.first.date,
|
34
|
-
'pattern' => pattern,
|
35
|
-
}
|
36
|
-
data['title'] = title
|
38
|
+
populate_data!
|
37
39
|
end
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
# Generate the start date of the archive.
|
42
|
+
#
|
43
|
+
# To determine the archive's start date, the date of the first post is
|
44
|
+
# converted to a string using `@date_pattern`. Doing this will clear any
|
45
|
+
# precision beyond what's specified in `@date_pattern`.
|
46
|
+
#
|
47
|
+
# Returns a DateTime containing the archive's start date.
|
48
|
+
def date
|
49
|
+
date_string = @posts.first.date.strftime(@date_pattern)
|
50
|
+
DateTime.strptime(date_string, @date_pattern)
|
42
51
|
end
|
43
52
|
|
53
|
+
# Generate the ArchivePage title.
|
54
|
+
#
|
55
|
+
# Returns a String containing the ArchivePage title.
|
44
56
|
def title
|
45
57
|
tokenized_title = @config['title'] || 'Blog archive - :date'
|
46
|
-
date
|
47
|
-
|
48
|
-
|
58
|
+
tokenized_title.gsub(':date', date.strftime(@date_pattern))
|
59
|
+
end
|
60
|
+
|
61
|
+
# Generate the ArchivePage url.
|
62
|
+
#
|
63
|
+
# Returns a String containing the ArchivePage url.
|
64
|
+
def url
|
65
|
+
base = @config['path'] || '/'
|
66
|
+
File.join(base, date.strftime(@date_pattern), 'index.html')
|
49
67
|
end
|
50
68
|
|
51
|
-
|
52
|
-
|
69
|
+
# Add the ArchivePage-specific data to the regular Page data.
|
70
|
+
#
|
71
|
+
# Returns nothing.
|
72
|
+
def populate_data!
|
73
|
+
data.merge!('date' => date,
|
74
|
+
'title' => title,
|
75
|
+
'archive' => {
|
76
|
+
'date_pattern' => @date_pattern,
|
77
|
+
'posts' => @posts
|
78
|
+
})
|
53
79
|
end
|
54
80
|
end
|
55
81
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#
|
2
|
+
# An archive listing pager.
|
3
|
+
#
|
4
|
+
# Author:: Mark Trapp
|
5
|
+
# Copyright: Copyright (c) 2013 Mark Trapp
|
6
|
+
# License:: MIT
|
7
|
+
# Acknowledgements:: Inspired by the work done by nlindley and ilkka on Github:
|
8
|
+
# https://gist.github.com/nlindley/6409459
|
9
|
+
# https://gist.github.com/nlindley/6409441
|
10
|
+
# https://gist.github.com/ilkka/707020
|
11
|
+
# https://gist.github.com/ilkka/707909
|
12
|
+
module Jekyll
|
13
|
+
module Itafroma
|
14
|
+
# Represents the pager used for ArchivePages.
|
15
|
+
class ArchivePager < Pager
|
16
|
+
# Static: Return the pagination path of the archive page
|
17
|
+
#
|
18
|
+
# posts - The Array of the archive's Posts.
|
19
|
+
# num_page - the pagination page number
|
20
|
+
#
|
21
|
+
# Returns the pagination path as a string
|
22
|
+
def self.paginate_archive_path(posts, num_page)
|
23
|
+
return posts.first.url if num_page.nil?
|
24
|
+
return nil if num_page < 1
|
25
|
+
return nil if num_page > posts.size
|
26
|
+
posts[num_page - 1].url
|
27
|
+
end
|
28
|
+
|
29
|
+
# Initialize a new Archive Pager.
|
30
|
+
#
|
31
|
+
# site - the Jekyll::Site object
|
32
|
+
# page - The Integer page number.
|
33
|
+
# all_posts - The Array of the archive's Posts.
|
34
|
+
# num_pages - The Integer number of pages or nil if you'd like the number
|
35
|
+
# of pages calculated.
|
36
|
+
def initialize(site, page, all_posts, num_pages = nil)
|
37
|
+
super
|
38
|
+
@previous_page_path = ArchivePager.paginate_archive_path(all_posts, @previous_page)
|
39
|
+
@next_page_path = ArchivePager.paginate_archive_path(all_posts, @next_page)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2.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: 2014-02-
|
11
|
+
date: 2014-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Jekyll plugin to create a set of archive pages.
|
14
14
|
email: mark@marktrapp.com
|
@@ -19,6 +19,7 @@ files:
|
|
19
19
|
- lib/jekyll/itafroma/archive.rb
|
20
20
|
- lib/jekyll/itafroma/archive_generator.rb
|
21
21
|
- lib/jekyll/itafroma/archive_page.rb
|
22
|
+
- lib/jekyll/itafroma/archive_pager.rb
|
22
23
|
homepage: http://marktrapp.com/projects/jekyll-archive
|
23
24
|
licenses:
|
24
25
|
- MIT
|