jekyll-galleries 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +9 -0
- data/README.md +197 -0
- data/lib/jekyll/galleries.rb +51 -13
- metadata +5 -4
- data/README.rdoc +0 -61
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96392eb09f6402ecf36bb1144ab3037ac4431d52
|
4
|
+
data.tar.gz: 52129659e6b1e595d2493e3457823f5c6c653ae9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf7c2944dd0d6bcc5703aa252295e457e198830b8c3f8347e3bb25f5320bc27df23b9cb42bd6c61675399d3c22aeb4658ba19a29b83bca9011970dc492753a65
|
7
|
+
data.tar.gz: 1530757ee636776276f8d678130f09822bcfa3ce41986c8b3d28298ed0aa10d229fda40bc2dc8aa544d9978d3c120d28e1b524ca3642e0a351155239eb9cffda
|
data/ChangeLog
CHANGED
data/README.md
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
# jekyll-galleries
|
2
|
+
|
3
|
+
By [allenlsy](mailto:cafe@allenlsy.com)
|
4
|
+
|
5
|
+
__Jekyll-galleries__ is a Jekyll plugin used for generating photo galleries from image folders.
|
6
|
+
|
7
|
+
If you have any questions or any suggestions, I'm very pleased to hear from you. I need your support and ideas to make this plugin better.
|
8
|
+
|
9
|
+
---
|
10
|
+
|
11
|
+
##### Features:
|
12
|
+
|
13
|
+
* Automatically generate galleries from <tt>galleries</tt> folder
|
14
|
+
* Provide a convenient to generate galleries index page
|
15
|
+
* Load galleries and photos configuration from YAML file
|
16
|
+
|
17
|
+
There are two main concept in this plugin:
|
18
|
+
|
19
|
+
* __GalleriesPage__: index page displays all the galleries
|
20
|
+
* __GalleryPage__: single gallery webpage which shows all the photos in this gallery
|
21
|
+
|
22
|
+
### How to use the plugin
|
23
|
+
|
24
|
+
Here is an example on how to use this plugin.
|
25
|
+
|
26
|
+
##### 1. Setup the plugin
|
27
|
+
|
28
|
+
Add `gem 'jekyll-galleries'` to the `Gemfile` in your jekyll project, and then run `bundle` command in shell to install it. Then add `require 'jekyll/galleries'` to `_plugins/_ext.rb`.
|
29
|
+
|
30
|
+
There are three attributes which are optional. All of them should be put at the root level of `_config.yml`, if needed.
|
31
|
+
|
32
|
+
* `galleries` specifies the extra information of each gallery, using the YAML object format.
|
33
|
+
* `gallery_dir` defines which folder in jekyll project stores the all the galleries. Default value is `galleries` if not defined.
|
34
|
+
* `gallery_layout` defines the layout __Jekyll-galleries__ will use to render each single gallery. Default value is `gallery`, which uses the `_layouts/gallery.html` as the template.
|
35
|
+
|
36
|
+
Check out the example `_config.yml` if you are still not clear.
|
37
|
+
|
38
|
+
##### 2. Add galleries to jekyll project
|
39
|
+
|
40
|
+
By default, galleries are stored in the `galleries` folder in the jekyll project root path. If you want to change the storing path, you can customize the `gallery_dir` attribute it in `_config.yml` file.
|
41
|
+
|
42
|
+
__Jekyll-galleries__ will recognize all the subfolders in `galleries` (or `gallery_dir` specified in `_config.yml`) with the format of `<yyyy-MM-dd>-<NAME>` as a valid gallery folder. Meanwhile it adds `date` (value `yyyy-MM-dd`) and `name` (value `NAME`) attributes to the gallery. In the `name` attributes, space and other characters are allowed. All the files in gallery folder will be loaded to the GalleryPage. So please ensure you have correct image file in the gallery folder.
|
43
|
+
|
44
|
+
##### 3. Adding attribute to photos
|
45
|
+
|
46
|
+
You can have a `.yml` file with the same name of the gallery folder, to define attributes of each photo in that gallery. Only photos with extra attributes are required in the yaml file. Each photo is identified by the attribute `filename`. For example, if you have an gallery, whose folder name is `2014-01-23-At the beach`, then in a `2014-01-23-At the beach.yml` file, you can config photos like this:
|
47
|
+
|
48
|
+
- filename: IMG_0075.JPG
|
49
|
+
annotation: this is the allenllsy's jekyll-galleries
|
50
|
+
- filename: IMG_1234.JPG
|
51
|
+
annotation: shot at London
|
52
|
+
|
53
|
+
Then later you can use the attributes in your template, such as `annotation` in the example above.
|
54
|
+
|
55
|
+
Notice that attribute `filename` is required for any photos that as extra attributes.
|
56
|
+
|
57
|
+
##### 4. Adding attribute to gallery
|
58
|
+
|
59
|
+
Inside the optional `galleries` attribute in `_config.yml`, you can have objects, with attribute `name` the value equals to your gallery name (not containing the date). For example:
|
60
|
+
|
61
|
+
galleries:
|
62
|
+
- name: Sample Gallery
|
63
|
+
subtitle: This is a sample gallery
|
64
|
+
|
65
|
+
Then in the template, the gallery will have the attribute `subtitle` that can be rendered.
|
66
|
+
|
67
|
+
##### 5. Use attributes in template
|
68
|
+
|
69
|
+
Now, the `site.data['galleries']` global variable contains all the gallery pages. It is an array of `GalleryPage` objects. Each `GalleryPage` object has at least three attributes: `name`, `date` and `url`. `url` is URL escaped. You can use them in your galleries index page.
|
70
|
+
|
71
|
+
In each gallery page, you have a `page` object. And `page.photos` is an array of `Photo` objects. An `Photo` object has at least `filename` and `url` two attributes. The `url` attribute is also URL escaped, so you don't need to worry about it.
|
72
|
+
|
73
|
+
In the example below, you will see how to use attributes in template in more detail.
|
74
|
+
|
75
|
+
### Example of Galleries Index page & Gallery page
|
76
|
+
|
77
|
+
* Galleries Index page: the index page of all galleries
|
78
|
+
* Gallery Page: the page display photos in that gallery
|
79
|
+
|
80
|
+
Suppose in the Jekyll project root folder, my file structure is like below:
|
81
|
+
|
82
|
+
galleries/
|
83
|
+
|-2014-01-23-At the beach
|
84
|
+
| -IMG_0001.JPG
|
85
|
+
| -IMG_0005.JPG
|
86
|
+
|-2014-02-01-Chinese New Year
|
87
|
+
| -sing a song.jpg
|
88
|
+
| -having dinner.jpg
|
89
|
+
|
90
|
+
##### Galleries index page template
|
91
|
+
|
92
|
+
After installing and setting up the plugin, I add a galleries index file `galleries.html` in Jekyll root directory:
|
93
|
+
|
94
|
+
---
|
95
|
+
layout: base
|
96
|
+
---
|
97
|
+
{% for gallery in site.data['galleries'] %}
|
98
|
+
<p>
|
99
|
+
<a href="{{ gallery.url }}">{{ gallery.name }}</a>
|
100
|
+
<span>{{ gallery.date }}</span>
|
101
|
+
</p>
|
102
|
+
{% endfor %}
|
103
|
+
|
104
|
+
If I want to also add other attributes, such as `excerpt` for some galleries, I can specifies them in `_config.yml`
|
105
|
+
|
106
|
+
galleries:
|
107
|
+
- name: At the beach
|
108
|
+
excerpt: Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
|
109
|
+
|
110
|
+
Then I update the `galleries.html` page:
|
111
|
+
|
112
|
+
---
|
113
|
+
layout: base
|
114
|
+
---
|
115
|
+
{% for gallery in site.data['galleries'] %}
|
116
|
+
<div>
|
117
|
+
<a href="{{ gallery.url }}">{{ gallery.name }}</a>
|
118
|
+
<span>{{ gallery.date }}</span>
|
119
|
+
{% if gallery.excerpt %}
|
120
|
+
<p>
|
121
|
+
{{ gallery.excerpt }}
|
122
|
+
</p>
|
123
|
+
{% endif %}
|
124
|
+
</div>
|
125
|
+
{% endfor %}
|
126
|
+
|
127
|
+
The generated `galleries.html` should be like this:
|
128
|
+
|
129
|
+
<div>
|
130
|
+
<a href="/galleries/2014-02-01-chinese-new-year.html">Chinese New Year</a>
|
131
|
+
<span>2014-02-01</span>
|
132
|
+
</div>
|
133
|
+
<div>
|
134
|
+
<a href="/galleries/2014-01-23-at-the-beach.html">At the beach</a>
|
135
|
+
<span>2014-01-23</span>
|
136
|
+
<p>
|
137
|
+
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
|
138
|
+
</p>
|
139
|
+
</div>
|
140
|
+
|
141
|
+
|
142
|
+
##### Gallery page template
|
143
|
+
|
144
|
+
Next, I add a `_layouts/gallery.html` file as my gallery template. This is the template for each single gallery
|
145
|
+
|
146
|
+
---
|
147
|
+
layout: base
|
148
|
+
---
|
149
|
+
|
150
|
+
{% for photo in page.photos %}
|
151
|
+
<img src="{{ photo.url }}" style="width:800px;"/>
|
152
|
+
{% if photo.info %}
|
153
|
+
<p>{{ photo.info }}</p>
|
154
|
+
{% endif %}
|
155
|
+
<hr >
|
156
|
+
{% endfor %}
|
157
|
+
|
158
|
+
In this template, I take use of the extra attribute `info` of photo. This attribute can be configured in photos config file, eg. `galleries/2014-02-01-Chinese New Year`:
|
159
|
+
|
160
|
+
- filename: 'sing a song.jpg'
|
161
|
+
info: 'We are singing a song'
|
162
|
+
|
163
|
+
The photos are identified using the `filename` attribute.
|
164
|
+
|
165
|
+
After I run `jekyll build`, it should generate a file `_site/galleries/2014-02-01-chinese-new-year.html`. The content should be like:
|
166
|
+
|
167
|
+
<img src="/galleries/2014-02-02-Chinese%20New%20Year/IMG_0094.JPG" style="width:800px;"/>
|
168
|
+
<hr >
|
169
|
+
<img src="/galleries/2014-02-02-Chinese%20New%20Year/sing%20a%20song.jpg" style="width:800px;"/>
|
170
|
+
<p>We are singing a song</p>
|
171
|
+
<hr >
|
172
|
+
|
173
|
+
### License
|
174
|
+
|
175
|
+
#### The MIT License
|
176
|
+
|
177
|
+
Copyright (c) 2010-2012 University of Cologne,
|
178
|
+
Albertus-Magnus-Platz, 50923 Cologne, Germany
|
179
|
+
|
180
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
181
|
+
of this software and associated documentation files (the "Software"), to deal
|
182
|
+
in the Software without restriction, including without limitation the rights
|
183
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
184
|
+
copies of the Software, and to permit persons to whom the Software is
|
185
|
+
furnished to do so, subject to the following conditions:
|
186
|
+
|
187
|
+
The above copyright notice and this permission notice shall be included in
|
188
|
+
all copies or substantial portions of the Software.
|
189
|
+
|
190
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
191
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
192
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
193
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
194
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
195
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
196
|
+
THE SOFTWARE.
|
197
|
+
|
data/lib/jekyll/galleries.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Jekyll
|
2
2
|
class GalleryGenerator < Generator
|
3
|
-
attr_accessor :site, :gallery_dir, :gallery_layout
|
3
|
+
attr_accessor :site, :gallery_dir, :gallery_layout, :galleries
|
4
4
|
class << self; attr_accessor :site; end
|
5
5
|
|
6
6
|
def generate(site)
|
@@ -10,8 +10,9 @@ module Jekyll
|
|
10
10
|
|
11
11
|
# array of GalleryPage objects
|
12
12
|
site.data['galleries'] = []
|
13
|
+
|
13
14
|
gallery_dirs = Dir["#{site.source}/#{gallery_dir}/*/"].select { |e| File.directory? e }
|
14
|
-
gallery_dirs.reverse! # sort by date desc
|
15
|
+
gallery_dirs.reverse! # in order to sort by date desc
|
15
16
|
gallery_dirs.each do |dir|
|
16
17
|
generate_gallery_page(dir)
|
17
18
|
end
|
@@ -22,6 +23,7 @@ module Jekyll
|
|
22
23
|
data = { 'layout' => gallery_layout }
|
23
24
|
|
24
25
|
page = GalleryPage.new(site, site.source, self.gallery_dir, gallery_dir, data)
|
26
|
+
|
25
27
|
site.pages << page
|
26
28
|
|
27
29
|
site.data['galleries'] << page
|
@@ -32,19 +34,42 @@ module Jekyll
|
|
32
34
|
class GalleryPage < Page
|
33
35
|
# Valid post name regex.
|
34
36
|
MATCHER = /^(\d+-\d+-\d+)-(.*)$/
|
37
|
+
CONFIG_GALLERIES_ATTR = 'galleries'
|
35
38
|
|
36
|
-
attr_accessor :
|
39
|
+
attr_accessor :url, :name, :slug, :date
|
37
40
|
|
38
|
-
def initialize(site, base, gen_dir,
|
41
|
+
def initialize(site, base, gen_dir, gallery_dir, data={})
|
39
42
|
self.content = data.delete('content') || ''
|
40
43
|
self.data = data
|
41
44
|
|
42
|
-
|
45
|
+
gallery_dir_name = File.basename gallery_dir
|
46
|
+
super(site, base, gen_dir, gallery_dir_name)
|
47
|
+
|
48
|
+
# load photos configuration
|
49
|
+
photos_config_filepath = "#{base}/#{site.config['gallery_dir']}/#{self.date}-#{self.name}.yml"
|
50
|
+
photos_config = YAML.load(File.open(photos_config_filepath).read) if File.exists?(photos_config_filepath)
|
51
|
+
|
52
|
+
# generating photos
|
53
|
+
self.url = "/#{gen_dir}/#{self.date}-#{self.slug}.html" # gallery page url
|
54
|
+
self.data['url'] = URI.escape self.url
|
43
55
|
|
44
|
-
#
|
45
|
-
|
46
|
-
|
47
|
-
self.data['
|
56
|
+
# For each photo, initial attributes are `filename` and `url`
|
57
|
+
photos = Dir["#{gallery_dir}/*"].map { |e| { filename: File.basename(e), url: URI.escape("/#{gen_dir}/#{gallery_dir_name}/#{File.basename e}") } } # basic photos attributes
|
58
|
+
|
59
|
+
self.data['photos'] = [] # storing an array of Photo
|
60
|
+
photos.each do |photo|
|
61
|
+
photo_data = {}
|
62
|
+
photo_data = photos_config.find { |e| e['filename'] == photo[:filename] } if photos_config
|
63
|
+
self.data['photos'] << Photo.new(photo[:filename], photo[:url], photo_data)
|
64
|
+
end
|
65
|
+
|
66
|
+
# gallery page configuration
|
67
|
+
if site.config[CONFIG_GALLERIES_ATTR]
|
68
|
+
attr = site.config[CONFIG_GALLERIES_ATTR].find { |e| e['name'] == self.name}
|
69
|
+
if attr
|
70
|
+
attr.each { |k, v| self.data[k] = v }
|
71
|
+
end
|
72
|
+
end
|
48
73
|
end
|
49
74
|
|
50
75
|
def read_yaml(*)
|
@@ -59,14 +84,28 @@ module Jekyll
|
|
59
84
|
m, date, name = *name.match(MATCHER)
|
60
85
|
|
61
86
|
# self.data['date'] = Time.parse(date)
|
62
|
-
self.data['date'] = date
|
63
|
-
self.data['name'] = name
|
64
|
-
self.data['slug'] = name
|
87
|
+
self.data['date'] = self.date = date
|
88
|
+
self.data['name'] = self.name = name
|
89
|
+
self.data['slug'] = self.slug = name.gsub(/[^0-9a-z ]/i, '').downcase.gsub(/ /, '-')
|
65
90
|
rescue ArgumentError
|
66
91
|
raise FatalException.new("Gallery #{name} does not have a valid date.")
|
67
92
|
end
|
68
93
|
end
|
69
94
|
|
95
|
+
class Photo
|
96
|
+
attr_accessor :filename, :url, :data
|
97
|
+
|
98
|
+
def initialize(filename, url, options=nil)
|
99
|
+
self.filename = filename
|
100
|
+
self.url = url
|
101
|
+
self.data = options || {}
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_liquid
|
105
|
+
self.data.merge({ 'url' => self.url })
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
70
109
|
class YamlToLiquid < Liquid::Tag
|
71
110
|
def initialize(tag_name, arg, tokens)
|
72
111
|
super
|
@@ -87,4 +126,3 @@ module Jekyll
|
|
87
126
|
end
|
88
127
|
|
89
128
|
Liquid::Template.register_tag('yaml_to_liquid', Jekyll::YamlToLiquid)
|
90
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-galleries
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- allenlsy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Jekyll plugin to automatically generate photo gallery (album) from image
|
14
14
|
folder.
|
@@ -19,7 +19,7 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- lib/jekyll/galleries.rb
|
21
21
|
- ChangeLog
|
22
|
-
- README.
|
22
|
+
- README.md
|
23
23
|
- Rakefile
|
24
24
|
homepage: http://github.com/allenlsy/jekyll-galleries
|
25
25
|
licenses:
|
@@ -53,6 +53,7 @@ rubygems_version: 2.1.11
|
|
53
53
|
signing_key:
|
54
54
|
specification_version: 4
|
55
55
|
summary: Jekyll plugin to automatically generate photo gallery (album) from image
|
56
|
-
folder.
|
56
|
+
folder. It provides easy configuration to customize the attribute, for using them
|
57
|
+
in galleries index page
|
57
58
|
test_files: []
|
58
59
|
has_rdoc:
|
data/README.rdoc
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
= jekyll-galleries
|
2
|
-
|
3
|
-
By allenlsy <mailto:cafe@allenlsy>
|
4
|
-
|
5
|
-
Jekyll-galleries is a Jekyll plugin used for generating photo galleries from image folders.
|
6
|
-
|
7
|
-
<tt>_config.yml</tt>:
|
8
|
-
|
9
|
-
gallery_dir: galleries
|
10
|
-
gallery_layout: gallery
|
11
|
-
|
12
|
-
Sample layout for gallery index, which you can make a <tt>galleries.html</tt> in Jekyll root directory:
|
13
|
-
|
14
|
-
{% for gallery in site.data['galleries'] %}
|
15
|
-
<p>
|
16
|
-
<a href="{{ gallery.url }}">{{ gallery.name }}</a>
|
17
|
-
<span>{{ gallery.date }}</span>
|
18
|
-
</p>
|
19
|
-
{% endfor %}
|
20
|
-
|
21
|
-
Sample layout for one gallery page, which normally you will put it as <tt>_layouts/gallery.html</tt>:
|
22
|
-
|
23
|
-
---
|
24
|
-
layout: base
|
25
|
-
---
|
26
|
-
{% for photo_url in page.photos %}
|
27
|
-
<p>
|
28
|
-
<img src="{{ photo_url }}" />
|
29
|
-
</p>
|
30
|
-
{% endfor %}
|
31
|
-
|
32
|
-
== Links
|
33
|
-
|
34
|
-
<b></b>
|
35
|
-
Source code:: <http://github.com/allenlsy/jekyll-galleries>
|
36
|
-
RubyGem:: <http://rubygems.org/gems/jekyll-galleries>
|
37
|
-
|
38
|
-
== License
|
39
|
-
|
40
|
-
=== The MIT License
|
41
|
-
|
42
|
-
Copyright (c) 2010-2012 University of Cologne,
|
43
|
-
Albertus-Magnus-Platz, 50923 Cologne, Germany
|
44
|
-
|
45
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
46
|
-
of this software and associated documentation files (the "Software"), to deal
|
47
|
-
in the Software without restriction, including without limitation the rights
|
48
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
49
|
-
copies of the Software, and to permit persons to whom the Software is
|
50
|
-
furnished to do so, subject to the following conditions:
|
51
|
-
|
52
|
-
The above copyright notice and this permission notice shall be included in
|
53
|
-
all copies or substantial portions of the Software.
|
54
|
-
|
55
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
56
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
57
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
58
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
59
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
60
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
61
|
-
THE SOFTWARE.
|