jekyll-index-pages 0.4.2 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 644663b8c4ce0860a650f8293f1795d30694ef57
4
- data.tar.gz: 39a86341f8fdbceff9fa5deaea830615c911f34e
3
+ metadata.gz: a1d9113d77e75aa8da870300ced987ad10325450
4
+ data.tar.gz: e0b2d158119e53b2a3cf79f19732b6c402e14367
5
5
  SHA512:
6
- metadata.gz: 71b7d568df6cb8aac4637e79cf14dc12015f022393e232d7e7e5760abd7f7423bcbca6b508d20c52cb062c5827130b4788759f617cf695aad05e252d3c5d9f7e
7
- data.tar.gz: 04778169628e282f12696b1523cc0cd2ad6bda00b18b73e5aee3d2e9b11e469bd858ee8655e95b43414b53d5e061f62ac5aafc134682244530bf5e7786b57638
6
+ metadata.gz: 0609577fc6a27874ea0ef5dd621ee43fcd581e0f76914033552925f95cf111d517eb8e7b7affe1d7605876c05c6ced2009b06bcd4f46b7a823ae2f351181c90a
7
+ data.tar.gz: 5adcccf910a80b6a078fab6a1e0df00c90da3a5da9dde634cdddb3f6969d038622b7409b6fc437934644016b67340672d8e6bca4c395615f34a3da59df65acb0
data/README.md CHANGED
@@ -168,20 +168,21 @@ To include the pagination, you can do the following:
168
168
  {% endif %}
169
169
  ```
170
170
 
171
- ### Linking category and tag pages
171
+ ### Linking index pages
172
172
 
173
- Sometimes you will need to link category or tag pages, for example when
174
- building some kind of navigation. For this particular use case, you can use `{%
175
- category_url %}` and `{% tag_url %}` tags for getting the correct URL to a
176
- given category or tag page.
177
-
178
- `{% category_url %}` accepts a valid category name as an argument:
173
+ Sometimes you will need to link index pages, for example when building some
174
+ kind of category navigation. For this particular use case, you can use `{%
175
+ category_url %}`, `{% tag_url %}`, `{% author_url %}` and `{% archive_url %}`
176
+ tags for getting the correct URL to a given index page.
179
177
 
180
178
  ```liquid
181
179
  <a href="{% category_url "Category name" %}">Category name</a>
180
+ <a href="{% tag_url "Tag name" %}">Tag name</a>
181
+ <a href="{% author_url "Author Name" %}">Author Name</a>
182
+ <a href="{% archive_url "2001" %}">2001</a>
182
183
  ```
183
184
 
184
- Likewise, `{% tag_url %}` receives a valid tag name.
185
+ You can pass the argument directly as a string or as a variable.
185
186
 
186
187
  The following example demonstrates how to create a basic category navigation:
187
188
 
@@ -3,9 +3,6 @@ module JekyllIndexPages
3
3
  priority :high
4
4
 
5
5
  def generate(site)
6
- config = site.config["index_pages"] || {}
7
- return if !config.key?("archive")
8
-
9
6
  archive = Hash.new { |hash, key| hash[key] = [] }
10
7
  site.posts.docs.each { |doc| archive[doc.date.strftime("%Y")] << doc }
11
8
  site.data["archive"] = archive
@@ -3,10 +3,7 @@ module JekyllIndexPages
3
3
  priority :high
4
4
 
5
5
  def generate(site)
6
- config = site.config["index_pages"] || {}
7
- return if !config.key?("authors")
8
-
9
- authors = Hash.new { |hash, key| authors[key] = [] }
6
+ authors = Hash.new { |hash, key| hash[key] = [] }
10
7
  site.posts.docs.each { |doc| authors[doc.data["author"]] << doc }
11
8
  site.data["authors"] = authors
12
9
  end
@@ -0,0 +1,14 @@
1
+ module JekyllIndexPages
2
+ class ArchiveURL < URLTag
3
+ def has_kind?(site, kind)
4
+ site.data["archive"].key?(kind)
5
+ end
6
+
7
+ def filter_config(config)
8
+ _, item = config.detect { |key, value| key == "archive" }
9
+ item
10
+ end
11
+ end
12
+ end
13
+
14
+ Liquid::Template.register_tag("archive_url", JekyllIndexPages::ArchiveURL)
@@ -0,0 +1,14 @@
1
+ module JekyllIndexPages
2
+ class AuthorURL < URLTag
3
+ def has_kind?(site, kind)
4
+ site.data["authors"].key?(kind)
5
+ end
6
+
7
+ def filter_config(config)
8
+ _, item = config.detect { |key, value| key == "authors" }
9
+ item
10
+ end
11
+ end
12
+ end
13
+
14
+ Liquid::Template.register_tag("author_url", JekyllIndexPages::AuthorURL)
@@ -1,50 +1,12 @@
1
1
  module JekyllIndexPages
2
- class CategoryURL < Liquid::Tag
3
- STRING_SYNTAX = %r{^\"[[:alnum:] ]+\"$}u
4
- VARIABLE_SYNTAX = %r{^\(?[[:alnum:]\-\.\[\]]+\)?$}u
5
-
6
- def initialize(tag, markup, tokens)
7
- super
8
- @markup = markup.strip
2
+ class CategoryURL < URLTag
3
+ def has_kind?(site, kind)
4
+ site.categories.has_key?(kind)
9
5
  end
10
6
 
11
- def render(context)
12
- input = ""
13
- if @markup.match(STRING_SYNTAX)
14
- input = @markup.gsub("\"", "")
15
- elsif @markup.match(VARIABLE_SYNTAX)
16
- input = Liquid::Variable.new(@markup).render(context)
17
- else
18
- raise ArgumentError, <<-eos
19
- Invalid syntax for category_url tag:
20
-
21
- #{@markup}
22
-
23
- Valid syntax:
24
-
25
- {% category_url "Category name" %}
26
-
27
- or
28
-
29
- {% category_url name_in_variable %}
30
-
31
- eos
32
- end
33
-
34
- site = context.registers[:site]
35
-
36
- category, _ = site.categories.detect { |key, value| key == input }
37
- return "" if !category
38
- category_slug =
39
- I18n.transliterate(
40
- Jekyll::Utils.slugify(category),
41
- :locale => I18n.locale
42
- )
43
-
44
- config = site.config["index_pages"] || {}
7
+ def filter_config(config)
45
8
  _, item = config.detect { |key, value| key == "categories" }
46
- permalink = item ? item["permalink"] : "/:label/"
47
- permalink.sub(":label", category_slug)
9
+ item
48
10
  end
49
11
  end
50
12
  end
@@ -1,50 +1,12 @@
1
1
  module JekyllIndexPages
2
- class TagURL < Liquid::Tag
3
- STRING_SYNTAX = %r{^\"[[:alnum:]\-]+\"$}u
4
- VARIABLE_SYNTAX = %r{^\(?[[:alnum:]\-\.\[\]]+\)?$}u
5
-
6
- def initialize(tag, markup, tokens)
7
- super
8
- @markup = markup.strip
2
+ class TagURL < URLTag
3
+ def has_kind?(site, kind)
4
+ site.tags.has_key?(kind)
9
5
  end
10
6
 
11
- def render(context)
12
- input = ""
13
- if @markup.match(STRING_SYNTAX)
14
- input = @markup.gsub("\"", "")
15
- elsif @markup.match(VARIABLE_SYNTAX)
16
- input = Liquid::Variable.new(@markup).render(context)
17
- else
18
- raise ArgumentError, <<-eos
19
- Invalid syntax for tag_url tag:
20
-
21
- #{@markup}
22
-
23
- Valid syntax:
24
-
25
- {% tag_url "Tag name" %}
26
-
27
- or
28
-
29
- {% tag_url name_in_variable %}
30
-
31
- eos
32
- end
33
-
34
- site = context.registers[:site]
35
-
36
- tag, _ = site.tags.detect { |key, value| key == input }
37
- return "" if !tag
38
- tag_slug =
39
- I18n.transliterate(
40
- Jekyll::Utils.slugify(tag),
41
- :locale => I18n.locale
42
- )
43
-
44
- config = site.config["index_pages"] || {}
7
+ def filter_config(config)
45
8
  _, item = config.detect { |key, value| key == "tags" }
46
- permalink = item ? item["permalink"] : "/:label/"
47
- permalink.sub(":label", tag_slug)
9
+ item
48
10
  end
49
11
  end
50
12
  end
@@ -0,0 +1,61 @@
1
+ module JekyllIndexPages
2
+ class URLTag < Liquid::Tag
3
+ STRING_SYNTAX = %r{^\"[[:alnum:]\- ]+\"$}u
4
+ VARIABLE_SYNTAX = %r{^\(?[[:alnum:]\-\.\[\]]+\)?$}u
5
+
6
+ def initialize(tag_name, markup, tokens)
7
+ super
8
+ @markup = markup.strip
9
+ @tag_name = tag_name
10
+ end
11
+
12
+ def parse_params(context)
13
+ input = ""
14
+ if @markup.match(STRING_SYNTAX)
15
+ input = @markup.gsub("\"", "")
16
+ elsif @markup.match(VARIABLE_SYNTAX)
17
+ input = Liquid::Variable.new(@markup).render(context)
18
+ else
19
+ raise ArgumentError, <<-eos
20
+ Invalid syntax for #{@tag_name} tag:
21
+
22
+ #{@markup}
23
+
24
+ Valid syntax:
25
+
26
+ {% #{@tag_name} "Name" %}
27
+
28
+ or
29
+
30
+ {% #{@tag_name} variable %}
31
+
32
+ eos
33
+ end
34
+ end
35
+
36
+ def has_kind?(site, kind)
37
+ false
38
+ end
39
+
40
+ def filter_config(config)
41
+ nil
42
+ end
43
+
44
+ def render(context)
45
+ site = context.registers[:site]
46
+ master_config = site.config["index_pages"] || {}
47
+
48
+ kind = parse_params(context)
49
+ return "" if !has_kind?(site, kind)
50
+ slug =
51
+ I18n.transliterate(
52
+ Jekyll::Utils.slugify(kind),
53
+ :locale => I18n.locale
54
+ )
55
+
56
+ config = filter_config(master_config)
57
+ permalink = config ? config["permalink"] : "/:label/"
58
+ permalink.sub(":label", slug)
59
+ end
60
+ end
61
+ end
@@ -1,3 +1,3 @@
1
1
  module JekyllIndexPages
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -6,5 +6,8 @@ require "jekyll-index-pages/collection"
6
6
  require "jekyll-index-pages/generator"
7
7
  require "jekyll-index-pages/index-page"
8
8
  require "jekyll-index-pages/pagination"
9
+ require "jekyll-index-pages/tags"
10
+ require "jekyll-index-pages/tags/archive-url"
11
+ require "jekyll-index-pages/tags/author-url"
9
12
  require "jekyll-index-pages/tags/category-url"
10
13
  require "jekyll-index-pages/tags/tag-url"
@@ -0,0 +1,95 @@
1
+ require "spec_helper"
2
+
3
+ describe JekyllIndexPages::ArchiveURL do
4
+ let(:overrides) { Hash.new }
5
+ let(:site_config) do
6
+ Jekyll.configuration(Jekyll::Utils.deep_merge_hashes({
7
+ "source" => File.expand_path("../fixtures/index-page", __FILE__),
8
+ "destination" => File.expand_path("../dest", __FILE__)
9
+ }, overrides))
10
+ end
11
+ let(:site) { Jekyll::Site.new(site_config) }
12
+ let(:payload) { site.site_payload }
13
+ let(:info) do
14
+ {
15
+ :registers => { :site => site, :page => payload["page"] }
16
+ }
17
+ end
18
+
19
+ before(:each) do
20
+ site.process
21
+ end
22
+
23
+ context "When no text is provided" do
24
+ let(:template) { Liquid::Template.parse("{% archive_url %}") }
25
+
26
+ describe "ArchiveURL.render" do
27
+ it "raises ArgumentError" do
28
+ expect { template.render!(payload, info) }.to raise_error(ArgumentError)
29
+ end
30
+ end
31
+ end
32
+
33
+ context "When a valid year is provided" do
34
+ let(:template) do
35
+ Liquid::Template.parse("{% archive_url \"1966\" %}")
36
+ end
37
+
38
+ describe "ArchiveURL.render" do
39
+ it "returns a valid archive page URL" do
40
+ expect(template.render!(payload, info)).to eq("/1966/")
41
+ end
42
+ end
43
+
44
+ context "and a custom archive permalink is provided" do
45
+ let(:overrides) do
46
+ {
47
+ "index_pages" => {
48
+ "archive" => {
49
+ "permalink" => "/custom/:label/"
50
+ }
51
+ }
52
+ }
53
+ end
54
+
55
+ describe "ArchiveURL.render" do
56
+ it "returns a valid archive page URL" do
57
+ expect(template.render!(payload, info)).to eq("/custom/1966/")
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ context "When a valid year is provided as a variable" do
64
+ let(:template) do
65
+ Liquid::Template.parse <<-eos
66
+ {% assign year = "1966" %}
67
+ {% archive_url year %}
68
+ eos
69
+ end
70
+
71
+ describe "ArchiveURL.render" do
72
+ it "returns a valid archive page URL" do
73
+ expect(template.render!(payload, info)).to eq("\n/1966/\n")
74
+ end
75
+ end
76
+
77
+ context "and a custom author permalink is provided" do
78
+ let(:overrides) do
79
+ {
80
+ "index_pages" => {
81
+ "archive" => {
82
+ "permalink" => "/custom/:label/"
83
+ }
84
+ }
85
+ }
86
+ end
87
+
88
+ describe "ArchiveURL.render" do
89
+ it "returns a valid archive page URL" do
90
+ expect(template.render!(payload, info)).to eq("\n/custom/1966/\n")
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
data/spec/archive_spec.rb CHANGED
@@ -14,35 +14,17 @@ describe(JekyllIndexPages::Archive) do
14
14
  site.process
15
15
  end
16
16
 
17
- context("When no configuration is provided") do
18
- describe("Archive.generate") do
19
- it("skips archive generation") do
20
- expect(site.data["archive"]).to be_nil
21
- end
17
+ describe("Archive.generate") do
18
+ it("generates a five year post archive") do
19
+ expect(site.data["archive"].length).to eq(5)
22
20
  end
23
- end
24
-
25
- context("When default configuration for archive index pages is provided") do
26
- let(:overrides) do
27
- {
28
- "index_pages" => {
29
- "archive" => {}
30
- }
31
- }
32
- end
33
-
34
- describe("Archive.generate") do
35
- it("generates a five year post archive") do
36
- expect(site.data["archive"].length).to eq(5)
37
- end
38
21
 
39
- it("generates a post listing page per year") do
40
- expect(site.data["archive"]["1966"].length).to be > 0
41
- expect(site.data["archive"]["1987"].length).to be > 0
42
- expect(site.data["archive"]["1993"].length).to be > 0
43
- expect(site.data["archive"]["1995"].length).to be > 0
44
- expect(site.data["archive"]["2001"].length).to be > 0
45
- end
22
+ it("generates a post listing page per year") do
23
+ expect(site.data["archive"]["1966"].length).to be > 0
24
+ expect(site.data["archive"]["1987"].length).to be > 0
25
+ expect(site.data["archive"]["1993"].length).to be > 0
26
+ expect(site.data["archive"]["1995"].length).to be > 0
27
+ expect(site.data["archive"]["2001"].length).to be > 0
46
28
  end
47
29
  end
48
30
  end
@@ -0,0 +1,120 @@
1
+ require "spec_helper"
2
+
3
+ describe JekyllIndexPages::AuthorURL do
4
+ let(:overrides) { Hash.new }
5
+ let(:site_config) do
6
+ Jekyll.configuration(Jekyll::Utils.deep_merge_hashes({
7
+ "source" => File.expand_path("../fixtures/index-page", __FILE__),
8
+ "destination" => File.expand_path("../dest", __FILE__)
9
+ }, overrides))
10
+ end
11
+ let(:site) { Jekyll::Site.new(site_config) }
12
+ let(:payload) { site.site_payload }
13
+ let(:info) do
14
+ {
15
+ :registers => { :site => site, :page => payload["page"] }
16
+ }
17
+ end
18
+
19
+ before(:each) do
20
+ site.process
21
+ end
22
+
23
+ context "When no text is provided" do
24
+ let(:template) { Liquid::Template.parse("{% author_url %}") }
25
+
26
+ describe "AuthorURL.render" do
27
+ it "raises ArgumentError" do
28
+ expect { template.render!(payload, info) }.to raise_error(ArgumentError)
29
+ end
30
+ end
31
+ end
32
+
33
+ context "When a valid author name is provided" do
34
+ let(:template) do
35
+ Liquid::Template.parse("{% author_url \"James T Kirk\" %}")
36
+ end
37
+
38
+ describe "AuthorURL.render" do
39
+ it "returns a valid author page URL" do
40
+ expect(template.render!(payload, info)).to eq("/james-t-kirk/")
41
+ end
42
+ end
43
+
44
+ context "and a custom author permalink is provided" do
45
+ let(:overrides) do
46
+ {
47
+ "index_pages" => {
48
+ "authors" => {
49
+ "permalink" => "/custom/:label/"
50
+ }
51
+ }
52
+ }
53
+ end
54
+
55
+ describe "AuthorURL.render" do
56
+ it "returns a valid author page URL" do
57
+ expect(template.render!(payload, info)).to eq("/custom/james-t-kirk/")
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ context "When valid author names are provided as a variable" do
64
+ let(:template) do
65
+ Liquid::Template.parse <<-eos
66
+ {% for author in site.data.authors %}
67
+ {% author_url author[0] %}
68
+ {% endfor %}
69
+ eos
70
+ end
71
+
72
+ describe "AuthorURL.render" do
73
+ it "returns valid author page URLs" do
74
+ expect(template.render!(payload, info)).to eq <<-eos
75
+
76
+ /james-t-kirk/
77
+
78
+ /jean-luc-picard/
79
+
80
+ /benjamin-sisko/
81
+
82
+ /kathryn-janeway/
83
+
84
+ /jonathan-archer/
85
+
86
+ eos
87
+ end
88
+ end
89
+
90
+ context "and a custom author permalink is provided" do
91
+ let(:overrides) do
92
+ {
93
+ "index_pages" => {
94
+ "authors" => {
95
+ "permalink" => "/custom/:label/"
96
+ }
97
+ }
98
+ }
99
+ end
100
+
101
+ describe "AuthorURL.render" do
102
+ it "returns valid author page URLs" do
103
+ expect(template.render!(payload, info)).to eq <<-eos
104
+
105
+ /custom/james-t-kirk/
106
+
107
+ /custom/jean-luc-picard/
108
+
109
+ /custom/benjamin-sisko/
110
+
111
+ /custom/kathryn-janeway/
112
+
113
+ /custom/jonathan-archer/
114
+
115
+ eos
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
data/spec/author_spec.rb CHANGED
@@ -14,35 +14,17 @@ describe(JekyllIndexPages::Author) do
14
14
  site.process
15
15
  end
16
16
 
17
- context("When no configuration is provided") do
18
- describe("Author.generate") do
19
- it("skips author index page generation") do
20
- expect(site.data["author"]).to be_nil
21
- end
17
+ describe("Author.generate") do
18
+ it("generates five author index pages") do
19
+ expect(site.data["authors"].length).to eq(5)
22
20
  end
23
- end
24
-
25
- context("When default configuration is provided") do
26
- let(:overrides) do
27
- {
28
- "index_pages" => {
29
- "authors" => {}
30
- }
31
- }
32
- end
33
-
34
- describe("Author.generate") do
35
- it("generates five author index pages") do
36
- expect(site.data["authors"].length).to eq(5)
37
- end
38
21
 
39
- it("generates a post listing page per author") do
40
- expect(site.data["authors"]["James T Kirk"].length).to be > 0
41
- expect(site.data["authors"]["Jean-Luc Picard"].length).to be > 0
42
- expect(site.data["authors"]["Benjamin Sisko"].length).to be > 0
43
- expect(site.data["authors"]["Kathryn Janeway"].length).to be > 0
44
- expect(site.data["authors"]["Jonathan Archer"].length).to be > 0
45
- end
22
+ it("generates a post listing page per author") do
23
+ expect(site.data["authors"]["James T Kirk"].length).to be > 0
24
+ expect(site.data["authors"]["Jean-Luc Picard"].length).to be > 0
25
+ expect(site.data["authors"]["Benjamin Sisko"].length).to be > 0
26
+ expect(site.data["authors"]["Kathryn Janeway"].length).to be > 0
27
+ expect(site.data["authors"]["Jonathan Archer"].length).to be > 0
46
28
  end
47
29
  end
48
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-index-pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Miguel Venegas Mendoza
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-19 00:00:00.000000000 Z
11
+ date: 2017-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -105,12 +105,17 @@ files:
105
105
  - lib/jekyll-index-pages/generator.rb
106
106
  - lib/jekyll-index-pages/index-page.rb
107
107
  - lib/jekyll-index-pages/pagination.rb
108
+ - lib/jekyll-index-pages/tags.rb
109
+ - lib/jekyll-index-pages/tags/archive-url.rb
110
+ - lib/jekyll-index-pages/tags/author-url.rb
108
111
  - lib/jekyll-index-pages/tags/category-url.rb
109
112
  - lib/jekyll-index-pages/tags/tag-url.rb
110
113
  - lib/jekyll-index-pages/version.rb
111
114
  - script/console
112
115
  - script/setup
116
+ - spec/archive-url_spec.rb
113
117
  - spec/archive_spec.rb
118
+ - spec/author-url_spec.rb
114
119
  - spec/author_spec.rb
115
120
  - spec/category-url_spec.rb
116
121
  - spec/collection_spec.rb
@@ -163,7 +168,9 @@ signing_key:
163
168
  specification_version: 4
164
169
  summary: Index page generator for Jekyll sites.
165
170
  test_files:
171
+ - spec/archive-url_spec.rb
166
172
  - spec/archive_spec.rb
173
+ - spec/author-url_spec.rb
167
174
  - spec/author_spec.rb
168
175
  - spec/category-url_spec.rb
169
176
  - spec/collection_spec.rb