jekyll-linkpreview 0.6.0.rc1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c51945d7da1fdd7145948dffd3f991f1675a1c8dc0f64f3a44d19afc700fd3f
4
- data.tar.gz: e18b2a9aa699e6d6208343790cf7e548fee7942f51cb197f87e8db36077b4394
3
+ metadata.gz: 3644c879680eba2cb17840f40258ec2adeb0493505ca28572cdcadcc72c87ced
4
+ data.tar.gz: 3925c9a5330bc589b239908cde01dc6be7493d05d35bf6bf2f8e52e3538b643a
5
5
  SHA512:
6
- metadata.gz: b73fa9cdc4ef0ef09906df15b56563f7c048af2c5ade7e78a87d1938f4654022f3073d243a32b4d5d11a62ba50622d9914b26a0cabe14a98156e08285452e8ea
7
- data.tar.gz: 654a1d448bc7c74785beba8c6cfb1e2d6303e7e4db63b341955ee029ec10309334cbc03297b93666b55d804d4a8e9540968041437c8825f656e1f60040f0814e
6
+ metadata.gz: 4246f72fc2c59ad23149b2c187864533f0fe85e09d1ca7f84feef875ad2404e6861aa6a37255f3ec3e76d2edff367fb5a6061d3f8c497c117edbdafba9801a5f
7
+ data.tar.gz: 689f9e31a23fb6846db6cb4854adabc464a890816418a988a1732d5cc9b4e34bc7df143774ec274e693d66f51d9af5d41b52ec731b8d3dab980afcd816378e0c
@@ -15,6 +15,9 @@ jobs:
15
15
  uses: actions/checkout@v3
16
16
  with:
17
17
  fetch-depth: 2
18
+ # See https://github.com/actions/runner-images/issues/6775.
19
+ - name: Suppress 'detected dubious ownership' error.
20
+ run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
18
21
  - id: check-release
19
22
  name: Decide whether to release
20
23
  run: |
@@ -34,6 +37,9 @@ jobs:
34
37
  steps:
35
38
  - name: Checkout
36
39
  uses: actions/checkout@v3
40
+ # See https://github.com/actions/runner-images/issues/6775.
41
+ - name: Suppress 'detected dubious ownership' error.
42
+ run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
37
43
  - env:
38
44
  RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
39
45
  name: Set credentials for RubyGems
@@ -43,7 +49,7 @@ jobs:
43
49
  chmod 0600 ~/.gem/credentials
44
50
  - name: Configure git
45
51
  run: |
46
- git config --global user.email "yusuke.nishioka.0713@gmail..com"
52
+ git config --global user.email "yusuke.nishioka.0713@gmail.com"
47
53
  git config --global user.name "Yusuke Nishioka"
48
54
  - name: Install dependencies
49
55
  run: bundle install
@@ -1,5 +1,11 @@
1
1
  name: Test
2
- on: [push]
2
+ on:
3
+ pull_request:
4
+ branches:
5
+ - master
6
+ push:
7
+ branches:
8
+ - master
3
9
  jobs:
4
10
  test:
5
11
  container:
@@ -7,7 +13,7 @@ jobs:
7
13
  runs-on: ubuntu-latest
8
14
  strategy:
9
15
  matrix:
10
- ruby: ["2.7", "3.1"]
16
+ ruby: ["2.7", "3.1", "3.2"]
11
17
  appraisal:
12
18
  - jekyll-35
13
19
  - jekyll-36
@@ -28,9 +34,29 @@ jobs:
28
34
  appraisal: jekyll-37
29
35
  - ruby: "3.1"
30
36
  appraisal: jekyll-38
37
+ - ruby: "3.2"
38
+ appraisal: jekyll-35
39
+ - ruby: "3.2"
40
+ appraisal: jekyll-36
41
+ - ruby: "3.2"
42
+ appraisal: jekyll-37
43
+ - ruby: "3.2"
44
+ appraisal: jekyll-38
31
45
  steps:
32
46
  - name: Checkout
33
47
  uses: actions/checkout@v3
48
+ # See https://github.com/actions/runner-images/issues/6775.
49
+ - name: Suppress 'detected dubious ownership' error
50
+ run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
51
+ - if: matrix.ruby == '2.7'
52
+ name: Update RubyGems version
53
+ # sass-embedded 1.57.1, which is one of dependencies of jekyll-sass-converter 3.0,
54
+ # requires rubygems version >= 3.3.22
55
+ # (see https://jekyllrb.com/news/2022/12/21/jekyll-sass-converter-3.0-released/
56
+ # for the jekyll-sass-converter 3.0 release).
57
+ # Just running `gem update --system` upgrades rubygems version to '>= 2.4',
58
+ # which appraisal 2.4.1 can't work with.
59
+ run: gem update --system 3.3.22
34
60
  - name: Install dependencies
35
61
  run: bundle install
36
62
  - name: Install dependencies for each appraisal
data/Gemfile CHANGED
@@ -2,3 +2,12 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in jekyll-linkpreview.gemspec
4
4
  gemspec
5
+
6
+ # The issue that appraisal 2.4.1 can't work with bundler >= 2.4 was solved
7
+ # (see https://github.com/thoughtbot/appraisal/issues/199 for details),
8
+ # but a new version has not been released yet as of Apr 2023.
9
+ # As it's not possible to install a gem from a git repository in the gemspec file,
10
+ # appraisal is being installed in Gemfile.
11
+ group :development do
12
+ gem 'appraisal', git: 'https://github.com/thoughtbot/appraisal'
13
+ end
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Jekyll::Linkpreview
2
2
 
3
- [![Build Status](https://travis-ci.com/ysk24ok/jekyll-linkpreview.svg?branch=master)](https://travis-ci.com/ysk24ok/jekyll-linkpreview)
3
+ [![Test](https://github.com/ysk24ok/jekyll-linkpreview/actions/workflows/test.yaml/badge.svg)](https://github.com/ysk24ok/jekyll-linkpreview/actions/workflows/test.yaml)
4
+ [![Release](https://github.com/ysk24ok/jekyll-linkpreview/actions/workflows/release.yaml/badge.svg)](https://github.com/ysk24ok/jekyll-linkpreview/actions/workflows/release.yaml)
4
5
 
5
6
  Jekyll plugin to generate link preview by `{% linkpreview %}` tag. The plugin fetches [Open Graph protocol](http://ogp.me/) metadata of the designated page to generate preview. The og properties are saved as JSON for caching and it is used when rebuilding the site.
6
7
 
@@ -49,28 +50,53 @@ You can override the default templates used for generating previews, both in cas
49
50
 
50
51
  ### Template for pages where Open Graph protocol metadata exists
51
52
 
52
- 1. Place `linkpreview.html` file inside `_includes/` folder of your Jekyll site (`_includes/linkpreview.html`)
53
+ 1. Place `linkpreview.html` file inside `_includes/` folder of your Jekyll site (`_includes/linkpreview.html`)
53
54
  * The folder is the same one you would store files for use with `{% include fragment.html %}` tag.
54
55
  Therefore, it *must* be under the [site's source](https://jekyllrb.com/docs/configuration/options/).
55
56
 
56
- 2. Use built-in variables to extract data which you would like to render. Available variables are:
57
- * **link_url** i.e. `{{ link_url }}`
58
- * **link_title** i.e. `{{ link_title }}`
59
- * **link_image** i.e. `{{ link_image }}`
60
- * **link_description** i.e. `{{ link_description }}`
61
- * **link_domain** i.e. `{{ link_domain }}`
57
+ 2. Use built-in variables to extract data which you would like to render. Available variables are:
58
+ * basic metadata
59
+ * `{{ title }}` for `og:title`
60
+ * `{{ type }}` for `og:type`
61
+ * `{{ image }}` for `og:image`
62
+ * `{{ url }}` for `og:url`
63
+ * optional metadata
64
+ * `{{ description }}` for `og:description`
65
+ * `{{ determiner }}` for `og:determiner`
66
+ * `{{ locale }}` for `og:locale`
67
+ * `{{ locale_alternate }}` for `og:locale:alternate`
68
+ * `{{ site_name }}` for `og:site_name`
69
+ * image
70
+ * `{{ image }}` for `og:image`
71
+ * `{{ image_secure_url }}` for `og:image:secure_url`
72
+ * `{{ image_type }}` for `og:image:type`
73
+ * `{{ image_width }}` for `og:image:width`
74
+ * `{{ image_height }}` for `og:image:height`
75
+ * `{{ image_alt }}` for `og:image:alt`
76
+ * video
77
+ * `{{ video }}` for `og:video`
78
+ * `{{ video_secure_url }}` for `og:video:secure_url`
79
+ * `{{ video_type }}` for `og:video:type`
80
+ * `{{ video_width }}` for `og:video:width`
81
+ * `{{ video_height }}` for `og:video:height`
82
+ * audio
83
+ * `{{ audio }}` for `og:audio`
84
+ * `{{ audio_secure_url }}` for `og:audio:secure_url`
85
+ * `{{ audio_type }}` for `og:audio:type`
86
+ * non og metadata
87
+ * `{{ domain }}`
62
88
 
63
89
  ### Template for pages where Open Graph protocol metadata does not exist
64
90
 
65
91
  1. Place `linkpreview_nog.html` file inside `_includes/` folder of your Jekyll site (`_includes/linkpreview_nog.html`)
66
- * The folder is the same one you would store files for use with `{% include fragment.html %}` tag.
67
- Therefore, it *must* be under the [site's source](https://jekyllrb.com/docs/configuration/options/).
68
-
69
- 2. Use built-in variables to extract data which you would like to render. Available variables are:
70
- * **link_url** i.e. `{{ link_url }}`
71
- * **link_title** i.e. `{{ link_title }}`
72
- * **link_description** i.e. `{{ link_description }}`
73
- * **link_domain** i.e. `{{ link_domain }}`
92
+ * The folder is the same one you would store files for use with `{% include fragment.html %}` tag.
93
+ Therefore, it *must* be under the [site's source](https://jekyllrb.com/docs/configuration/options/).
94
+
95
+ 2. Use built-in variables to extract data which you would like to render. Available variables are:
96
+ * `{{ title }}`
97
+ * `{{ url }}`
98
+ * `{{ description }}`
99
+ * `{{ domain }}`
74
100
 
75
101
  ## Development
76
102
 
@@ -24,6 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rake", "~> 12.3.3"
25
25
  spec.add_development_dependency "rspec", "~> 3.0"
26
26
  spec.add_development_dependency "rspec-parameterized", "~> 0.5.2"
27
- spec.add_development_dependency "appraisal", "~> 2.2.0"
28
27
  spec.add_development_dependency "wwtd", "~> 1.4.1"
29
28
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Linkpreview
3
- VERSION = "0.6.0.rc1"
3
+ VERSION = "0.7.0"
4
4
  end
5
5
  end
@@ -7,61 +7,81 @@ require "jekyll-linkpreview/version"
7
7
 
8
8
  module Jekyll
9
9
  module Linkpreview
10
- class OpenGraphProperties
11
- @@template_file = 'linkpreview.html'
12
-
13
- def initialize(title, url, image, description, domain)
14
- @title = title
15
- @url = url
16
- @image = image
17
- @description = description
18
- @domain = domain
10
+ class Properties
11
+ def initialize(properties, template_file)
12
+ @properties = properties
13
+ @template_file = template_file
19
14
  end
20
15
 
21
16
  def to_hash()
22
- {
23
- 'title' => @title,
24
- 'url' => @url,
25
- 'image' => @image,
26
- 'description' => @description,
27
- 'domain' => @domain,
28
- }
17
+ @properties
29
18
  end
30
19
 
31
20
  def to_hash_for_custom_template()
32
- {
33
- 'link_title' => @title,
34
- 'link_url' => @url,
35
- 'link_image' => @image,
36
- 'link_description' => @description,
37
- 'link_domain' => @domain
21
+ hash_for_custom_template = {}
22
+ @properties.each{ |key, value|
23
+ hash_for_custom_template[key] = value
24
+ # NOTE: 'link_*' variables will be deleted in v1.0.0.
25
+ hash_for_custom_template['link_' + key] = value
38
26
  }
27
+ hash_for_custom_template
39
28
  end
40
29
 
41
30
  def template_file()
42
- @@template_file
31
+ @template_file
43
32
  end
44
33
  end
45
34
 
46
35
  class OpenGraphPropertiesFactory
36
+ @@template_file = 'linkpreview.html'
37
+
38
+ def self.template_file
39
+ @@template_file
40
+ end
41
+
47
42
  def from_page(page)
48
- og_properties = page.meta_tags['property']
49
- image_url = get_og_property(og_properties, 'og:image')
50
- title = get_og_property(og_properties, 'og:title')
51
- url = get_og_property(og_properties, 'og:url')
52
- image = convert_to_absolute_url(image_url, page.root_url)
53
- description = get_og_property(og_properties, 'og:description')
54
- domain = page.host
55
- OpenGraphProperties.new(title, url, image, description, domain)
43
+ properties = page.meta_tags['property']
44
+ og_properties = {
45
+ # basic metadata (https://ogp.me/#metadata)
46
+ 'title' => get_property(properties, 'og:title'),
47
+ 'type' => get_property(properties, 'og:type'),
48
+ 'url' => get_property(properties, 'og:url'),
49
+ 'image' => convert_to_absolute_url(get_property(properties, 'og:image'), page.root_url),
50
+ # optional metadata (https://ogp.me/#optional)
51
+ ## image
52
+ 'image_secure_url' => convert_to_absolute_url(get_property(properties, 'og:image:secure_url'), page.root_url),
53
+ 'image_type' => get_property(properties, 'og:image:type'),
54
+ 'image_width' => get_property(properties, 'og:image:width'),
55
+ 'image_height' => get_property(properties, 'og:image:height'),
56
+ 'image_alt' => get_property(properties, 'og:image:alt'),
57
+ ## video
58
+ 'video' => convert_to_absolute_url(get_property(properties, 'og:video'), page.root_url),
59
+ 'video_secure_url' => convert_to_absolute_url(get_property(properties, 'og:video:secure_url'), page.root_url),
60
+ 'video_type' => get_property(properties, 'og:video:type'),
61
+ 'video_width' => get_property(properties, 'og:video:width'),
62
+ 'video_height' => get_property(properties, 'og:video:height'),
63
+ ## audio
64
+ 'audio' => convert_to_absolute_url(get_property(properties, 'og:audio'), page.root_url),
65
+ 'audio_secure_url' => convert_to_absolute_url(get_property(properties, 'og:audio:secure_url'), page.root_url),
66
+ 'audio_type' => get_property(properties, 'og:audio:type'),
67
+ ## other optional metadata
68
+ 'description' => get_property(properties, 'og:description'),
69
+ 'determiner' => get_property(properties, 'og:determiner'),
70
+ 'locale' => get_property(properties, 'og:locale'),
71
+ 'locale_alternate' => get_property(properties, 'og:locale:alternate'),
72
+ 'site_name' => get_property(properties, 'og:site_name'),
73
+ # not defined in OGP
74
+ 'domain' => page.host,
75
+ }
76
+ Properties.new(og_properties, @@template_file)
56
77
  end
57
78
 
58
79
  def from_hash(hash)
59
- OpenGraphProperties.new(
60
- hash['title'], hash['url'], hash['image'], hash['description'], hash['domain'])
80
+ Properties.new(hash, @@template_file)
61
81
  end
62
82
 
63
83
  private
64
- def get_og_property(properties, key)
84
+ def get_property(properties, key)
65
85
  if !properties.key? key then
66
86
  return nil
67
87
  end
@@ -81,57 +101,24 @@ module Jekyll
81
101
  end
82
102
  end
83
103
 
84
- class NonOpenGraphProperties
104
+ class NonOpenGraphPropertiesFactory
85
105
  @@template_file = 'linkpreview_nog.html'
86
106
 
87
- def initialize(title, url, description, domain)
88
- @title = title
89
- @url = url
90
- @description = description
91
- @domain = domain
92
- end
93
-
94
- def to_hash()
95
- {
96
- 'title' => @title,
97
- 'url' => @url,
98
- 'description' => @description,
99
- 'domain' => @domain,
100
- }
101
- end
102
-
103
- def to_hash_for_custom_template()
104
- {
105
- 'link_title' => @title,
106
- 'link_url' => @url,
107
- 'link_description' => @description,
108
- 'link_domain' => @domain
109
- }
110
- end
111
-
112
- def template_file()
107
+ def self.template_file
113
108
  @@template_file
114
109
  end
115
- end
116
110
 
117
- class NonOpenGraphPropertiesFactory
118
111
  def from_page(page)
119
- NonOpenGraphProperties.new(
120
- page.title, page.url, get_description(page), page.host)
112
+ Properties.new({
113
+ 'title' => page.best_title,
114
+ 'url' => page.url,
115
+ 'description' => page.best_description,
116
+ 'domain' => page.host,
117
+ }, @@template_file)
121
118
  end
122
119
 
123
120
  def from_hash(hash)
124
- NonOpenGraphProperties.new(
125
- hash['title'], hash['url'], hash['description'], hash['domain'])
126
- end
127
-
128
- private
129
- def get_description(page)
130
- if !page.parsed.xpath('//p[normalize-space()]').empty? then
131
- return page.parsed.xpath('//p[normalize-space()]').map(&:text).first[0..180] + "..."
132
- else
133
- return "..."
134
- end
121
+ Properties.new(hash, @@template_file)
135
122
  end
136
123
  end
137
124
 
@@ -158,7 +145,7 @@ module Jekyll
158
145
  end
159
146
  page = fetch(url)
160
147
  properties = create_properties_from_page(page)
161
- if Dir.exists?(@@cache_dir) then
148
+ if Dir.exist?(@@cache_dir) then
162
149
  save_cache_file(cache_filepath, properties)
163
150
  else
164
151
  # TODO: This message will be shown at all linkprevew tag
@@ -189,7 +176,9 @@ module Jekyll
189
176
 
190
177
  private
191
178
  def create_properties_from_page(page)
192
- if page.meta_tags['property'].empty? then
179
+ if !%w[og:title og:type og:url og:image].all? { |required_tag|
180
+ page.meta_tags['property'].include?(required_tag)
181
+ }
193
182
  factory = NonOpenGraphPropertiesFactory.new
194
183
  else
195
184
  factory = OpenGraphPropertiesFactory.new
@@ -239,16 +228,15 @@ module Jekyll
239
228
  image_html = ""
240
229
  if image then
241
230
  image_html = <<-EOS
242
- <div class="jekyll-linkpreview-image">
243
- <a href="#{url}" target="_blank">
244
- <img src="#{image}" />
245
- </a>
246
- </div>
231
+ <div class="jekyll-linkpreview-image">
232
+ <a href="#{url}" target="_blank">
233
+ <img src="#{image}" />
234
+ </a>
235
+ </div>
247
236
  EOS
248
237
  end
249
238
  html = <<-EOS
250
239
  <div class="jekyll-linkpreview-wrapper">
251
- <p><a href="#{url}" target="_blank">#{url}</a></p>
252
240
  <div class="jekyll-linkpreview-wrapper-inner">
253
241
  <div class="jekyll-linkpreview-content">
254
242
  #{image_html}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-linkpreview
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0.rc1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke Nishioka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-09 00:00:00.000000000 Z
11
+ date: 2023-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -100,20 +100,6 @@ dependencies:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
102
  version: 0.5.2
103
- - !ruby/object:Gem::Dependency
104
- name: appraisal
105
- requirement: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - "~>"
108
- - !ruby/object:Gem::Version
109
- version: 2.2.0
110
- type: :development
111
- prerelease: false
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - "~>"
115
- - !ruby/object:Gem::Version
116
- version: 2.2.0
117
103
  - !ruby/object:Gem::Dependency
118
104
  name: wwtd
119
105
  requirement: !ruby/object:Gem::Requirement
@@ -166,9 +152,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
152
  version: '0'
167
153
  required_rubygems_version: !ruby/object:Gem::Requirement
168
154
  requirements:
169
- - - ">"
155
+ - - ">="
170
156
  - !ruby/object:Gem::Version
171
- version: 1.3.1
157
+ version: '0'
172
158
  requirements: []
173
159
  rubygems_version: 3.3.26
174
160
  signing_key: