jekyll-plugin-gkarchive 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-plugin-gkarchive/archive.rb +127 -0
- data/lib/jekyll-plugin-gkarchive/version.rb +1 -1
- data/lib/jekyll-plugin-gkarchive.rb +2 -2
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5add8bfce9b19a0c090bbc79f2abf0fcf83c012abfe1133089d788a15ba90de2
|
4
|
+
data.tar.gz: b4689ce0d7f8838f37839f5e0058ae1dd63fe284c24f1010397de29fda928f87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6d5b4221c27c6fa22d1b216e92b385b97f63f0b66a6a76b4b0ba61b3cfae050939314cd8e098eff35a8a68ef4c207e3335abc4bda5d03123a314012ba83f421
|
7
|
+
data.tar.gz: 442349071d8be55003a85393e290cd20bd516c82b7da12007a91633dee532b35f759c36edc467508ee30321ea1dd55d8c127a19d6d5a718a7cb551a2817ef150
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Archives
|
5
|
+
class Archive < Jekyll::Page
|
6
|
+
attr_accessor :posts, :type, :slug
|
7
|
+
|
8
|
+
# Attributes for Liquid templates
|
9
|
+
ATTRIBUTES_FOR_LIQUID = %w(
|
10
|
+
posts
|
11
|
+
type
|
12
|
+
title
|
13
|
+
date
|
14
|
+
name
|
15
|
+
path
|
16
|
+
url
|
17
|
+
permalink
|
18
|
+
).freeze
|
19
|
+
|
20
|
+
# Initialize a new Archive page
|
21
|
+
#
|
22
|
+
# site - The Site object.
|
23
|
+
# title - The name of the tag/category or a Hash of the year/month/day in case of date.
|
24
|
+
# e.g. { :year => 2014, :month => 08 } or "my-category" or "my-tag".
|
25
|
+
# type - The type of archive. Can be one of "year", "month", "day", "category", or "tag"
|
26
|
+
# posts - The array of posts that belong in this archive.
|
27
|
+
def initialize(site, title, type, posts)
|
28
|
+
@site = site
|
29
|
+
@posts = posts
|
30
|
+
@type = type
|
31
|
+
@title = title
|
32
|
+
@config = site.config["jekyll-archives"]
|
33
|
+
|
34
|
+
# Generate slug if tag or category
|
35
|
+
# (taken from jekyll/jekyll/features/support/env.rb)
|
36
|
+
@slug = Utils.slugify(title) if title.is_a? String
|
37
|
+
|
38
|
+
# Use ".html" for file extension and url for path
|
39
|
+
@ext = File.extname(relative_path)
|
40
|
+
@path = relative_path
|
41
|
+
@name = File.basename(relative_path, @ext)
|
42
|
+
|
43
|
+
@data = {
|
44
|
+
"layout" => layout,
|
45
|
+
}
|
46
|
+
@content = ""
|
47
|
+
end
|
48
|
+
|
49
|
+
# The template of the permalink.
|
50
|
+
#
|
51
|
+
# Returns the template String.
|
52
|
+
def template
|
53
|
+
@config["permalinks"][type]
|
54
|
+
end
|
55
|
+
|
56
|
+
# The layout to use for rendering
|
57
|
+
#
|
58
|
+
# Returns the layout as a String
|
59
|
+
def layout
|
60
|
+
if @config["layouts"] && @config["layouts"][type]
|
61
|
+
@config["layouts"][type]
|
62
|
+
else
|
63
|
+
@config["layout"]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Returns a hash of URL placeholder names (as symbols) mapping to the
|
68
|
+
# desired placeholder replacements. For details see "url.rb".
|
69
|
+
def url_placeholders
|
70
|
+
if @title.is_a? Hash
|
71
|
+
@title.merge(:type => @type)
|
72
|
+
else
|
73
|
+
{ :name => @slug, :type => @type }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# The generated relative url of this page. e.g. /about.html.
|
78
|
+
#
|
79
|
+
# Returns the String url.
|
80
|
+
def url
|
81
|
+
@url ||= URL.new({
|
82
|
+
:template => template,
|
83
|
+
:placeholders => url_placeholders,
|
84
|
+
:permalink => nil,
|
85
|
+
}).to_s
|
86
|
+
rescue ArgumentError
|
87
|
+
raise ArgumentError, "Template \"#{template}\" provided is invalid."
|
88
|
+
end
|
89
|
+
|
90
|
+
def permalink
|
91
|
+
data && data.is_a?(Hash) && data["permalink"]
|
92
|
+
end
|
93
|
+
|
94
|
+
# Produce a title object suitable for Liquid based on type of archive.
|
95
|
+
#
|
96
|
+
# Returns a String (for tag and category archives) and nil for
|
97
|
+
# date-based archives.
|
98
|
+
def title
|
99
|
+
@title if @title.is_a? String
|
100
|
+
end
|
101
|
+
|
102
|
+
# Produce a date object if a date-based archive
|
103
|
+
#
|
104
|
+
# Returns a Date.
|
105
|
+
def date
|
106
|
+
if @title.is_a? Hash
|
107
|
+
args = @title.values.map(&:to_i)
|
108
|
+
Date.new(*args)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Obtain the write path relative to the destination directory
|
113
|
+
#
|
114
|
+
# Returns the destination relative path String.
|
115
|
+
def relative_path
|
116
|
+
path = URL.unescape_path(url).gsub(%r!^\/!, "")
|
117
|
+
path = File.join(path, "index.html") if url =~ %r!\/$!
|
118
|
+
path
|
119
|
+
end
|
120
|
+
|
121
|
+
# Returns the object as a debug String.
|
122
|
+
def inspect
|
123
|
+
"#<Jekyll:Archive @type=#{@type} @title=#{@title} @data=#{@data.inspect}>"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -23,8 +23,8 @@ require "jekyll"
|
|
23
23
|
module Jekyll
|
24
24
|
module Archives
|
25
25
|
# Internal requires
|
26
|
-
|
27
|
-
|
26
|
+
autoload :Archive, "jekyll-archives/archive"
|
27
|
+
autoload :VERSION, "jekyll-plugin-gkarchive/version"
|
28
28
|
|
29
29
|
class Archives < Jekyll::Generator
|
30
30
|
safe true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-plugin-gkarchive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@glueckkanja"
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- Rakefile
|
66
66
|
- jekyll-plugin-gkarchive.gemspec
|
67
67
|
- lib/jekyll-plugin-gkarchive.rb
|
68
|
+
- lib/jekyll-plugin-gkarchive/archive.rb
|
68
69
|
- lib/jekyll-plugin-gkarchive/version.rb
|
69
70
|
- screenshot.png
|
70
71
|
homepage: https://glueckkanja.com
|