sutty-liquid 0.6.0 → 0.7.2

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: 208a07a3955ffd0ba332ba272d1b7ba868aacee433bb1a71cc1af72468a4d434
4
- data.tar.gz: 5c5228f00ef585c35524310a5c0b57e71292dc35890ace25ce691c7ccb6b7f10
3
+ metadata.gz: 8a055c727c2c4f960fa8d9bf769add3e1f76a7287f80f0232ed368ba7b444df3
4
+ data.tar.gz: 24b5f07c35b6a299b5390e7c90b3b5e4b642457098de79e10758eac359d30f51
5
5
  SHA512:
6
- metadata.gz: 41efec969df4effe3e52596b0ce4c38f93cf828b4e9f3614dc644d11b838d18d841ed4e5f2bf5a3ab05a106cafeaf8985c623defdbc8fd36679e9b89d4728e7d
7
- data.tar.gz: dbacfff37b6598665a29290d75f106918dc47c96c9ee36c02f4e107b15e94b828814c9af045b47e440407ef696242448cef2f9a82a08949a57c6fd8a23fe6dde
6
+ metadata.gz: e17c4ee5e491311f589ebb7f142edc0a1fb71f1a860eff5de048e8f121900116dd6fe6e9c10201690c71f437018c71865edb5edc384a8978c571ce1d66cd3793
7
+ data.tar.gz: 690b1f9fbf7906c1d000feb7d3728b6413a305414c5f9234d8a6ea6ce75f695fd41cc6fd87533a4b5429a47761282924fbe5b5b9bb9834b7b69bfc8f6469b513
@@ -12,6 +12,8 @@ module Jekyll
12
12
  require 'pry'
13
13
 
14
14
  binding.pry
15
+
16
+ input
15
17
  end
16
18
  end
17
19
  end
@@ -3,6 +3,11 @@
3
3
  module Jekyll
4
4
  module Filters
5
5
  module SocialNetwork
6
+ SUBDOMAINS = /\A(www|chat)\./.freeze
7
+ DOMAIN_MAP = {
8
+ 't.me' => 'telegram'
9
+ }.freeze
10
+
6
11
  # Takes a URL and returns a Hash of attributes, useful when you
7
12
  # want to generate social network buttons from an undetermined
8
13
  # list of URLs.
@@ -19,19 +24,22 @@ module Jekyll
19
24
  # @param [String]
20
25
  # @return [Hash]
21
26
  def social_network(url)
22
- return {} unless url.is_a? String
23
-
24
- require 'uri'
27
+ begin
28
+ require 'uri'
25
29
 
26
- uri = URI url
27
- uri.host.sub! 'www.', ''
28
- name = %r{/@\w+} =~ uri.query ? 'mastodon' : uri.host.split('.', 2).first
30
+ uri = URI url
31
+ host = uri.host.sub SUBDOMAINS, ''
29
32
 
30
- { 'host' => uri.host, 'name' => name, 'url' => url }.to_liquid
31
- rescue URI::InvalidURIError => e
32
- Jekyll.logger.warn e.message
33
+ name = DOMAIN_MAP[host]
34
+ name ||= %r{/@\w+} =~ uri.query ? 'mastodon' : host.split('.', 2).first
35
+ rescue ArgumentError, URI::InvalidURIError => e
36
+ Jekyll.logger.warn(e.message) if Jekyll.respond_to?(:logger)
37
+ ensure
38
+ host ||= url
39
+ name ||= 'globe'
40
+ end
33
41
 
34
- {}.to_liquid
42
+ { 'host' => host, 'name' => name, 'url' => url }.to_liquid
35
43
  end
36
44
  end
37
45
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Filters
5
+ module Strings
6
+ # String#start_with?
7
+ def start_with(input, start)
8
+ input.to_s.start_with? start.to_s
9
+ end
10
+
11
+ # Replaces the last ocurrence of a String
12
+ #
13
+ # @param [String]
14
+ # @param [String]
15
+ # @param [String]
16
+ # @return [String]
17
+ def replace_last(input, search, replace)
18
+ hay = input.split search
19
+ needle = "#{replace}#{hay.pop}"
20
+
21
+ hay.join(search) + needle
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ Liquid::Template.register_filter(Jekyll::Filters::Strings)
@@ -9,7 +9,7 @@ require_relative 'jekyll/filters/json'
9
9
  require_relative 'jekyll/filters/menu'
10
10
  require_relative 'jekyll/filters/number'
11
11
  require_relative 'jekyll/filters/sample'
12
- require_relative 'jekyll/filters/string'
12
+ require_relative 'jekyll/filters/strings'
13
13
  require_relative 'jekyll/filters/social_network'
14
14
 
15
15
  require_relative 'jekyll/filters/pry'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sutty-liquid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-12 00:00:00.000000000 Z
11
+ date: 2021-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.13'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.13'
41
83
  description: An assorment of Liquid filters and tags for Jekyll used in Sutty
42
84
  email:
43
85
  - f@sutty.nl
@@ -61,7 +103,7 @@ files:
61
103
  - lib/jekyll/filters/pry.rb
62
104
  - lib/jekyll/filters/sample.rb
63
105
  - lib/jekyll/filters/social_network.rb
64
- - lib/jekyll/filters/string.rb
106
+ - lib/jekyll/filters/strings.rb
65
107
  - lib/jekyll/tags/pry.rb
66
108
  - lib/sutty-liquid.rb
67
109
  homepage: https://0xacab.org/sutty/jekyll/sutty-liquid
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jekyll
4
- module Filters
5
- module String
6
- # String#start_with?
7
- def start_with(input, start)
8
- input.to_s.start_with? start.to_s
9
- end
10
- end
11
- end
12
- end
13
-
14
- Liquid::Template.register_filter(Jekyll::Filters::String)