jekyll-index-pages 0.5.3 → 0.6.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 +34 -45
- data/lib/jekyll-index-pages/index-page.rb +6 -0
- data/lib/jekyll-index-pages/version.rb +1 -1
- data/spec/fixtures/index-page/_layouts/posts.html +2 -0
- data/spec/generator_spec.rb +22 -0
- data/spec/index-page_spec.rb +48 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15b1bb8d47b230b04e9f5494826715b53e9d45667c91b39181f4e0f95f38e621
|
4
|
+
data.tar.gz: 940618a6e09b35ddc2cf16a99cad645e1189678e615f084ffd8808757c67f9f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01705f933b4716cbc199e6d685fb2f4f31c9e6980d26f6ff3d6ce7e8054e16b4d01bc3fdba60edca999f7dbd51612116f67c097d9fb8b7f587de46f1f2a0e070
|
7
|
+
data.tar.gz: b24eb1a4defef28a49c2cd4577b031a682fbf66b92344020b3267fc0e9f4eea0483249bdbed362f517ec39870d46338e9545903fbd9e59f84b05a7f1d5f1c189
|
data/README.md
CHANGED
@@ -2,9 +2,7 @@
|
|
2
2
|
|
3
3
|
[](https://travis-ci.org/rukbotto/jekyll-index-pages)
|
4
4
|
|
5
|
-
Index page generator for Jekyll sites. Generates paginated index pages for blog
|
6
|
-
posts, categories and tags. It can also generate a paginated yearly archive,
|
7
|
-
author and collection pages.
|
5
|
+
Index page generator for Jekyll sites. Generates paginated index pages for blog posts, categories and tags. It can also generate a paginated yearly archive, author and collection pages.
|
8
6
|
|
9
7
|
## Installation
|
10
8
|
|
@@ -37,8 +35,7 @@ gems:
|
|
37
35
|
|
38
36
|
### Configuring the plugin
|
39
37
|
|
40
|
-
If you want to generate index pages for your blog posts, you can add the
|
41
|
-
following settings to your `_config.yml` file:
|
38
|
+
If you want to generate index pages for your blog posts, you can add the following settings to your `_config.yml` file:
|
42
39
|
|
43
40
|
```yaml
|
44
41
|
index_pages:
|
@@ -50,16 +47,11 @@ index_pages:
|
|
50
47
|
layout: blog
|
51
48
|
```
|
52
49
|
|
53
|
-
This will tell the plugin to generate index pages with given title and excerpt,
|
54
|
-
using the layout named `_layouts/blog.html`. Each index page will contain up to
|
55
|
-
20 documents. First page can be accessed at `/blog/`. Subsequent pages can be
|
56
|
-
accessed at `/blog/<page-num>/`.
|
50
|
+
This will tell the plugin to generate index pages with given title and excerpt, using the layout named `_layouts/blog.html`. Each index page will contain up to 20 documents. First page can be accessed at `/blog/`. Subsequent pages can be accessed at `/blog/<page-num>/`.
|
57
51
|
|
58
|
-
> Documents are sorted automatically using document's `date` setting, the
|
59
|
-
> first being the most recent.
|
52
|
+
> Documents are sorted automatically using document's `date` setting, the first being the most recent.
|
60
53
|
|
61
|
-
If you want to generate index pages for categories, add the `categories`
|
62
|
-
setting to `index_page` section:
|
54
|
+
If you want to generate index pages for categories, add the `categories` setting to `index_page` section:
|
63
55
|
|
64
56
|
```yaml
|
65
57
|
index_pages:
|
@@ -110,14 +102,9 @@ permalink: /:label/
|
|
110
102
|
layout: posts|categories|tags|authors|archive
|
111
103
|
```
|
112
104
|
|
113
|
-
For categories and tags, `:label` variable refers to the category or tag name.
|
114
|
-
For posts, `:label` will always be equal to `posts`. For the archive, `:label`
|
115
|
-
refers to any given year. For authors, `:label` is the author name. `:label`
|
116
|
-
value is slugified when composing the permalink.
|
105
|
+
For categories and tags, `:label` variable refers to the category or tag name. For posts, `:label` will always be equal to `posts`. For the archive, `:label` refers to any given year. For authors, `:label` is the author name. `:label` value is slugified when composing the permalink.
|
117
106
|
|
118
|
-
Default value for layout depends on the type of index page. For collection
|
119
|
-
index pages, the default layout is the same as the custon name used to define
|
120
|
-
the collection config:
|
107
|
+
Default value for layout depends on the type of index page. For collection index pages, the default layout is the same as the custon name used to define the collection config:
|
121
108
|
|
122
109
|
```yaml
|
123
110
|
custom_name:
|
@@ -126,21 +113,35 @@ custom_name:
|
|
126
113
|
...
|
127
114
|
```
|
128
115
|
|
129
|
-
Because this plugin [transliterates](http://stackoverflow.com/a/20586777) the
|
130
|
-
URL for generated pages, you need to define a language as follows:
|
116
|
+
Because this plugin [transliterates](http://stackoverflow.com/a/20586777) the URL for generated pages, you need to define a language as follows:
|
131
117
|
|
132
118
|
```yaml
|
133
119
|
lang: en-US
|
134
120
|
```
|
135
121
|
|
136
|
-
Then get the specified locale file from
|
137
|
-
|
138
|
-
|
122
|
+
Then get the specified locale file from <https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale> and add it to the `_locales/` directory inside your site codebase.
|
123
|
+
|
124
|
+
### Including custom data into templates
|
125
|
+
|
126
|
+
To include custom data in the template, you must define a variable in the configuration under the `data` section:
|
127
|
+
|
128
|
+
```yaml
|
129
|
+
index_pages:
|
130
|
+
posts:
|
131
|
+
layout: blog
|
132
|
+
data:
|
133
|
+
custom: This is a custom data item
|
134
|
+
```
|
135
|
+
|
136
|
+
In this case, you can print the contents of the `custom` variable in the `_layouts/blog.html` layout like this:
|
137
|
+
|
138
|
+
```liquid
|
139
|
+
{{ page.custom }}
|
140
|
+
```
|
139
141
|
|
140
142
|
### Including documents and pagination into templates
|
141
143
|
|
142
|
-
To include the paginated documents in your layouts, you can use the `pager`
|
143
|
-
variable as demonstrated next:
|
144
|
+
To include the paginated documents in your layouts, you can use the `pager` variable as demonstrated next:
|
144
145
|
|
145
146
|
```liquid
|
146
147
|
{% assign pager = page.pager %}
|
@@ -152,8 +153,7 @@ variable as demonstrated next:
|
|
152
153
|
{% endfor %}
|
153
154
|
```
|
154
155
|
|
155
|
-
Each document in `pager.docs` is a Jekyll document, so you can access all its
|
156
|
-
variables as normally do when developing a layout.
|
156
|
+
Each document in `pager.docs` is a Jekyll document, so you can access all its variables as normally do when developing a layout.
|
157
157
|
|
158
158
|
To include the pagination, you can do the following:
|
159
159
|
|
@@ -173,10 +173,7 @@ To include the pagination, you can do the following:
|
|
173
173
|
|
174
174
|
### Linking index pages
|
175
175
|
|
176
|
-
Sometimes you will need to link index pages, for example when building some
|
177
|
-
kind of category navigation. For this particular use case, you can use `{%
|
178
|
-
category_url %}`, `{% tag_url %}`, `{% author_url %}` and `{% archive_url %}`
|
179
|
-
tags for getting the correct URL to a given index page.
|
176
|
+
Sometimes you will need to link index pages, for example when building some kind of category navigation. For this particular use case, you can use `{% category_url %}`, `{% tag_url %}`, `{% author_url %}` and `{% archive_url %}` tags for getting the correct URL to a given index page.
|
180
177
|
|
181
178
|
```liquid
|
182
179
|
<a href="{% category_url "Category name" %}">Category name</a>
|
@@ -199,22 +196,14 @@ The following example demonstrates how to create a basic category navigation:
|
|
199
196
|
|
200
197
|
## Development
|
201
198
|
|
202
|
-
After checking out the repo, run `script/setup` to install dependencies. Then,
|
203
|
-
run `rake spec` to run the tests. You can also run `script/console` for an
|
204
|
-
interactive prompt that will allow you to experiment.
|
199
|
+
After checking out the repo, run `script/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `script/console` for an interactive prompt that will allow you to experiment.
|
205
200
|
|
206
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To
|
207
|
-
release a new version, update the version number in `version.rb`, and then run
|
208
|
-
`bundle exec rake release`, which will create a git tag for the version, push
|
209
|
-
git commits and tags, and push the `.gem` file to
|
210
|
-
[rubygems.org](https://rubygems.org).
|
201
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
211
202
|
|
212
203
|
## Contributing
|
213
204
|
|
214
|
-
Bug reports and pull requests are welcome on GitHub at
|
215
|
-
https://github.com/rukbotto/jekyll-index-pages.
|
205
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/rukbotto/jekyll-index-pages.>
|
216
206
|
|
217
207
|
## License
|
218
208
|
|
219
|
-
The gem is available as open source under the terms of the [MIT
|
220
|
-
License](http://opensource.org/licenses/MIT).
|
209
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -22,6 +22,12 @@ module JekyllIndexPages
|
|
22
22
|
self.process(@name)
|
23
23
|
self.read_yaml(File.join(base, layout_dir), layout_name)
|
24
24
|
|
25
|
+
if config.key?("data") and config["data"].is_a?(Hash)
|
26
|
+
config["data"].each do |key, value|
|
27
|
+
self.data[key] = value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
25
31
|
self.data["title"] = title.sub(":label", label)
|
26
32
|
self.data["excerpt"] = excerpt.sub(":label", label)
|
27
33
|
|
data/spec/generator_spec.rb
CHANGED
@@ -197,6 +197,28 @@ describe JekyllIndexPages::Generator do
|
|
197
197
|
end
|
198
198
|
end
|
199
199
|
|
200
|
+
context "When custom data is provided in the configuration for posts index page" do
|
201
|
+
let(:overrides) do
|
202
|
+
{
|
203
|
+
"index_pages" => {
|
204
|
+
"posts" => {
|
205
|
+
"data" => {
|
206
|
+
"custom" => "This is a custom data item"
|
207
|
+
}
|
208
|
+
}
|
209
|
+
}
|
210
|
+
}
|
211
|
+
end
|
212
|
+
|
213
|
+
describe "Generator.generate" do
|
214
|
+
it "generates an index page containing the custom data items" do
|
215
|
+
expect(site.pages.length).to eq(1)
|
216
|
+
expect(site.pages[0].data["custom"]).to eq("This is a custom data item")
|
217
|
+
expect(site.pages[0].content).to include("This is a custom data item")
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
200
222
|
context "When default configuration for category index pages is provided" do
|
201
223
|
let(:overrides) do
|
202
224
|
{
|
data/spec/index-page_spec.rb
CHANGED
@@ -47,6 +47,10 @@ describe JekyllIndexPages::IndexPage do
|
|
47
47
|
expect(page.data["excerpt"]).to eq("posts")
|
48
48
|
end
|
49
49
|
|
50
|
+
it "with no additional data" do
|
51
|
+
expect(page.data.length).to eq(3)
|
52
|
+
end
|
53
|
+
|
50
54
|
it "listing the first two posts" do
|
51
55
|
expect(page.data["pager"]["docs"].length).to eq(2)
|
52
56
|
end
|
@@ -96,14 +100,56 @@ describe JekyllIndexPages::IndexPage do
|
|
96
100
|
let(:config) do
|
97
101
|
{
|
98
102
|
"title" => "Star Trek Index",
|
99
|
-
"excerpt" => "Star Trek Index"
|
103
|
+
"excerpt" => "Star Trek Index",
|
104
|
+
"data" => {
|
105
|
+
"description" => "This is the Star Trek Index"
|
106
|
+
}
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "IndexPage.initialize" do
|
111
|
+
it "creates the first index page with the specified title, excerpt and data items" do
|
112
|
+
expect(page.data["title"]).to eq("Star Trek Index")
|
113
|
+
expect(page.data["excerpt"]).to eq("Star Trek Index")
|
114
|
+
expect(page.data["description"]).to eq("This is the Star Trek Index")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "When custom data is not provided as a Hash" do
|
120
|
+
let(:config) do
|
121
|
+
{
|
122
|
+
"title" => "Star Trek Index",
|
123
|
+
"excerpt" => "Star Trek Index",
|
124
|
+
"data" => ["This is custom data item"]
|
125
|
+
}
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "IndexPage.initialize" do
|
129
|
+
it "will not add any custom data to index page" do
|
130
|
+
expect(page.data.length).to eq(3)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context "When custom data tries to override the page's original data" do
|
136
|
+
let(:config) do
|
137
|
+
{
|
138
|
+
"title" => "Star Trek Index",
|
139
|
+
"excerpt" => "Star Trek Index",
|
140
|
+
"data" => {
|
141
|
+
"title" => "This is another title",
|
142
|
+
"excerpt" => "This is another excerpt",
|
143
|
+
"pager" => nil
|
144
|
+
}
|
100
145
|
}
|
101
146
|
end
|
102
147
|
|
103
148
|
describe "IndexPage.initialize" do
|
104
|
-
it "
|
149
|
+
it "will preserve the original data" do
|
105
150
|
expect(page.data["title"]).to eq("Star Trek Index")
|
106
151
|
expect(page.data["excerpt"]).to eq("Star Trek Index")
|
152
|
+
expect(page.data["pager"]).to be_instance_of(Hash)
|
107
153
|
end
|
108
154
|
end
|
109
155
|
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.6.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: 2018-
|
11
|
+
date: 2018-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|