jekyll-linkpreview 0.6.0 → 0.7.0
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 +4 -4
- data/.github/workflows/release.yaml +3 -3
- data/.github/workflows/test.yaml +12 -1
- data/Gemfile +9 -0
- data/README.md +42 -17
- data/jekyll-linkpreview.gemspec +1 -4
- data/lib/jekyll-linkpreview/version.rb +1 -1
- data/lib/jekyll-linkpreview.rb +64 -80
- metadata +4 -24
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3644c879680eba2cb17840f40258ec2adeb0493505ca28572cdcadcc72c87ced
|
|
4
|
+
data.tar.gz: 3925c9a5330bc589b239908cde01dc6be7493d05d35bf6bf2f8e52e3538b643a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4246f72fc2c59ad23149b2c187864533f0fe85e09d1ca7f84feef875ad2404e6861aa6a37255f3ec3e76d2edff367fb5a6061d3f8c497c117edbdafba9801a5f
|
|
7
|
+
data.tar.gz: 689f9e31a23fb6846db6cb4854adabc464a890816418a988a1732d5cc9b4e34bc7df143774ec274e693d66f51d9af5d41b52ec731b8d3dab980afcd816378e0c
|
|
@@ -17,7 +17,7 @@ jobs:
|
|
|
17
17
|
fetch-depth: 2
|
|
18
18
|
# See https://github.com/actions/runner-images/issues/6775.
|
|
19
19
|
- name: Suppress 'detected dubious ownership' error.
|
|
20
|
-
run: git config --global --add safe.directory
|
|
20
|
+
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
|
|
21
21
|
- id: check-release
|
|
22
22
|
name: Decide whether to release
|
|
23
23
|
run: |
|
|
@@ -39,7 +39,7 @@ jobs:
|
|
|
39
39
|
uses: actions/checkout@v3
|
|
40
40
|
# See https://github.com/actions/runner-images/issues/6775.
|
|
41
41
|
- name: Suppress 'detected dubious ownership' error.
|
|
42
|
-
run: git config --global --add safe.directory
|
|
42
|
+
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
|
|
43
43
|
- env:
|
|
44
44
|
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
|
|
45
45
|
name: Set credentials for RubyGems
|
|
@@ -49,7 +49,7 @@ jobs:
|
|
|
49
49
|
chmod 0600 ~/.gem/credentials
|
|
50
50
|
- name: Configure git
|
|
51
51
|
run: |
|
|
52
|
-
git config --global user.email "yusuke.nishioka.0713@gmail
|
|
52
|
+
git config --global user.email "yusuke.nishioka.0713@gmail.com"
|
|
53
53
|
git config --global user.name "Yusuke Nishioka"
|
|
54
54
|
- name: Install dependencies
|
|
55
55
|
run: bundle install
|
data/.github/workflows/test.yaml
CHANGED
|
@@ -13,7 +13,7 @@ jobs:
|
|
|
13
13
|
runs-on: ubuntu-latest
|
|
14
14
|
strategy:
|
|
15
15
|
matrix:
|
|
16
|
-
ruby: ["2.7", "3.1"]
|
|
16
|
+
ruby: ["2.7", "3.1", "3.2"]
|
|
17
17
|
appraisal:
|
|
18
18
|
- jekyll-35
|
|
19
19
|
- jekyll-36
|
|
@@ -34,9 +34,20 @@ jobs:
|
|
|
34
34
|
appraisal: jekyll-37
|
|
35
35
|
- ruby: "3.1"
|
|
36
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
|
|
37
45
|
steps:
|
|
38
46
|
- name: Checkout
|
|
39
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}
|
|
40
51
|
- if: matrix.ruby == '2.7'
|
|
41
52
|
name: Update RubyGems version
|
|
42
53
|
# sass-embedded 1.57.1, which is one of dependencies of jekyll-sass-converter 3.0,
|
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
|
-
[](https://github.com/ysk24ok/jekyll-linkpreview/actions/workflows/test.yaml)
|
|
4
|
+
[](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,29 +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
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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 }}`
|
|
63
88
|
|
|
64
89
|
### Template for pages where Open Graph protocol metadata does not exist
|
|
65
90
|
|
|
66
91
|
1. Place `linkpreview_nog.html` file inside `_includes/` folder of your Jekyll site (`_includes/linkpreview_nog.html`)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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 }}`
|
|
75
100
|
|
|
76
101
|
## Development
|
|
77
102
|
|
data/jekyll-linkpreview.gemspec
CHANGED
|
@@ -20,12 +20,9 @@ Gem::Specification.new do |spec|
|
|
|
20
20
|
|
|
21
21
|
spec.add_dependency "jekyll", ">= 3.5", "< 5.0"
|
|
22
22
|
spec.add_dependency "metainspector", "~> 5.9"
|
|
23
|
-
|
|
24
|
-
# See https://github.com/thoughtbot/appraisal/issues/199 for details.
|
|
25
|
-
spec.add_development_dependency "bundler", ">= 2.0", "< 2.4"
|
|
23
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
|
26
24
|
spec.add_development_dependency "rake", "~> 12.3.3"
|
|
27
25
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
28
26
|
spec.add_development_dependency "rspec-parameterized", "~> 0.5.2"
|
|
29
|
-
spec.add_development_dependency "appraisal", "~> 2.0"
|
|
30
27
|
spec.add_development_dependency "wwtd", "~> 1.4.1"
|
|
31
28
|
end
|
data/lib/jekyll-linkpreview.rb
CHANGED
|
@@ -7,65 +7,81 @@ require "jekyll-linkpreview/version"
|
|
|
7
7
|
|
|
8
8
|
module Jekyll
|
|
9
9
|
module Linkpreview
|
|
10
|
-
class
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@title = title
|
|
15
|
-
@type = type
|
|
16
|
-
@url = url
|
|
17
|
-
@image = image
|
|
18
|
-
@description = description
|
|
19
|
-
@domain = domain
|
|
10
|
+
class Properties
|
|
11
|
+
def initialize(properties, template_file)
|
|
12
|
+
@properties = properties
|
|
13
|
+
@template_file = template_file
|
|
20
14
|
end
|
|
21
15
|
|
|
22
16
|
def to_hash()
|
|
23
|
-
|
|
24
|
-
'title' => @title,
|
|
25
|
-
'type' => @type,
|
|
26
|
-
'url' => @url,
|
|
27
|
-
'image' => @image,
|
|
28
|
-
'description' => @description,
|
|
29
|
-
'domain' => @domain,
|
|
30
|
-
}
|
|
17
|
+
@properties
|
|
31
18
|
end
|
|
32
19
|
|
|
33
20
|
def to_hash_for_custom_template()
|
|
34
|
-
{
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
'
|
|
38
|
-
'
|
|
39
|
-
'link_description' => @description,
|
|
40
|
-
'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
|
|
41
26
|
}
|
|
27
|
+
hash_for_custom_template
|
|
42
28
|
end
|
|
43
29
|
|
|
44
30
|
def template_file()
|
|
45
|
-
|
|
31
|
+
@template_file
|
|
46
32
|
end
|
|
47
33
|
end
|
|
48
34
|
|
|
49
35
|
class OpenGraphPropertiesFactory
|
|
36
|
+
@@template_file = 'linkpreview.html'
|
|
37
|
+
|
|
38
|
+
def self.template_file
|
|
39
|
+
@@template_file
|
|
40
|
+
end
|
|
41
|
+
|
|
50
42
|
def from_page(page)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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)
|
|
60
77
|
end
|
|
61
78
|
|
|
62
79
|
def from_hash(hash)
|
|
63
|
-
|
|
64
|
-
hash['title'], hash['type'], hash['url'], hash['image'], hash['description'], hash['domain'])
|
|
80
|
+
Properties.new(hash, @@template_file)
|
|
65
81
|
end
|
|
66
82
|
|
|
67
83
|
private
|
|
68
|
-
def
|
|
84
|
+
def get_property(properties, key)
|
|
69
85
|
if !properties.key? key then
|
|
70
86
|
return nil
|
|
71
87
|
end
|
|
@@ -85,56 +101,24 @@ module Jekyll
|
|
|
85
101
|
end
|
|
86
102
|
end
|
|
87
103
|
|
|
88
|
-
class
|
|
104
|
+
class NonOpenGraphPropertiesFactory
|
|
89
105
|
@@template_file = 'linkpreview_nog.html'
|
|
90
106
|
|
|
91
|
-
def
|
|
92
|
-
@title = title
|
|
93
|
-
@url = url
|
|
94
|
-
@description = description
|
|
95
|
-
@domain = domain
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def to_hash()
|
|
99
|
-
{
|
|
100
|
-
'title' => @title,
|
|
101
|
-
'url' => @url,
|
|
102
|
-
'description' => @description,
|
|
103
|
-
'domain' => @domain,
|
|
104
|
-
}
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def to_hash_for_custom_template()
|
|
108
|
-
{
|
|
109
|
-
'link_title' => @title,
|
|
110
|
-
'link_url' => @url,
|
|
111
|
-
'link_description' => @description,
|
|
112
|
-
'link_domain' => @domain
|
|
113
|
-
}
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def template_file()
|
|
107
|
+
def self.template_file
|
|
117
108
|
@@template_file
|
|
118
109
|
end
|
|
119
|
-
end
|
|
120
110
|
|
|
121
|
-
class NonOpenGraphPropertiesFactory
|
|
122
111
|
def from_page(page)
|
|
123
|
-
|
|
112
|
+
Properties.new({
|
|
113
|
+
'title' => page.best_title,
|
|
114
|
+
'url' => page.url,
|
|
115
|
+
'description' => page.best_description,
|
|
116
|
+
'domain' => page.host,
|
|
117
|
+
}, @@template_file)
|
|
124
118
|
end
|
|
125
119
|
|
|
126
120
|
def from_hash(hash)
|
|
127
|
-
|
|
128
|
-
hash['title'], hash['url'], hash['description'], hash['domain'])
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
private
|
|
132
|
-
def get_description(page)
|
|
133
|
-
if !page.parsed.xpath('//p[normalize-space()]').empty? then
|
|
134
|
-
return page.parsed.xpath('//p[normalize-space()]').map(&:text).first[0..180] + "..."
|
|
135
|
-
else
|
|
136
|
-
return "..."
|
|
137
|
-
end
|
|
121
|
+
Properties.new(hash, @@template_file)
|
|
138
122
|
end
|
|
139
123
|
end
|
|
140
124
|
|
|
@@ -161,7 +145,7 @@ module Jekyll
|
|
|
161
145
|
end
|
|
162
146
|
page = fetch(url)
|
|
163
147
|
properties = create_properties_from_page(page)
|
|
164
|
-
if Dir.
|
|
148
|
+
if Dir.exist?(@@cache_dir) then
|
|
165
149
|
save_cache_file(cache_filepath, properties)
|
|
166
150
|
else
|
|
167
151
|
# TODO: This message will be shown at all linkprevew tag
|
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.
|
|
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: 2023-
|
|
11
|
+
date: 2023-05-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: jekyll
|
|
@@ -48,22 +48,16 @@ dependencies:
|
|
|
48
48
|
name: bundler
|
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
|
50
50
|
requirements:
|
|
51
|
-
- - "
|
|
51
|
+
- - "~>"
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
53
|
version: '2.0'
|
|
54
|
-
- - "<"
|
|
55
|
-
- !ruby/object:Gem::Version
|
|
56
|
-
version: '2.4'
|
|
57
54
|
type: :development
|
|
58
55
|
prerelease: false
|
|
59
56
|
version_requirements: !ruby/object:Gem::Requirement
|
|
60
57
|
requirements:
|
|
61
|
-
- - "
|
|
58
|
+
- - "~>"
|
|
62
59
|
- !ruby/object:Gem::Version
|
|
63
60
|
version: '2.0'
|
|
64
|
-
- - "<"
|
|
65
|
-
- !ruby/object:Gem::Version
|
|
66
|
-
version: '2.4'
|
|
67
61
|
- !ruby/object:Gem::Dependency
|
|
68
62
|
name: rake
|
|
69
63
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -106,20 +100,6 @@ dependencies:
|
|
|
106
100
|
- - "~>"
|
|
107
101
|
- !ruby/object:Gem::Version
|
|
108
102
|
version: 0.5.2
|
|
109
|
-
- !ruby/object:Gem::Dependency
|
|
110
|
-
name: appraisal
|
|
111
|
-
requirement: !ruby/object:Gem::Requirement
|
|
112
|
-
requirements:
|
|
113
|
-
- - "~>"
|
|
114
|
-
- !ruby/object:Gem::Version
|
|
115
|
-
version: '2.0'
|
|
116
|
-
type: :development
|
|
117
|
-
prerelease: false
|
|
118
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
119
|
-
requirements:
|
|
120
|
-
- - "~>"
|
|
121
|
-
- !ruby/object:Gem::Version
|
|
122
|
-
version: '2.0'
|
|
123
103
|
- !ruby/object:Gem::Dependency
|
|
124
104
|
name: wwtd
|
|
125
105
|
requirement: !ruby/object:Gem::Requirement
|