jekyll-index-pages 0.3.3 → 0.4.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/README.md +21 -1
- data/lib/jekyll-index-pages/tags/category-url.rb +35 -0
- data/lib/jekyll-index-pages/tags/tag-url.rb +35 -0
- data/lib/jekyll-index-pages/version.rb +1 -1
- data/lib/jekyll-index-pages.rb +4 -5
- data/spec/category-url_spec.rb +62 -0
- data/spec/fixtures/index-page/_posts/1966-09-08-viaje-a-las-estrellas-la-serie-original.md +1 -1
- data/spec/generator_spec.rb +2 -2
- data/spec/tag-url_spec.rb +62 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 434e6a42ab53e8200e65e037b6984b6693eb05bc
|
4
|
+
data.tar.gz: c022b58acba4625785ca9a81d20e8fa67add484f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d44e8f13335e1274a05a8333a153e2e07a878e5cbb926f67c9782e2518280f451b3a50294929f27dd1bdfc38e9c2b5fba3ef7b7a800a17e892d5fe770be039de
|
7
|
+
data.tar.gz: d612fc1f00c25007a98a4116da3ffa9f4f50e20136097260dfbe7aeb3e7bc87e8e0c610067db0ee1b1abc33a808bfc7d4037f5c69840088d4ad2523e418eaf6d
|
data/README.md
CHANGED
@@ -123,7 +123,7 @@ custom_name:
|
|
123
123
|
...
|
124
124
|
```
|
125
125
|
|
126
|
-
|
126
|
+
Because this plugin [transliterates](http://stackoverflow.com/a/20586777) the
|
127
127
|
URL for generated pages, you need to define a language as follows:
|
128
128
|
|
129
129
|
```yaml
|
@@ -168,6 +168,26 @@ To include the pagination, you can do the following:
|
|
168
168
|
{% endif %}
|
169
169
|
```
|
170
170
|
|
171
|
+
### Linking category and tag pages
|
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. Likewise,
|
179
|
+
`{% tag_url %}` receives a valid tag name.
|
180
|
+
|
181
|
+
The following example demonstrates how to create a basic category navigation:
|
182
|
+
|
183
|
+
```liquid
|
184
|
+
<ul>
|
185
|
+
{% for category in site.categories %}
|
186
|
+
<li><a href="{% category_url category[0] %}">{{ category[0] }}</a></li>
|
187
|
+
{% endfor%}
|
188
|
+
</ul>
|
189
|
+
```
|
190
|
+
|
171
191
|
## Development
|
172
192
|
|
173
193
|
After checking out the repo, run `script/setup` to install dependencies. Then,
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module JekyllIndexPages
|
2
|
+
class CategoryURL < Liquid::Tag
|
3
|
+
def initialize(tag, text, tokens)
|
4
|
+
super
|
5
|
+
@text = text.strip
|
6
|
+
end
|
7
|
+
|
8
|
+
def render(context)
|
9
|
+
site = context.registers[:site]
|
10
|
+
|
11
|
+
config = site.config["index_pages"] || {}
|
12
|
+
_, item = config.detect do |key, value|
|
13
|
+
key == "categories"
|
14
|
+
end
|
15
|
+
|
16
|
+
permalink = item ? item["permalink"] : "/:label/"
|
17
|
+
category, _ = site.categories.detect do |key, value|
|
18
|
+
key == @text
|
19
|
+
end
|
20
|
+
|
21
|
+
if category
|
22
|
+
category_slug =
|
23
|
+
I18n.transliterate(
|
24
|
+
Jekyll::Utils.slugify(category),
|
25
|
+
:locale => I18n.locale
|
26
|
+
)
|
27
|
+
permalink.sub(":label", category_slug)
|
28
|
+
else
|
29
|
+
""
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Liquid::Template.register_tag("category_url", JekyllIndexPages::CategoryURL)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module JekyllIndexPages
|
2
|
+
class TagURL < Liquid::Tag
|
3
|
+
def initialize(tag, text, tokens)
|
4
|
+
super
|
5
|
+
@text = text.strip
|
6
|
+
end
|
7
|
+
|
8
|
+
def render(context)
|
9
|
+
site = context.registers[:site]
|
10
|
+
|
11
|
+
config = site.config["index_pages"] || {}
|
12
|
+
_, item = config.detect do |key, value|
|
13
|
+
key == "tags"
|
14
|
+
end
|
15
|
+
|
16
|
+
permalink = item ? item["permalink"] : "/:label/"
|
17
|
+
tag, _ = site.tags.detect do |key, value|
|
18
|
+
key == @text
|
19
|
+
end
|
20
|
+
|
21
|
+
if tag
|
22
|
+
tag_slug =
|
23
|
+
I18n.transliterate(
|
24
|
+
Jekyll::Utils.slugify(tag),
|
25
|
+
:locale => I18n.locale
|
26
|
+
)
|
27
|
+
permalink.sub(":label", tag_slug)
|
28
|
+
else
|
29
|
+
""
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Liquid::Template.register_tag("tag_url", JekyllIndexPages::TagURL)
|
data/lib/jekyll-index-pages.rb
CHANGED
@@ -4,8 +4,7 @@ require "jekyll-index-pages/archive"
|
|
4
4
|
require "jekyll-index-pages/author"
|
5
5
|
require "jekyll-index-pages/collection"
|
6
6
|
require "jekyll-index-pages/generator"
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
7
|
+
require "jekyll-index-pages/index-page"
|
8
|
+
require "jekyll-index-pages/pagination"
|
9
|
+
require "jekyll-index-pages/tags/category-url"
|
10
|
+
require "jekyll-index-pages/tags/tag-url"
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe JekyllIndexPages::CategoryURL 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("{% category_url %}") }
|
25
|
+
|
26
|
+
describe "CategoryURL.render" do
|
27
|
+
it "returns an empty string" do
|
28
|
+
expect(template.render(payload, info)).to eq("")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "When a valid category name is provided" do
|
34
|
+
let(:template) do
|
35
|
+
Liquid::Template.parse("{% category_url Ciencia ficción %}")
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "CategoryURL.render" do
|
39
|
+
it "returns a valid category page URL" do
|
40
|
+
expect(template.render(payload, info)).to eq("/ciencia-ficcion/")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "and a custom category permalink is provided" do
|
45
|
+
let(:overrides) do
|
46
|
+
{
|
47
|
+
"index_pages" => {
|
48
|
+
"categories" => {
|
49
|
+
"permalink" => "/custom/:label/"
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "CategoryURL.render" do
|
56
|
+
it "returns a valid category page URL" do
|
57
|
+
expect(template.render(payload, info)).to eq("/custom/ciencia-ficcion/")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/spec/generator_spec.rb
CHANGED
@@ -197,8 +197,8 @@ describe(JekyllIndexPages::Generator) do
|
|
197
197
|
end
|
198
198
|
|
199
199
|
describe("Generator.generate") do
|
200
|
-
it("generates
|
201
|
-
expect(site.pages.length).to eq(
|
200
|
+
it("generates three tag index pages") do
|
201
|
+
expect(site.pages.length).to eq(3)
|
202
202
|
end
|
203
203
|
|
204
204
|
it("generates a tag index page at /star-trek/") do
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe JekyllIndexPages::TagURL 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("{% tag_url %}") }
|
25
|
+
|
26
|
+
describe "TagURL.render" do
|
27
|
+
it "returns an empty string" do
|
28
|
+
expect(template.render(payload, info)).to eq("")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "When a valid tag name is provided" do
|
34
|
+
let(:template) do
|
35
|
+
Liquid::Template.parse("{% tag_url ciencia-ficción %}")
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "TagURL.render" do
|
39
|
+
it "returns a valid tag page URL" do
|
40
|
+
expect(template.render(payload, info)).to eq("/ciencia-ficcion/")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "and a custom tag permalink is provided" do
|
45
|
+
let(:overrides) do
|
46
|
+
{
|
47
|
+
"index_pages" => {
|
48
|
+
"tags" => {
|
49
|
+
"permalink" => "/custom/:label/"
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "TagURL.render" do
|
56
|
+
it "returns a valid tag page URL" do
|
57
|
+
expect(template.render(payload, info)).to eq("/custom/ciencia-ficcion/")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
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
|
+
version: 0.4.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-
|
11
|
+
date: 2017-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -105,11 +105,14 @@ 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/category-url.rb
|
109
|
+
- lib/jekyll-index-pages/tags/tag-url.rb
|
108
110
|
- lib/jekyll-index-pages/version.rb
|
109
111
|
- script/console
|
110
112
|
- script/setup
|
111
113
|
- spec/archive_spec.rb
|
112
114
|
- spec/author_spec.rb
|
115
|
+
- spec/category-url_spec.rb
|
113
116
|
- spec/collection_spec.rb
|
114
117
|
- spec/fixtures/index-page/_config.yml
|
115
118
|
- spec/fixtures/index-page/_layouts/archive.html
|
@@ -134,6 +137,7 @@ files:
|
|
134
137
|
- spec/index-page_spec.rb
|
135
138
|
- spec/pagination_spec.rb
|
136
139
|
- spec/spec_helper.rb
|
140
|
+
- spec/tag-url_spec.rb
|
137
141
|
homepage: https://github.com/rukbotto/jekyll-index-pages
|
138
142
|
licenses:
|
139
143
|
- MIT
|
@@ -161,6 +165,7 @@ summary: Index page generator for Jekyll sites.
|
|
161
165
|
test_files:
|
162
166
|
- spec/archive_spec.rb
|
163
167
|
- spec/author_spec.rb
|
168
|
+
- spec/category-url_spec.rb
|
164
169
|
- spec/collection_spec.rb
|
165
170
|
- spec/fixtures/index-page/_config.yml
|
166
171
|
- spec/fixtures/index-page/_layouts/archive.html
|
@@ -185,3 +190,4 @@ test_files:
|
|
185
190
|
- spec/index-page_spec.rb
|
186
191
|
- spec/pagination_spec.rb
|
187
192
|
- spec/spec_helper.rb
|
193
|
+
- spec/tag-url_spec.rb
|