jekyll-share-plugin 1.0.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.
data/README.md ADDED
@@ -0,0 +1,135 @@
1
+ # Jekyll-Share
2
+
3
+ This is a Jekyll plugin that provides the Liquid tags to render the sharing services links through the
4
+ [ShareWith][share_with] gem.
5
+
6
+ Using the config section, or defining variables from within the layout template, the target fields can
7
+ be customized entirely.
8
+
9
+ [![Ruby](https://github.com/fabiomux/jekyll-share-plugin/actions/workflows/main.yml/badge.svg)][wf_main]
10
+ [![Gem Version](https://badge.fury.io/rb/jekyll-share-plugin.svg)][gem_version]
11
+
12
+
13
+ ## Installation
14
+
15
+ Can install the gem either manually or using *Bundler*.
16
+
17
+ ### Using Bundler
18
+
19
+ Install the gem and add to the application's Gemfile by executing:
20
+
21
+ $ bundle add jekyll-share-plugin --group jekyll_plugins
22
+
23
+ ### Manually
24
+
25
+ If bundler is not being used to manage dependencies, install the gem by executing:
26
+
27
+ $ gem install jekyll-share-plugin
28
+
29
+ Then, add the following code within the Gemfile of your Jekyll project:
30
+
31
+ ```ruby
32
+ group :jekyll_plugins do
33
+ ...
34
+ gem 'jekyll-share-plugin'
35
+ end
36
+ ```
37
+
38
+ ## Configuration
39
+
40
+ Inside the `_config.yml` file, set up some or all of the following fields under the `jekyll-share`
41
+ section:
42
+
43
+ ```yaml
44
+ jekyll-share:
45
+ paths:
46
+ - $HOME/.jekyll-share/services
47
+ mappings:
48
+ twitter:hashtags: '@tags'
49
+ email:subject: '@title'
50
+ # These variables below must be setup in your layout file
51
+ twitter:related: '@related'
52
+ linkedin:summary: '@summary'
53
+ pinterest:media_url: '@media_url'
54
+ email:body: '@str_body'
55
+ post_selector: include.post
56
+ groups:
57
+ default:
58
+ wrappers:
59
+ service_start: '<li class="list-inline-item">'
60
+ service_end: '</li>'
61
+ group_start: '<ul class="list-inline">'
62
+ group_end: '</ul>'
63
+ extend_with:
64
+ - icons.font_awesome
65
+ icon_size: 'medium'
66
+ template: 'icon'
67
+ services:
68
+ - twitter
69
+ - facebook
70
+ - linkedin
71
+ - reddit
72
+ - tumblr
73
+ - telegram
74
+ - flipboard
75
+ - pocket
76
+ - pinterest
77
+ ```
78
+
79
+ *paths*
80
+ : It is the path where other services can be found
81
+
82
+ *mappings*
83
+ : Associate the not standard params with the variables within the layout or include template, or as a field
84
+ part of the front matter in the current document.
85
+
86
+ *post_selector*
87
+ : This is how the script will read the post data inside a paginator layout.
88
+
89
+ *groups*
90
+ : Define the groups of services to render, every group can specify other parameters:
91
+
92
+ *wrappers*
93
+ : Defines the HTML tags that wrap the group of links or the single link.
94
+
95
+ *extend_with*
96
+ : This implementes the extensions provided by *share_with* gem.
97
+
98
+ *icon_size*
99
+ : The size of the icons among the ones defined by *share_with*.
100
+
101
+ *template*
102
+ : The default template to use among the ones defined by *share_with*.
103
+
104
+ *services*
105
+ : The list of services included in the group.
106
+
107
+ ## Usage
108
+
109
+ Jekyll-Share provides two Liquid tags that can be used to render the service links:
110
+
111
+ **share_single**
112
+ : Recall the single service to render.
113
+ ```liquid
114
+ {% share_single name='email' %}
115
+ ```
116
+
117
+ **share_group**
118
+ : Recall the group of services as specified in the `.config.yml` file.
119
+ ```liquid
120
+ {% share_group name='default' icon_size=icon_size %}
121
+ ```
122
+
123
+ ## More Help
124
+
125
+ More info is available at:
126
+ - the [project page on the Freeaptitude blog][project_page];
127
+ - the [Jekyll-Share Github wiki][jekyll_share_wiki];
128
+ - the [ShareWith Github wiki][share_with_wiki].
129
+
130
+ [share_with]: https://github.com/fabiomux/share_with "ShareWith project page on GitHub"
131
+ [share_with_wiki]: https://github.com/fabiomux/share_with/wiki "ShareWith wiki page on GitHub"
132
+ [wf_main]: https://github.com/fabiomux/jekyll-share-plugin/actions/workflows/main.yml
133
+ [gem_version]: https://badge.fury.io/rb/jekyll-share-plugin
134
+ [project_page]: https://freeaptitude.altervista.org/projects/jekyll-share.html "Project page on the Freeaptitude blog"
135
+ [jekyll_share_wiki]: https://github.com/fabiomux/jekyll-share-plugin/wiki "Jekyll-Share wiki page on GitHub"
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/jekyll/share/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "jekyll-share-plugin"
7
+ spec.version = Jekyll::Share::VERSION
8
+ spec.authors = ["Fabio Mucciante"]
9
+ spec.email = ["fabio.mucciante@gmail.com"]
10
+
11
+ spec.summary = "Jekyll plugin that renders the sharing links from known services."
12
+ spec.description = "It provides links from Facebook, Linkedin, Reddit, Telegram, Twitter, and more..."
13
+ spec.homepage = "https://freeaptitude.altervista.org/projects/jekyll-share.html"
14
+
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/fabiomux/jekyll-share-plugin"
21
+ spec.metadata["changelog_uri"] = "https://freeaptitude.altervista.org/projects/jekyll-share.html#changelog"
22
+ spec.metadata["wiki_uri"] = "https://github.com/fabiomux/jekyll-share-plugin/wiki"
23
+ spec.metadata["rubygems_mfa_required"] = "true"
24
+
25
+ # Specify which files should be added to the gem when it is released.
26
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
+ spec.files = Dir.chdir(__dir__) do
28
+ `git ls-files -z`.split("\x0").reject do |f|
29
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
30
+ end
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+
36
+ # Uncomment to register a new dependency of your gem
37
+ # spec.add_dependency "example-gem", "~> 1.0"
38
+ spec.add_dependency "jekyll", ">= 3.7", "< 5.0"
39
+ spec.add_dependency "share_with"
40
+
41
+ # For more information and examples about making a new gem, check out our
42
+ # guide at: https://bundler.io/guides/creating_gem.html
43
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Share
5
+ #
6
+ # Configurations required across the gem.
7
+ #
8
+ class Config
9
+ def self.gconfig
10
+ @@gconfig ||= Jekyll.configuration.freeze
11
+ end
12
+
13
+ def self.base_url
14
+ @@base_url ||= gconfig["base_url"].freeze
15
+ end
16
+
17
+ def self.url
18
+ @@url ||= gconfig["url"].freeze
19
+ end
20
+
21
+ def self.source
22
+ @@source ||= gconfig["source"].freeze
23
+ end
24
+
25
+ def self.config
26
+ @@config ||= gconfig["jekyll-share"].freeze
27
+ end
28
+
29
+ def self.groups
30
+ @@groups ||= (config["groups"] || []).freeze
31
+ end
32
+
33
+ def self.group(name)
34
+ raise InvalidGroup unless groups.key? name
35
+
36
+ groups[name]
37
+ end
38
+
39
+ def self.mappings
40
+ @@mappings ||= (config["mappings"] || []).freeze
41
+ end
42
+
43
+ def self.post_selector
44
+ @@post_selector ||= (config["post_selector"] || "include.post").freeze
45
+ end
46
+
47
+ def self.paths
48
+ @@paths ||= (config["paths"] || ["~/.jekyll-share/services"]).freeze
49
+ end
50
+ end
51
+
52
+ #
53
+ # Group configurations.
54
+ #
55
+ class GroupConfig
56
+ attr_reader :config
57
+
58
+ def initialize(name)
59
+ raise InvalidGroup unless Config.groups.key? name
60
+
61
+ @name = name
62
+ @config = Config.groups[name]
63
+ end
64
+
65
+ def template
66
+ @config["template"] || "icon"
67
+ end
68
+
69
+ def wrappers
70
+ @config["wrappers"] || { "group_start" => "", "group_end" => "",
71
+ "service_start" => "", "service_end" => "" }
72
+ end
73
+
74
+ def extend_with
75
+ @config["extend_with"] || []
76
+ end
77
+
78
+ def services
79
+ @config["services"] || []
80
+ end
81
+
82
+ def icon_size
83
+ @config["icon_size"] || "large"
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Share
5
+ #
6
+ # Contains the methods to calculate the Disqus ID associated to
7
+ # a post or a page.
8
+ #
9
+ module Helper
10
+ def preview?(context)
11
+ return true if context["#{Config.post_selector}.title"]
12
+ end
13
+
14
+ def extract_page_data(context)
15
+ extract_data "page", context
16
+ end
17
+
18
+ def extract_preview_data(context)
19
+ extract_data Config.post_selector, context
20
+ end
21
+
22
+ private
23
+
24
+ # rubocop:disable Metrics/PerceivedComplexity
25
+ # rubocop:disable Metrics/CyclomaticComplexity
26
+ def extract_data(selector, context)
27
+ res = {}
28
+ res["title"] = context["#{selector}.title"]
29
+ res["url"] = context["site.url"].to_s +
30
+ context["site.base_dir"].to_s +
31
+ context["#{selector}.url"]
32
+ res["tags"] = context["#{selector}.tags"]
33
+ res["categories"] = context["#{selector}.categories"]
34
+
35
+ if res["tags"].instance_of? String
36
+ res["tags"] = res["tags"].split.join(",")
37
+ elsif res["tags"].instance_of? Array
38
+ res["tags"] = res["tags"].join(",")
39
+ end
40
+
41
+ if res["categories"].instance_of? String
42
+ res["categories"] = res["categories"].split.join(",")
43
+ elsif res["tags"].instance_of? Array
44
+ res["categories"] = res["categories"].join(",")
45
+ end
46
+
47
+ Config.mappings.each do |k, v|
48
+ res[k] = if v[0] == "@"
49
+ param = v.delete("@")
50
+ if res.key?(param)
51
+ res[param]
52
+ else
53
+ context.key?(param) ? context[param] : context["#{selector}.#{param}"]
54
+ end
55
+ else
56
+ v
57
+ end
58
+ end
59
+
60
+ res
61
+ end
62
+ # rubocop:enable Metrics/PerceivedComplexity
63
+ # rubocop:enable Metrics/CyclomaticComplexity
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "share_with"
4
+
5
+ module Jekyll
6
+ module Share
7
+ #
8
+ # Single service rendering.
9
+ #
10
+ class Single < Liquid::Tag
11
+ include Helper
12
+
13
+ def initialize(tag_name, text, tokens)
14
+ super
15
+ @@share_single ||= {}
16
+ @text = text
17
+ end
18
+
19
+ def render(context)
20
+ @params = init_params(@text, context)
21
+ if @@share_single.key? @name
22
+ @@share_single[@name].reset!
23
+ else
24
+ @@share_single[@name] = ShareWith::Service.new @name,
25
+ extend_with: @extend_with,
26
+ paths: Config.paths
27
+ end
28
+
29
+ @params = if preview?(context)
30
+ extract_preview_data(context).merge @params
31
+ else
32
+ extract_page_data(context).merge @params
33
+ end
34
+
35
+ @params.each do |key, value|
36
+ @@share_single[@name].set_conditional_param(key, value)
37
+ end
38
+
39
+ @@share_single[@name].render(@template)
40
+ end
41
+
42
+ private
43
+
44
+ def init_params(text, context)
45
+ params = text.split_params(context)
46
+ @name = params["name"]
47
+ params.delete("name")
48
+ raise MissingService if @name.nil? || @name.empty?
49
+
50
+ @template = params["template"] || "icon"
51
+ params.delete("template")
52
+ @extend_with = params["extend_with"]
53
+ params.delete("extend_with")
54
+
55
+ params
56
+ end
57
+ end
58
+
59
+ #
60
+ # Group of services.
61
+ #
62
+ class Group < Liquid::Tag
63
+ include Helper
64
+
65
+ def initialize(tag_name, text, tokens)
66
+ super
67
+ @@share_groups ||= {}
68
+ @text = text
69
+ end
70
+
71
+ def render(context)
72
+ @params = init_params(@text, context)
73
+ if @@share_groups.key? @name
74
+ @@share_groups[@name].reset_all!
75
+ else
76
+ @@share_groups[@name] = ShareWith::Collection.new extend_with: @extend_with,
77
+ services: @services,
78
+ paths: Config.paths
79
+ end
80
+
81
+ @params = if preview?(context)
82
+ @params.merge extract_preview_data(context)
83
+ else
84
+ @params.merge extract_page_data(context)
85
+ end
86
+
87
+ @params.each do |key, value|
88
+ @@share_groups[@name].set_conditional_param(key, value)
89
+ end
90
+
91
+ res = [@wrappers["group_start"].to_s]
92
+ @@share_groups[@name].render_all(@template).each do |_k, v|
93
+ res << "#{@wrappers["service_start"]}#{v}#{@wrappers["service_end"]}"
94
+ end
95
+ res << @wrappers["group_end"].to_s
96
+
97
+ res.join("\n")
98
+ end
99
+
100
+ private
101
+
102
+ def init_params(text, context)
103
+ params = text.split_params(context)
104
+ @name = params["name"] || "default"
105
+ params.delete("name")
106
+
107
+ gcfg = GroupConfig.new(@name)
108
+ @template = params["template"] || gcfg.template
109
+ params.delete("template")
110
+ @wrappers = gcfg.wrappers
111
+
112
+ @extend_with = gcfg.extend_with
113
+ @services = gcfg.services
114
+
115
+ params["icon_size"] ||= gcfg.icon_size
116
+
117
+ params
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Share
5
+ #
6
+ # Convert the params to hash
7
+ #
8
+ class ::String
9
+ def split_params(context)
10
+ scan(/(\w+)=(?:(["'])(.+?)\2|([^ ]+))/)
11
+ .to_h do |x|
12
+ x[3] = context[x[3]] if x[1].nil?
13
+ x.delete_at 1
14
+ x.compact
15
+ end
16
+ end
17
+ end
18
+
19
+ #
20
+ # Invalid group name error
21
+ #
22
+ class InvalidGroup < StandardError
23
+ def initialize(name)
24
+ super "The group '#{name}' is not valid!"
25
+ end
26
+ end
27
+
28
+ #
29
+ # No service name has been specified.
30
+ #
31
+ class MissingService < StandardError
32
+ def initialize
33
+ super "No service name has been specified!"
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Share
5
+ VERSION = "1.0.0"
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll"
4
+
5
+ require_relative "share/config"
6
+ require_relative "share/helper"
7
+ require_relative "share/tags"
8
+ require_relative "share/utils"
9
+
10
+ Liquid::Template.register_tag("share_single", Jekyll::Share::Single)
11
+ Liquid::Template.register_tag("share_group", Jekyll::Share::Group)
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "jekyll/share"
@@ -0,0 +1,8 @@
1
+ module Jekyll
2
+ module Share
3
+ module Plugin
4
+ VERSION: String
5
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
6
+ end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-share-plugin
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Fabio Mucciante
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-01-26 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: share_with
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
+ description: It provides links from Facebook, Linkedin, Reddit, Telegram, Twitter,
48
+ and more...
49
+ email:
50
+ - fabio.mucciante@gmail.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - ".rspec"
56
+ - ".rubocop.yml"
57
+ - CODE_OF_CONDUCT.md
58
+ - Gemfile
59
+ - Gemfile.lock
60
+ - LICENSE
61
+ - README.md
62
+ - Rakefile
63
+ - jekyll-share-plugin.gemspec
64
+ - lib/jekyll-share-plugin.rb
65
+ - lib/jekyll/share.rb
66
+ - lib/jekyll/share/config.rb
67
+ - lib/jekyll/share/helper.rb
68
+ - lib/jekyll/share/tags.rb
69
+ - lib/jekyll/share/utils.rb
70
+ - lib/jekyll/share/version.rb
71
+ - sig/jekyll/share/plugin.rbs
72
+ homepage: https://freeaptitude.altervista.org/projects/jekyll-share.html
73
+ licenses: []
74
+ metadata:
75
+ homepage_uri: https://freeaptitude.altervista.org/projects/jekyll-share.html
76
+ source_code_uri: https://github.com/fabiomux/jekyll-share-plugin
77
+ changelog_uri: https://freeaptitude.altervista.org/projects/jekyll-share.html#changelog
78
+ wiki_uri: https://github.com/fabiomux/jekyll-share-plugin/wiki
79
+ rubygems_mfa_required: 'true'
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 2.6.0
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubygems_version: 3.4.3
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Jekyll plugin that renders the sharing links from known services.
99
+ test_files: []