jekyll-flickr 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: '08d52c799b1be3a7e36cec03f8a9bef0077b3157'
4
+ data.tar.gz: c588c8f2a4bd69aa051c84b571bb489bab40d4d2
5
+ SHA512:
6
+ metadata.gz: 3bfbeec7b14f0ee7c771868a87b51fc1ee7798e1e1020bcdeb68834bfde30824c1939d38668cd8bccd2c55225c4cccb59b69646c6e7cfc3cd2926ad48cc5a72a
7
+ data.tar.gz: 8a84fef0dc6a3c82766d01cc935322c76119978018208c7e9617c8dfa1947434ed54469dd2d2d9f177d77a6c8993c051e95d4837ab4433a1f6a730644f9c422e
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ ## HEAD
2
+
3
+
4
+ ## 0.1.0 / 2017-04-08
5
+
6
+ * Birthday!
7
+ * move monkey patched code to a proper Jekyll Tag plug-in
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec
5
+
6
+ if ENV["GH_PAGES"]
7
+ gem "github-pages"
8
+ elsif ENV["JEKYLL_VERSION"]
9
+ gem "jekyll", "~> #{ENV["JEKYLL_VERSION"]}"
10
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017-present Robert Riemann and jekyll-onebox contributors
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,116 @@
1
+ # Jekyll::Flickr
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/jekyll-flickr.svg)](https://badge.fury.io/rb/jekyll-flickr)
4
+
5
+ Liquid tag for responsive [Flickr] images using [HTML5 srcset](http://alistapart.com/article/responsive-images-in-practice): `{% flickr %}`.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ $ gem 'jekyll-flickr'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install jekyll-flickr
20
+
21
+ Then add the following to your site's `_config.yml`:
22
+
23
+ ```yaml
24
+ plugins:
25
+ - jekyll-flickr
26
+ ```
27
+
28
+ 💡 If you are using a Jekyll version less than 3.5.0, use the `gems` key instead of `plugins`.
29
+
30
+ You must further provide two [Flickr API credentials](https://www.flickr.com/services/api/keys/). You can either use environment variables `FLICKR_API_KEY` and `FLICKR_API_SECRET` or the `_config.yml`:
31
+
32
+ ```yml
33
+ flickr:
34
+ api_key: <flickr_api_key>
35
+ api_secret: <flickr_shared_secret>
36
+ ```
37
+
38
+ 💡 API requests are cached in `.jekyll-cache/flickr` for faster builds.
39
+
40
+ ## Usage
41
+
42
+ Use the tag as follows in your Jekyll pages, posts and collections:
43
+
44
+ ```liquid
45
+ {% flickr photo_id "Caption" img_attributes %}
46
+ ```
47
+ - The `photo_id` is required and determines the photo from Flickr. In the URL <http://alistapart.com/article/responsive-images-in-practice>, the photo_id is the number in the path after the author (here also a number), i.e. `38285149681`.
48
+ - The `Caption` is optional and must be enclosed by double quotation marks. So far, double quotation marks in captions are not supported.
49
+ - The `img_attributes` are any optional text that will be included in the `<img>` tag.
50
+
51
+ Example:
52
+
53
+ ```liquid
54
+ {% flickr 38285149681 "My favourite photo of the month." style="float: right;"}
55
+ ```
56
+
57
+ This will create the following HTML output:
58
+
59
+ ```html
60
+ <figure>
61
+ <img src="https://farm5.staticflickr.com/4570/38285149681_f7323259a3_c.jpg" srcset="https://farm5.staticflickr.com/4570/38285149681_f7323259a3_n.jpg 320w, https://farm5.staticflickr.com/4570/38285149681_f7323259a3_z.jpg 640w, https://farm5.staticflickr.com/4570/38285149681_f7323259a3_c.jpg 800w, https://farm5.staticflickr.com/4570/38285149681_f7323259a3_b.jpg 1024w, https://farm5.staticflickr.com/4570/38285149681_2436f15109_h.jpg 1600w" sizes="100vw" style="float: right;" alt="My favourite photo of the month.">
62
+ <figcaption>
63
+ <div class="caption">My favourite photo of the month.</div>
64
+ <div class="license">
65
+ © Flickr/<a href="https://www.flickr.com/photos/140750848@N04/38285149681/">moulichoudari</a>
66
+ <a href="https://creativecommons.org/licenses/by/2.0/">CC Attribution License</a>
67
+ </div>
68
+ </figcaption>
69
+ </figure>
70
+ ```
71
+
72
+ ## Configuration
73
+
74
+ ```yml
75
+ flickr:
76
+ api_key: <flickr_api_key>
77
+ api_secret: <flickr_shared_secret>
78
+ widths: [320, 640, 800, 1024, 1600]
79
+ width_legacy: 800
80
+ width_viewport: 100vw
81
+ figcaption: true
82
+ license: true
83
+ caption: true
84
+ ```
85
+
86
+ The Flickr API provides images in a [number of sizes](https://www.flickr.com/services/api/flickr.photos.getSizes.html) (e.g. 75, 150, 100, 240, 320, 500, 640, 1024, 3648). The `widths` allows to filter for sizes to be included in the `srcset` attribute. The size `width_legacy` chosen from the supported sizes is used by [browsers with no support](https://caniuse.com/#feat=srcset) for the `srcset` attribute.
87
+
88
+ The configuration option `width_viewport` allows to define the occupying width of the photos. It is used to set the `sizes` attribute. [More Information](http://alistapart.com/article/responsive-images-in-practice)
89
+
90
+ ## TODO
91
+
92
+ - allow more control on cache expiration
93
+ - allow for custom templates globally configured
94
+ - allow for templates per tag via some arguments
95
+ - block version (`Liquid::Block`) that allows to enclosure the caption
96
+ - use a more sophisticated RegExp to allow for captions with quotation marks
97
+
98
+ ## Similar Projects
99
+
100
+ - [jekyll-flickresponsive.rb](https://gist.github.com/mikka2061/e8ddb2566d90b00f990d6a39b0fd1346) using the `<picture>` tag for responsive images.
101
+ - <https://github.com/j0k3r/jekyll-flickr-photoset>
102
+ - <https://github.com/cnunciato/jekyll-flickr>
103
+ - <https://github.com/lawmurray/indii-jekyll-flickr>
104
+ - <https://github.com/tsmango/jekyll_flickr_set_tag>
105
+
106
+
107
+ ## Contributing
108
+
109
+ 1. Fork it ( https://github.com/rriemann/jekyll-flickr/fork )
110
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
111
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
112
+ 4. Push to the branch (`git push origin my-new-feature`)
113
+ 5. Create a new Pull Request
114
+
115
+
116
+ [Flickr]: https://www.flickr.com/
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require "jekyll-flickr/version"
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "jekyll-flickr"
10
+ spec.version = Jekyll::Onebox::VERSION
11
+ spec.authors = ["Robert Riemann"]
12
+ spec.email = ["robert@riemann.cc"]
13
+ spec.summary = "Liquid tag for responsive Flickr images using HTML5 srcset."
14
+ spec.homepage = "https://github.com/rriemann/jekyll-flickr"
15
+ spec.license = "MIT"
16
+
17
+ spec.required_ruby_version = ">= 2.1"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0")
20
+ spec.executables = spec.files.grep(%r!^bin/!) { |f| File.basename(f) }
21
+ # spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "jekyll-cache", "~> 1.2"
25
+ spec.add_dependency "flickraw-cached", ">= 20120701"
26
+ spec.add_dependency "flickraw", "~> 0.9.9"
27
+ spec.add_development_dependency "bundler", "~> 1.6"
28
+ spec.add_development_dependency "jekyll", ">= 3.0"
29
+ spec.add_development_dependency "rake"
30
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll-onebox/version"
4
+ require "jekyll-onebox/flickr_tag"
5
+
6
+ module Jekyll
7
+ module Flickr
8
+ end
9
+ end
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'flickraw-cached'
4
+
5
+ module Jekyll
6
+ module Flickr
7
+ class FlickrTag < Liquid::Tag
8
+
9
+ # selection of sizes from those offered by Flickr API
10
+ DEFAULT_CONFIG = {
11
+ 'widths' => [320, 640, 800, 1024, 1600],
12
+ 'width_legacy' => 800,
13
+ 'figcaption' => true,
14
+ 'license' => true,
15
+ 'caption' => true,
16
+ 'width_viewport' => '100vw'
17
+ }
18
+
19
+ # Flickr licenses from (added CC myself)
20
+ # https://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html
21
+ LICENSES = [
22
+ {
23
+ name: "All Rights Reserved", url: ""
24
+ },
25
+ {
26
+ name: "CC Attribution-NonCommercial-ShareAlike License",
27
+ url: "https://creativecommons.org/licenses/by-nc-sa/2.0/"
28
+ },
29
+ {
30
+ name: "CC Attribution-NonCommercial License",
31
+ url: "https://creativecommons.org/licenses/by-nc/2.0/"
32
+ },
33
+ {
34
+ name: "CC Attribution-NonCommercial-NoDerivs License",
35
+ url: "https://creativecommons.org/licenses/by-nc-nd/2.0/"
36
+ },
37
+ {
38
+ name: "CC Attribution License",
39
+ url: "https://creativecommons.org/licenses/by/2.0/"
40
+ },
41
+ {
42
+ name: "CC Attribution-ShareAlike License",
43
+ url: "https://creativecommons.org/licenses/by-sa/2.0/"
44
+ },
45
+ {
46
+ name: "CC Attribution-NoDerivs License",
47
+ url: "https://creativecommons.org/licenses/by-nd/2.0/",
48
+ },
49
+ {
50
+ name: "No known copyright restrictions",
51
+ url: "https://www.flickr.com/commons/usage/"
52
+ },
53
+ {
54
+ name: "United States Government Work",
55
+ url: "http://www.usa.gov/copyright.shtml"
56
+ },
57
+ {
58
+ name: "Public Domain Dedication (CC0)",
59
+ url: "https://creativecommons.org/publicdomain/zero/1.0/"
60
+ },
61
+ {
62
+ name: "Public Domain Mark",
63
+ url: "https://creativecommons.org/publicdomain/mark/1.0/"
64
+ }
65
+ ]
66
+
67
+ def initialize(tag_name, text, tokens)
68
+ super
69
+
70
+ @text = text.strip
71
+ end
72
+
73
+ def render(context)
74
+ config = DEFAULT_CONFIG.merge(context.registers[:site].config['flickr'])
75
+
76
+ match = /(?<photo_id>\d+)(\s(\"(?<caption>[^"]+)\"))?(?<attr>.*)/.match @text
77
+
78
+ photo_id = match.named_captures['photo_id']
79
+ photo_caption = match.named_captures['caption']
80
+ photo_attr = match.named_captures['attr']
81
+
82
+ cache = Jekyll::Cache::FileStore.new 'flickr'
83
+ photo_data = cache.fetch photo_id do
84
+ FlickRaw.api_key = ENV['FLICKR_API_KEY'] || config['api_key']
85
+ FlickRaw.shared_secret = ENV['FLICKR_API_SECRET'] || config['api_secret']
86
+ {
87
+ info: flickr.photos.getInfo(photo_id: photo_id),
88
+ sizes: flickr.photos.getSizes(photo_id: photo_id)
89
+ }
90
+ end
91
+
92
+ widths = config['widths'] + [config['width_legacy']]
93
+ photo_sizes = photo_data[:sizes].select{ |photo| widths.include?(photo['width'].to_i) }
94
+ photo_legacy = photo_data[:sizes].find{ |photo| photo['width'].to_i == config['width_legacy']}
95
+
96
+ srcset = photo_sizes.map{|photo| "#{photo['source']} #{photo['width']}w"}.join(", ")
97
+
98
+ sizes = unless photo_attr.include?('sizes=') then
99
+ context.registers[:site].config['flickr']['width_viewport']
100
+ else
101
+ ""
102
+ end
103
+
104
+ if photo_caption and not photo_attr.include?('alt=') then
105
+ photo_attr += " alt=\"#{photo_caption}\""
106
+ end
107
+
108
+ img_tag = "<img src=\"#{photo_legacy.source}\" srcset=\"#{srcset}\" sizes=\"#{sizes}\" #{photo_attr}>"
109
+
110
+ return img_tag if not config['figcaption']
111
+
112
+ photo_license = if config['license'] then
113
+ license = LICENSES[photo_data[:info].license.to_i]
114
+
115
+ owner_link = "&copy; Flickr/<a href=\"#{photo_data[:info]['urls'].first['_content']}\">#{photo_data[:info]['owner']['username']}</a>"
116
+
117
+ puts license.inspect
118
+
119
+ license_link = if license[:url]
120
+ "<a href=\"#{license[:url]}\">#{license[:name]}</a>"
121
+ else
122
+ license[:name]
123
+ end
124
+ "<div class=\"license\">#{owner_link} #{license_link}</div>"
125
+ else
126
+ ""
127
+ end
128
+
129
+ photo_caption = if config['caption'] and photo_caption then
130
+ "<div class=\"caption\">#{photo_caption}</div>"
131
+ else
132
+ ""
133
+ end
134
+
135
+ return img_tag if photo_license.empty? and photo_caption.empty?
136
+
137
+ return <<-HTML
138
+ <figure>
139
+ #{img_tag}
140
+ <figcaption>#{photo_caption}#{photo_license}</figcaption>
141
+ </figure>
142
+ HTML
143
+ end
144
+ end
145
+ end
146
+ end
147
+
148
+ Liquid::Template.register_tag('flickr', Jekyll::Flickr::FlickrTag)
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Onebox
5
+ VERSION = "0.1.0".freeze
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-flickr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Robert Riemann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll-cache
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: flickraw-cached
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '20120701'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '20120701'
41
+ - !ruby/object:Gem::Dependency
42
+ name: flickraw
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.9
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.9
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: jekyll
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - robert@riemann.cc
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - CHANGELOG.md
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - jekyll-flickr.gemspec
111
+ - lib/jekyll-flickr.rb
112
+ - lib/jekyll-flickr/flickr_tag.rb
113
+ - lib/jekyll-flickr/version.rb
114
+ homepage: https://github.com/rriemann/jekyll-flickr
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '2.1'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.6.14
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Liquid tag for responsive Flickr images using HTML5 srcset.
138
+ test_files: []