jekyll-flickr 0.2.0 → 0.2.2

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
  SHA256:
3
- metadata.gz: 881a1741332d21f044fadeecdb3fa58dab7e1ab16f9e6479de353543deca1014
4
- data.tar.gz: a4db748b22cd0a44aa7e649dca5b518aac1fd3e5b53dc4cb0cc9f5d54d729326
3
+ metadata.gz: d94b1b8306a77dc6119b4ab96551a1fbdd974c29d38315440199133a49033e86
4
+ data.tar.gz: 27437b172e95945596f9961f7f28bc53cc7e14ae9469bd4fc98ed9a3962a7adb
5
5
  SHA512:
6
- metadata.gz: 9c1fe75600c0451107d435ee325889ef0317935329652d1e38e35993270bb1dc9afee2364feef7383ff3b865e052044e183b4a9ffd7c0ad11baf9ba0a50645f7
7
- data.tar.gz: f24e90e92c7c4cda30a8d1ad83d7d34d5fb8b63df36058402c8eee799571b6155c7c5a71d4ffae560e7045163a78e200654b969b768f7b77ae0639dfd570ee7f
6
+ metadata.gz: 6e6b34b03b0416f5f93ccc45f832ac218f630304ac49e0830243b445072ab2a12c89b7b00de2e2a90004af14fd60291ec5e96adafe36af14967e1286b8cdd206
7
+ data.tar.gz: 7bdc1f8170ac75289b147f38b60f02b3982f2659f40a2dbf41bff91f10a2f57aea67e389d0b0269bfa5800341321aa8654b29bb1d2d6b232166f0e84549e523e
data/CHANGELOG.md CHANGED
@@ -1,6 +1,15 @@
1
1
  ## HEAD
2
2
 
3
- ## master 0.2.0 / 2021-02-25
3
+ ## 0.2.2 / 2025-08-01
4
+
5
+ * fix: load licenses dynamically from flickr after the script broke due to outdated hardcoded licenses
6
+
7
+ ## 0.2.1 / 2024-01-01
8
+
9
+ * fix: change cache name according to recommendation from <https://jekyllrb.com/tutorials/cache-api/>
10
+ * feature: Add flexibility to searching for the right picture width and some minor issues (courtesy of <akarwande@coredigital.com>)
11
+
12
+ ## 0.2.0 / 2021-02-25
4
13
 
5
14
  * dependencies: require Jekyll 4.x and use gem flickr instead of flickraw
6
15
  * use native Jekyll cache API (<https://jekyllrb.com/tutorials/cache-api/>) instead of jekyll-cache
@@ -5,6 +5,7 @@ require 'flickr'
5
5
  module Jekyll
6
6
  module Flickr
7
7
  class FlickrTag < Liquid::Tag
8
+ CACHE_NAME = "Jekyll::Flickr::FlickrTag"
8
9
 
9
10
  # selection of sizes from those offered by Flickr API
10
11
  DEFAULT_CONFIG = {
@@ -16,54 +17,6 @@ module Jekyll
16
17
  'width_viewport' => '100vw'
17
18
  }
18
19
 
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
20
  def initialize(tag_name, text, tokens)
68
21
  super
69
22
 
@@ -78,7 +31,14 @@ module Jekyll
78
31
  end
79
32
 
80
33
  def cache
81
- @@cache ||= Jekyll::Cache.new("flickr")
34
+ @@cache ||= Jekyll::Cache.new(CACHE_NAME)
35
+ end
36
+
37
+ def licenses
38
+ @@licenses ||= begin
39
+ # https://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html
40
+ @@licenses = flickr.photos.licenses.getInfo.sort_by{ |license| license.id.to_i }
41
+ end
82
42
  end
83
43
 
84
44
  def config
@@ -87,7 +47,7 @@ module Jekyll
87
47
 
88
48
  def render(context)
89
49
 
90
- match = /(?<photo_id>\d+)(\s(\"(?<caption>[^"]+)\"))?(?<attr>.*)/.match @text
50
+ match = /(?<photo_id>\d+)(\s(\"(?<caption>[^"]*)\"))?(?<attr>.*)/.match @text
91
51
 
92
52
  photo_id = match.named_captures['photo_id']
93
53
  photo_caption = match.named_captures['caption']
@@ -104,6 +64,25 @@ module Jekyll
104
64
  photo_sizes = photo_data[:sizes].select{ |photo| widths.include?(photo['width'].to_i) }
105
65
  photo_legacy = photo_data[:sizes].find{ |photo| photo['width'].to_i == config['width_legacy']} || photo_data[:sizes].find{ |photo| photo['label'] == 'Original'}
106
66
 
67
+ # if these sizes are not found, pick the one closes to width_legacy
68
+ unless photo_legacy
69
+ candidate = nil
70
+ smallest_delta = nil
71
+ photo_data[:sizes].each do |photo|
72
+ current_delta = (photo['width'].to_i - config['width_legacy']).abs
73
+ if !smallest_delta || (current_delta < smallest_delta)
74
+ candidate = photo
75
+ smallest_delta = current_delta
76
+ end
77
+ end
78
+ photo_legacy = candidate
79
+ end
80
+
81
+ # if no photo is found return
82
+ unless photo_legacy
83
+ return ""
84
+ end
85
+
107
86
  srcset = photo_sizes.map{|photo| "#{photo['source']} #{photo['width']}w"}.join(", ")
108
87
 
109
88
  sizes = unless photo_attr.include?('sizes=') then
@@ -118,10 +97,10 @@ module Jekyll
118
97
 
119
98
  img_tag = "<img class=\"flickr\" src=\"#{photo_legacy.source}\" srcset=\"#{srcset}\" sizes=\"#{sizes}\" #{photo_attr}>"
120
99
 
121
- return img_tag if not config['figcaption']
100
+ return compute_html_tag(img_tag) if not config['figcaption']
122
101
 
123
102
  photo_license = if config['license'] then
124
- license = LICENSES[photo_data[:info].license.to_i]
103
+ license = licenses[photo_data[:info].license.to_i]
125
104
 
126
105
  owner_link = "&copy; Flickr/<a href=\"#{photo_data[:info]['urls'].first['_content']}\">#{photo_data[:info]['owner']['username']}</a>"
127
106
 
@@ -141,12 +120,24 @@ module Jekyll
141
120
  ""
142
121
  end
143
122
 
144
- return img_tag if photo_license.empty? and photo_caption.empty?
123
+ return compute_html_tag(img_tag) if photo_license.empty? and photo_caption.empty?
145
124
 
146
125
  return <<-HTML
147
126
  <figure class="flickr">
148
127
  #{img_tag}
149
128
  <figcaption>#{photo_caption}#{photo_license}</figcaption>
129
+ </figure>
130
+ HTML
131
+ end
132
+
133
+ #######
134
+ private
135
+ #######
136
+
137
+ def compute_html_tag(img_tag)
138
+ return <<-HTML
139
+ <figure class="flickr">
140
+ #{img_tag}
150
141
  </figure>
151
142
  HTML
152
143
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Flickr
5
- VERSION = "0.2.0".freeze
5
+ VERSION = "0.2.2".freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-flickr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Riemann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-25 00:00:00.000000000 Z
11
+ date: 2025-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: flickr
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubygems_version: 3.0.1
111
+ rubygems_version: 3.5.22
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: Liquid tag for responsive Flickr images using HTML5 srcset.