badpixxel-jekyll-flickr 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 775b9978bea89fbab21c5d1f23a06ff12615ea4d49c6d0b5572b8fba3674b597
4
+ data.tar.gz: 4252e5251b71c3c9f1e207379839872cff5676e06acb839d4a2dfeaf4a0a540d
5
+ SHA512:
6
+ metadata.gz: '09d3ce1e39961e6abd96ef0b80c47947e998197d082bf3063a3b13f6a7085dbc6d575333aab313ca1b0705eb42662ccdcf386f3b6efd9a40b31bc06807e5df73'
7
+ data.tar.gz: 67c335d3d6b4895650f4f6943cc82fb7c756f9ee4d0910d1f08b23dcfdd37ab93b8ee31b202dd9a3eb68ba362acba2c4e9b3f6e197059a26ec7f21560a97d658
data/.gitignore ADDED
@@ -0,0 +1,56 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ deploy:
2
+ provider: rubygems
3
+ gemspec: badpixxel-jekyll-flickr.gemspec
4
+ api_key:
5
+ secure: Bok1ntaSXwMZG+Lrd4MhzP3ksUnlgWrsNaaBUkuwuLYlGc4dfrkEKUDfrztRvtACgiK+/6WuKe6FWMJI/ifeWNi7MEXREgkqwjXFbXFXJWmlQ2reXNlxJGv4UqZGv1kmG2WnauS4hDKc9TqKA36HzJwXQpbP4KQNslvbfdPlI5ptwTshzAuSrznC6AWPvzirsBXwXag8Zu8MPlQd7MJWl3QNaOOOJgylsGOIgikaZAucnO5qPOlTANhSP6pqEhrbqozVxUWf43diFvMUcOMKwk0woyEb37TuPLg4y9IFQYqnzg/BiE24Hcb6tE/ibawclt8Kp6pReerBw+XN7lNfy7MnEA+b6B50mZM1GvQHs5MI63E361hVoi7BvJWHeBr/112Ozqv2Z9KFiGwVBOeYUabzQrzL3YkXoWzSD2DotOd1MGp8XDtOYmxrrM5a3WxuBhmxPPXYfC3yppckFwsgCFmaAkdBq3ES1+up4azRA/8rw4vZYSCtEsVV9t8xFsz8eMZCdQojqVf+J0egM9y9LR94QFpxasDATkMHJNuMO0X0nEAqqXA/NbYEP35RUmcZEkyQzUqJgDBBbaKeX2558qUndFXaT531Vs/qGfv0hvwLX6mYXCgeSOhJdkj2EDFFxnqJ7c2U3897RbnmPEEPgmEYHE+JeQSuhXSa0TL+K38=
6
+ on:
7
+ tags: true
data/GemFile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec
5
+
6
+ gem "jekyll", ENV["JEKYLL_VERSION"] if ENV["JEKYLL_VERSION"]
7
+
8
+ install_if -> { Gem.win_platform? } do
9
+ gem "tzinfo", "~> 1.2"
10
+ gem "tzinfo-data"
11
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 BadPixxel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # jekyll-flickr
2
+ A Jekyll plugin to embed Flickr Galreies &amp; Photos in your Jekyll blog
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/badpixxel-jekyll-flickr/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "badpixxel-jekyll-flickr"
7
+ spec.version = Jekyll::FLICKR_VERSION
8
+ spec.authors = ["BadPixxel"]
9
+ spec.email = ["eshop.bpaquier@gmail.com"]
10
+ spec.summary = "A Jekyll plugin to embed Flickr Sets & Photos in your Jekyll blog"
11
+ spec.homepage = "https://github.com/BadPixxel/jekyll-flickr"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.required_ruby_version = ">= 2.3.0"
18
+
19
+ spec.add_dependency "jekyll", ">= 3.7", "< 5.0"
20
+ spec.add_dependency "flickraw"
21
+
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "nokogiri", "~> 1.6"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ end
@@ -0,0 +1,147 @@
1
+ ##
2
+ ## Embed Flickr photos in a Jekyll blog.
3
+ ##
4
+ ## Copyright (C) 2015 Lawrence Murray, www.indii.org.
5
+ ## Copyright (C) 2020 BadPixxel, www.badpixxel.com.
6
+ ##
7
+ ## This program is free software; you can redistribute it and/or modify it
8
+ ## under the terms of the GNU General Public License as published by the Free
9
+ ## Software Foundation; either version 2 of the License, or (at your option)
10
+ ## any later version.
11
+ ##
12
+ require 'flickraw'
13
+ require 'shellwords'
14
+
15
+ module Jekyll
16
+
17
+ # Setup Flickr Plugin
18
+ def self.flickr_setup(site)
19
+ # Complete Configuration with defaults Parameters
20
+ FlickrConfig.resolve(site)
21
+ # Load Flickr Contents from API
22
+ FlickrLoader.setup(site)
23
+ FlickrLoader.load(site)
24
+ end
25
+
26
+ # Get Flickr Photoset from Cache
27
+ def self.flickr_get_photoset(site, photoset_name)
28
+ # Build Photoset Slug
29
+ slug = photoset_name.downcase.gsub(/ /, '-').gsub(/[^a-z\-]/, '')
30
+ # Build Photoset Path
31
+ photoset_file = File.join(site.config['flickr']['cache_dir'], "#{slug}.yml")
32
+ # Check if Photoset is Already in Cache
33
+ if !File.exists?(photoset_file)
34
+ return false
35
+ end
36
+
37
+ return Photoset.new(site, photoset_file)
38
+ end
39
+
40
+ class PhotoPost < Post
41
+ def initialize(site, base, dir, photo)
42
+ name = photo.date[0..9] + '-photo-' + photo.slug + '.md'
43
+
44
+ data = Hash.new
45
+ data['title'] = photo.title
46
+ data['shorttitle'] = photo.title
47
+ data['description'] = photo.description
48
+ data['date'] = photo.date
49
+ data['slug'] = photo.slug
50
+ data['permalink'] = File.join('/archives', photo.slug, 'index.html')
51
+ data['flickr'] = Hash.new
52
+ data['flickr']['id'] = photo.id
53
+ data['flickr']['url_full'] = photo.url_full
54
+ data['flickr']['url_thumb'] = photo.url_thumb
55
+
56
+ if site.config['flickr']['generate_frontmatter']
57
+ site.config['flickr']['generate_frontmatter'].each do |key, value|
58
+ data[key] = value
59
+ end
60
+ end
61
+
62
+ File.open(File.join('_posts', name), 'w') {|f|
63
+ f.print(YAML::dump(data))
64
+ f.print("---\n\n")
65
+ f.print(photo.gen_full_html)
66
+ }
67
+
68
+ super(site, base, dir, name)
69
+ end
70
+ end
71
+
72
+ class FlickrPageGenerator < Generator
73
+ safe true
74
+
75
+ def generate(site)
76
+ Jekyll::flickr_setup(site)
77
+ cache_dir = site.config['flickr']['cache_dir']
78
+
79
+ file_photosets = Dir.glob(File.join(cache_dir, '*.yml'))
80
+ file_photosets.each_with_index do |file_photoset, pos|
81
+ photoset = Photoset.new(site, file_photoset)
82
+ if site.config['flickr']['generate_photosets'].include? photoset.title
83
+ # generate photo pages if requested
84
+ if site.config['flickr']['generate_posts']
85
+ file_photos = Dir.glob(File.join(photoset.cache_dir, '*.yml'))
86
+ file_photos.each do |file_photo, pos|
87
+ photo = Photo.new(site, photoset, file_photo, pos)
88
+ page_photo = PhotoPost.new(site, site.source, '', photo)
89
+
90
+ # posts need to be in a _posts directory, but this means Jekyll has already
91
+ # read in photo posts from any previous run... so for each photo, update
92
+ # its associated post if it already exists, otherwise create a new post
93
+ site.posts.each_with_index do |post, pos|
94
+ if post.data['slug'] == photo.slug
95
+ site.posts.delete_at(pos)
96
+ end
97
+ end
98
+ site.posts << page_photo
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ # re-sort posts by date
105
+ site.posts.sort! {|left, right| left.date <=> right.date}
106
+ end
107
+ end
108
+
109
+ class FlickrPhotosetTag < Liquid::Tag
110
+ def initialize(tag_name, markup, tokens)
111
+ super
112
+ params = Shellwords.shellwords markup
113
+ title = params[0]
114
+ @slug = title.downcase.gsub(/ /, '-').gsub(/[^a-z\-]/, '')
115
+ end
116
+
117
+ def render(context)
118
+ site = context.registers[:site]
119
+ Jekyll::flickr_setup(site)
120
+ file_photoset = File.join(site.config['flickr']['cache_dir'], "#{@slug}.yml")
121
+ photoset = Photoset.new(site, file_photoset)
122
+ return photoset.gen_html
123
+ end
124
+ end
125
+
126
+ class FlickrFancysetTag < Liquid::Tag
127
+ def initialize(tag_name, markup, tokens)
128
+ super
129
+ params = Shellwords.shellwords markup
130
+ title = params[0]
131
+ @slug = title.downcase.gsub(/ /, '-').gsub(/[^a-z\-]/, '')
132
+ end
133
+
134
+ def render(context)
135
+ site = context.registers[:site]
136
+ Jekyll::flickr_setup(site)
137
+ file_photoset = File.join(site.config['flickr']['cache_dir'], "#{@slug}.yml")
138
+ photoset = Photoset.new(site, file_photoset)
139
+ return photoset.gen_html_fancy
140
+ end
141
+ end
142
+
143
+ end
144
+
145
+ Liquid::Template.register_tag('flickr_photoset', Jekyll::FlickrPhotosetTag)
146
+
147
+ Liquid::Template.register_tag('flickr_fancyset', Jekyll::FlickrFancysetTag)
@@ -0,0 +1,48 @@
1
+ ##
2
+ ## Embed Flickr photos in a Jekyll blog.
3
+ ##
4
+ ## Copyright (C) 2015 Lawrence Murray, www.indii.org.
5
+ ## Copyright (C) 2020 BadPixxel, www.badpixxel.com.
6
+ ##
7
+ ## This program is free software; you can redistribute it and/or modify it
8
+ ## under the terms of the GNU General Public License as published by the Free
9
+ ## Software Foundation; either version 2 of the License, or (at your option)
10
+ ## any later version.
11
+ ##
12
+
13
+ module Jekyll
14
+
15
+ FLICKR_CACHE_DIR = '_data/flickr'
16
+ FLICKR_SIZE_FULL = 'Large'
17
+ FLICKR_SIZE_THUMB = 'Small 320'
18
+
19
+ class FlickrConfig
20
+
21
+ def self.resolve(site)
22
+ # Setup Defaults Plugin Parameters
23
+ if !site.config['flickr']['cache_dir']
24
+ site.config['flickr']['cache_dir'] = FLICKR_CACHE_DIR
25
+ end
26
+ if !site.config['flickr']['size_full']
27
+ site.config['flickr']['size_full'] = FLICKR_SIZE_FULL
28
+ end
29
+ if !site.config['flickr']['size_thumb']
30
+ site.config['flickr']['size_thumb'] = FLICKR_SIZE_THUMB
31
+ end
32
+ if !site.config['flickr']['generate_posts']
33
+ site.config['flickr']['generate_posts'] = false
34
+ end
35
+ if !site.config['flickr']['generate_photosets']
36
+ site.config['flickr']['generate_photosets'] = []
37
+ end
38
+ if !site.config['flickr'].key?('use_cache')
39
+ site.config['flickr']['use_cache'] = false
40
+ end
41
+ if !site.config['flickr'].key?('flush_cache')
42
+ site.config['flickr']['flush_cache'] = false
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,59 @@
1
+ ##
2
+ ## Embed Flickr photos in a Jekyll blog.
3
+ ##
4
+ ## Copyright (C) 2015 Lawrence Murray, www.indii.org.
5
+ ## Copyright (C) 2020 BadPixxel, www.badpixxel.com.
6
+ ##
7
+ ## This program is free software; you can redistribute it and/or modify it
8
+ ## under the terms of the GNU General Public License as published by the Free
9
+ ## Software Foundation; either version 2 of the License, or (at your option)
10
+ ## any later version.
11
+ ##
12
+
13
+ module Jekyll
14
+
15
+ module FlickrFilters
16
+
17
+ # Get All tags for a Flikr PhotoSet
18
+ def flickr_ps_tags(photoset)
19
+ site = @context.registers[:site]
20
+ Jekyll::flickr_setup(site)
21
+ photoset = Jekyll::flickr_get_photoset(site, photoset)
22
+ if !photoset
23
+ return []
24
+ end
25
+
26
+ return photoset.get_tags()
27
+ end
28
+
29
+ # Get Most Used tags for a Flikr PhotoSet
30
+ def flickr_ps_top_tags(photoset, count = 10)
31
+ site = @context.registers[:site]
32
+ Jekyll::flickr_setup(site)
33
+ photoset = Jekyll::flickr_get_photoset(site, photoset)
34
+ if !photoset
35
+ return []
36
+ end
37
+
38
+ return photoset.get_top_tags(count)
39
+ end
40
+
41
+
42
+ # Get Flikr PhotoSet Photos
43
+ def flickr_ps_photos(photoset, max = false)
44
+ site = @context.registers[:site]
45
+ Jekyll::flickr_setup(site)
46
+ photoset = Jekyll::flickr_get_photoset(site, photoset)
47
+ if !photoset
48
+ return []
49
+ end
50
+
51
+ return photoset.get_photos_array(max)
52
+ end
53
+
54
+
55
+ end
56
+
57
+ end
58
+
59
+ Liquid::Template.register_filter(Jekyll::FlickrFilters)
@@ -0,0 +1,84 @@
1
+ ##
2
+ ## Embed Flickr photos in a Jekyll blog.
3
+ ##
4
+ ## Copyright (C) 2015 Lawrence Murray, www.indii.org.
5
+ ## Copyright (C) 2020 BadPixxel, www.badpixxel.com.
6
+ ##
7
+ ## This program is free software; you can redistribute it and/or modify it
8
+ ## under the terms of the GNU General Public License as published by the Free
9
+ ## Software Foundation; either version 2 of the License, or (at your option)
10
+ ## any later version.
11
+ ##
12
+
13
+ require 'flickraw'
14
+
15
+ module Jekyll
16
+
17
+ class FlickrLoader
18
+
19
+ attr_accessor :is_loaded
20
+
21
+ @@is_loaded = false
22
+
23
+ def self.load(site)
24
+
25
+ if @@is_loaded
26
+ puts "Flickr: Photosets Already Loaded"
27
+ return
28
+ end
29
+
30
+ # Setup Defaults Plugin Parameters
31
+ if not self.is_ready(site)
32
+ puts "Flickr: Using Cached Photosets"
33
+ return
34
+ end
35
+ puts "Flickr: Update of Photosets cache"
36
+
37
+ # Fetch list of Photosets
38
+ nsid = flickr.people.findByUsername(:username => site.config['flickr']['screen_name']).id
39
+ flickr_photosets = flickr.photosets.getList(:user_id => nsid)
40
+
41
+ # Update All Photosets Cache
42
+ flickr_photosets.each do |flickr_photoset|
43
+ photoset = Photoset.new(site, flickr_photoset)
44
+ puts "Flickr: Update Photosets #{flickr_photoset.title} (#{photoset.photos_from_cache} In Cache, #{photoset.photos_from_flickr} Loaded from Flickr)"
45
+ end
46
+
47
+ @@is_loaded = true
48
+ puts "Flickr: Photosets cache updated"
49
+
50
+ end
51
+
52
+ def self.is_ready(site)
53
+ # Check if Plugin Parameters Allow Cache Loading
54
+ if site.config['flickr']['use_cache']
55
+ return false
56
+ end
57
+ if !site.config['flickr']['cache_dir']
58
+ return false
59
+ end
60
+
61
+ return true
62
+ end
63
+
64
+ def self.setup(site)
65
+
66
+ cache_dir = site.config['flickr']['cache_dir']
67
+ # Clear any existing cache if requested
68
+ if site.config['flickr']['flush_cache']
69
+ if Dir.exists?(cache_dir)
70
+ FileUtils.rm_rf(cache_dir)
71
+ end
72
+ end
73
+ # Ensure Cache Dir Exists
74
+ if !Dir.exists?(cache_dir)
75
+ Dir.mkdir(cache_dir)
76
+ end
77
+ # Populate cache from Flickr
78
+ FlickRaw.api_key = site.config['flickr']['api_key']
79
+ FlickRaw.shared_secret = site.config['flickr']['api_secret']
80
+ end
81
+
82
+ end
83
+
84
+ end
@@ -0,0 +1,183 @@
1
+ ##
2
+ ## Embed Flickr photos in a Jekyll blog.
3
+ ##
4
+ ## Copyright (C) 2015 Lawrence Murray, www.indii.org.
5
+ ## Copyright (C) 2020 BadPixxel, www.badpixxel.com.
6
+ ##
7
+ ## This program is free software; you can redistribute it and/or modify it
8
+ ## under the terms of the GNU General Public License as published by the Free
9
+ ## Software Foundation; either version 2 of the License, or (at your option)
10
+ ## any later version.
11
+ ##
12
+
13
+ require 'flickraw'
14
+
15
+ module Jekyll
16
+
17
+ class Photo
18
+ attr_accessor :id, :title, :slug, :date, :description, :tags, :date_update, :date_update_str, :url_full, :url_thumb, :cache_file, :position, :from_cache
19
+
20
+ def initialize(site, photoset, photo, pos)
21
+ self.from_cache = false
22
+ if photo.is_a? String
23
+ self.cache_load(photo)
24
+ else
25
+ self.flickr_load(site, photoset, photo, pos)
26
+ end
27
+ end
28
+
29
+ def flickr_load(site, photoset, flickr_photo, pos)
30
+
31
+ # Check if Photo is Alreday in cache & not outdated
32
+ if !self.cache_outdated(photoset, flickr_photo)
33
+ photo = File.join(photoset.cache_dir, "#{flickr_photo.id}.yml")
34
+ self.cache_load(photo)
35
+ return
36
+ end
37
+
38
+ # init
39
+ self.id = flickr_photo.id
40
+ self.title = flickr_photo.title
41
+ self.slug = self.title.downcase.gsub(/ /, '-').gsub(/[^a-z\-]/, '') + '-' + self.id
42
+ self.date = ''
43
+ self.description = ''
44
+ self.tags = Array.new
45
+ self.url_full = ''
46
+ self.url_thumb = ''
47
+ self.cache_file = File.join(photoset.cache_dir, "#{self.id}.yml")
48
+ self.position = pos
49
+ self.date_update = flickr_photo.lastupdate
50
+ self.date_update_str = DateTime.strptime(flickr_photo.lastupdate, '%s').to_s
51
+
52
+ # sizes request
53
+ flickr_sizes = flickr.photos.getSizes(:photo_id => self.id)
54
+ if flickr_sizes
55
+ size_full = flickr_sizes.find {|s| s.label == site.config['flickr']['size_full']}
56
+ if size_full
57
+ self.url_full = size_full.source
58
+ end
59
+
60
+ size_thumb = flickr_sizes.find {|s| s.label == site.config['flickr']['size_thumb']}
61
+ if size_thumb
62
+ self.url_thumb = size_thumb.source
63
+ end
64
+ end
65
+
66
+ # other info request
67
+ flickr_info = flickr.photos.getInfo(:photo_id => self.id)
68
+ if flickr_info
69
+ self.date = DateTime.strptime(flickr_info.dates.posted, '%s').to_s
70
+ self.description = flickr_info.description
71
+ flickr_info.tags.each do |tag|
72
+ self.tags << tag.raw
73
+ end
74
+ end
75
+
76
+ cache_store
77
+ end
78
+
79
+ def cache_exists(photoset, flickr_photo)
80
+ # Check if Photo is Already in Cache
81
+ return File.exists?(File.join(photoset.cache_dir, "#{flickr_photo.id}.yml"))
82
+ end
83
+
84
+ def cache_outdated(photoset, flickr_photo)
85
+ cache_file = File.join(photoset.cache_dir, "#{flickr_photo.id}.yml")
86
+ # Check if Photo is Already in Cache
87
+ if !File.exists?(cache_file)
88
+ return true
89
+ end
90
+ # Load Cached Values
91
+ cached = YAML::load(File.read(cache_file))
92
+ if !cached["date_update"] or (cached["date_update"] != flickr_photo.lastupdate)
93
+ return true
94
+ end
95
+
96
+ return false
97
+ end
98
+
99
+ def cache_load(file)
100
+ cached = YAML::load(File.read(file))
101
+ self.id = cached['id']
102
+ self.title = cached['title']
103
+ self.slug = cached['slug']
104
+ self.date = cached['date']
105
+ self.description = cached['description']
106
+ self.tags = cached['tags']
107
+ self.url_full = cached['url_full']
108
+ self.url_thumb = cached['url_thumb']
109
+ self.cache_file = cached['cache_file']
110
+ self.position = cached['position']
111
+ self.date_update = cached['date_update']
112
+ self.date_update_str = cached['date_update_str']
113
+ self.from_cache = true
114
+ end
115
+
116
+ def cache_store
117
+ cached = Hash.new
118
+ cached['id'] = self.id
119
+ cached['title'] = self.title
120
+ cached['slug'] = self.slug
121
+ cached['date'] = self.date
122
+ cached['description'] = self.description
123
+ cached['tags'] = self.tags
124
+ cached['url_full'] = self.url_full
125
+ cached['url_thumb'] = self.url_thumb
126
+ cached['cache_file'] = self.cache_file
127
+ cached['position'] = self.position
128
+ cached['date_update'] = self.date_update
129
+ cached['date_update_str'] = self.date_update_str
130
+
131
+ File.open(self.cache_file, 'w') {|f| f.print(YAML::dump(cached))}
132
+ end
133
+
134
+ def to_liquid
135
+
136
+ tags_hash = []
137
+ self.tags.each do |tag|
138
+ tags_hash += [tag.hash]
139
+ end
140
+
141
+ return [
142
+ 'id' => self.id,
143
+ 'title' => self.title,
144
+ 'date' => self.date,
145
+ 'decription' => self.description,
146
+ 'tags' => self.tags,
147
+ 'tags_hash' => tags_hash,
148
+ 'url_full' => self.url_full,
149
+ 'url_thumb' => self.url_thumb,
150
+ 'position' => self.position,
151
+ 'date_update' => self.date_update,
152
+ ]
153
+ end
154
+
155
+ def gen_thumb_html
156
+ content = ''
157
+ if self.url_full and self.url_thumb
158
+ content = "<a href=\"#{self.url_full}\" data-lightbox=\"photoset\"><img src=\"#{self.url_thumb}\" alt=\"#{self.title}\" title=\"#{self.title}\" class=\"photo thumbnail\" width=\"75\" height=\"75\" /></a>\n"
159
+ end
160
+ return content
161
+ end
162
+
163
+ def gen_thumb_html_fancy
164
+ content = ''
165
+ if self.url_full and self.url_thumb
166
+ content = "<a href=\"#{self.url_full}\" data-fancybox=\"photoset\"><img src=\"#{self.url_thumb}\" alt=\"#{self.title}\" title=\"#{self.title}\" class=\"img-fluid thumbnail\" /></a>\n"
167
+ end
168
+ return content
169
+ end
170
+
171
+ def gen_full_html
172
+ content = ''
173
+ if self.url_full and self.url_thumb
174
+ content = "<p><a href=\"#{self.url_full}\" data-lightbox=\"photoset\"><img src=\"#{self.url_full}\" alt=\"#{self.title}\" title=\"#{self.title}\" class=\"photo full\" /></a></p>\n<p>#{self.description}</p>\n"
175
+ if self.tags
176
+ content += "<p>Tagged <i>" + self.tags.join(", ") + ".</i></p>\n"
177
+ end
178
+ end
179
+ return content
180
+ end
181
+ end
182
+
183
+ end
@@ -0,0 +1,194 @@
1
+ ##
2
+ ## Embed Flickr photos in a Jekyll blog.
3
+ ##
4
+ ## Copyright (C) 2015 Lawrence Murray, www.indii.org.
5
+ ## Copyright (C) 2020 BadPixxel, www.badpixxel.com.
6
+ ##
7
+ ## This program is free software; you can redistribute it and/or modify it
8
+ ## under the terms of the GNU General Public License as published by the Free
9
+ ## Software Foundation; either version 2 of the License, or (at your option)
10
+ ## any later version.
11
+ ##
12
+
13
+ require 'flickraw'
14
+
15
+ module Jekyll
16
+
17
+ class Photoset
18
+ attr_accessor :id, :title, :description, :date_update, :date_update_str, :slug, :cache_dir, :cache_file, :photos, :photos_from_cache, :photos_from_flickr
19
+
20
+ def initialize(site, photoset)
21
+ self.photos = Array.new
22
+ self.photos_from_cache = 0
23
+ self.photos_from_flickr = 0
24
+ if photoset.is_a? String
25
+ self.cache_load(site, photoset)
26
+ else
27
+ self.flickr_load(site, photoset)
28
+ end
29
+ self.photos.sort! {|left, right| left.position <=> right.position}
30
+ end
31
+
32
+ # Load Photoset from Flckr (if needed)
33
+ def flickr_load(site, flickr_photoset)
34
+ self.id = flickr_photoset.id
35
+ self.title = flickr_photoset.title
36
+ self.description = flickr_photoset.description
37
+ self.date_update = flickr_photoset.date_update
38
+ self.date_update_str = DateTime.strptime(flickr_photoset.date_update, '%s').to_s
39
+ self.slug = self.title.downcase.gsub(/ /, '-').gsub(/[^a-z\-]/, '')
40
+ self.cache_dir = File.join(site.config['flickr']['cache_dir'], self.slug)
41
+ self.cache_file = File.join(site.config['flickr']['cache_dir'], "#{self.slug}.yml")
42
+
43
+ # write to cache
44
+ if self.cache_outdated(flickr_photoset)
45
+ self.cache_store
46
+ end
47
+
48
+ # create cache directory
49
+ if !Dir.exists?(self.cache_dir)
50
+ Dir.mkdir(self.cache_dir)
51
+ end
52
+
53
+ # photos
54
+ flickr_photos = flickr.photosets.getPhotos(:photoset_id => self.id, :extras => "date_taken, last_update").photo
55
+ flickr_photos.each_with_index do |flickr_photo, pos|
56
+ photo = Photo.new(site, self, flickr_photo, pos)
57
+ self.photos << photo
58
+ if photo.from_cache
59
+ self.photos_from_cache += 1
60
+ else
61
+ self.photos_from_flickr += 1
62
+ end
63
+ end
64
+ end
65
+
66
+ # Check if Photoset Cachge is Outdated
67
+ def cache_outdated(flickr_photoset)
68
+ # Check if Photoset is Already in Cache
69
+ if !File.exists?(self.cache_file)
70
+ return true
71
+ end
72
+ # Load Cached Values
73
+ cached = YAML::load(File.read(cache_file))
74
+ if !cached["date_update"] or (cached["date_update"] != flickr_photoset.date_update)
75
+ return true
76
+ end
77
+
78
+ return false
79
+ end
80
+
81
+ # Load Photoset from Cache
82
+ def cache_load(site, file)
83
+ cached = YAML::load(File.read(file))
84
+ self.id = cached['id']
85
+ self.title = cached['title']
86
+ self.description = cached['description']
87
+ self.date_update = cached['date_update']
88
+ self.date_update_str = cached['date_update_str']
89
+ self.slug = cached['slug']
90
+ self.cache_dir = cached['cache_dir']
91
+ self.cache_file = cached['cache_file']
92
+
93
+ file_photos = Dir.glob(File.join(self.cache_dir, '*.yml'))
94
+ file_photos.each_with_index do |file_photo, pos|
95
+ self.photos << Photo.new(site, self, file_photo, pos)
96
+ end
97
+ end
98
+
99
+ # Store Photoset in Cache
100
+ def cache_store
101
+ cached = Hash.new
102
+ cached['id'] = self.id
103
+ cached['title'] = self.title
104
+ cached['description'] = self.description
105
+ cached['date_update'] = self.date_update
106
+ cached['date_update_str'] = self.date_update_str
107
+ cached['slug'] = self.slug
108
+ cached['cache_dir'] = self.cache_dir
109
+ cached['cache_file'] = self.cache_file
110
+
111
+ File.open(self.cache_file, 'w') {|f| f.print(YAML::dump(cached))}
112
+ end
113
+
114
+ # Get List of Most used tags
115
+ def get_top_tags(count)
116
+ # Build List of tags [ "tag" => count ]
117
+ all_tags = {}
118
+ self.photos.each do |photo|
119
+ photo.tags.each do |tag|
120
+ if all_tags.has_key?(tag)
121
+ all_tags[tag] += 1
122
+ else
123
+ all_tags[tag] = 1
124
+ end
125
+ end
126
+ end
127
+ # Sort & Filter tags
128
+ sorted_tags = all_tags.sort_by {|_key, value| value}.reverse.first(count).to_h
129
+ # Build Hashed Tags List
130
+ hashed_tags = []
131
+ sorted_tags.each do |tag_str, count|
132
+ hashed_tags += [ "tag" => tag_str, "hash" => tag_str.hash, "count" => count ]
133
+ end
134
+
135
+ return hashed_tags
136
+ end
137
+
138
+ # Get List of All Photoset Tags
139
+ def get_tags()
140
+ # Build List of tags [ "tag" => count ]
141
+ all_tags = {}
142
+ self.photos.each do |photo|
143
+ photo.tags.each do |tag|
144
+ if all_tags.has_key?(tag)
145
+ all_tags[tag] += 1
146
+ else
147
+ all_tags[tag] = 1
148
+ end
149
+ end
150
+ end
151
+ # Build Hashed Tags List
152
+ hashed_tags = []
153
+ all_tags.each do |tag_str, count|
154
+ hashed_tags += [ "tag" => tag_str, "hash" => tag_str.hash, "count" => count ]
155
+ end
156
+
157
+ return hashed_tags
158
+ end
159
+
160
+ # Get List of All Photoset Photos
161
+ def get_photos_array(max = false)
162
+ # Build List of Photos [ "tag" => count ]
163
+ if max != false
164
+ photos = self.photos.first(max)
165
+ else
166
+ photos = self.photos
167
+ end
168
+
169
+ collection = []
170
+ photos.each do |photo|
171
+ collection += photo.to_liquid
172
+ end
173
+
174
+ return collection
175
+ end
176
+
177
+ def gen_html
178
+ content = ''
179
+ self.photos.each do |photo|
180
+ content += photo.gen_thumb_html
181
+ end
182
+ return content
183
+ end
184
+
185
+ def gen_html_fancy
186
+ content = ''
187
+ self.photos.each do |photo|
188
+ content += photo.gen_thumb_html_fancy
189
+ end
190
+ return content
191
+ end
192
+ end
193
+
194
+ end
@@ -0,0 +1,3 @@
1
+ module Jekyll
2
+ FLICKR_VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: badpixxel-jekyll-flickr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - BadPixxel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.7'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.7'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: flickraw
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: nokogiri
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.6'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.6'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ description:
90
+ email:
91
+ - eshop.bpaquier@gmail.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - ".travis.yml"
98
+ - GemFile
99
+ - LICENSE
100
+ - README.md
101
+ - badpixxel-jekyll-flickr.gemspec
102
+ - lib/badpixxel-jekyll-flickr.rb
103
+ - lib/badpixxel-jekyll-flickr/config.rb
104
+ - lib/badpixxel-jekyll-flickr/filters.rb
105
+ - lib/badpixxel-jekyll-flickr/loader.rb
106
+ - lib/badpixxel-jekyll-flickr/photo.rb
107
+ - lib/badpixxel-jekyll-flickr/photoset.rb
108
+ - lib/badpixxel-jekyll-flickr/version.rb
109
+ homepage: https://github.com/BadPixxel/jekyll-flickr
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: 2.3.0
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.0.6
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: A Jekyll plugin to embed Flickr Sets & Photos in your Jekyll blog
132
+ test_files: []