jekyll-kw-shorten 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-kw-shorten.rb +2 -2
- data/lib/jekyll/KargWare/Shorten/parser.rb +13 -2
- data/lib/jekyll/KargWare/Shorten/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 012dee8b1fc72f257b2e457836d2b8f56cc3faac819e57fb0f29336cf3ff2436
|
4
|
+
data.tar.gz: b3203689baedeeef368523c60a6bc272c74642f4348bf7dfc332665836085188
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 443768121201fcbb3a56405c1d25ca797278b4178070445b5ff745113a6efc1f694aff1156f9ea6e073b553c690348eb423db86ae0154e7d4e8847792d015a04
|
7
|
+
data.tar.gz: ed61ccbf42f6b92577d68f8efbc4258f884185b69866a93c93b1484dc2e10c7937177b3bc9303e6b2cdaf6993e89637270fc1e5cc89be8120fd735a5ca6442af
|
data/lib/jekyll-kw-shorten.rb
CHANGED
@@ -35,11 +35,11 @@ module Jekyll
|
|
35
35
|
|
36
36
|
# shorten filter {{ number | shorten }} for Jekyll
|
37
37
|
module ShortenFilter
|
38
|
-
def shorten(
|
38
|
+
def shorten(input)
|
39
39
|
parser = Jekyll::KargWare::Shorten::Parser.new(
|
40
40
|
Jekyll::KargWare::Shorten.get_plugin_config(@context)
|
41
41
|
)
|
42
|
-
parser.parse(
|
42
|
+
parser.parse(input)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -7,6 +7,9 @@ module Jekyll
|
|
7
7
|
module Shorten
|
8
8
|
# jekyll-kw-shorten parser class
|
9
9
|
class Parser
|
10
|
+
# https://stackoverflow.com/questions/33952093/how-to-allow-only-one-dot-in-regex
|
11
|
+
DIGITS_AND_SINGLE_DOT_ESCAPE_REGEXP = /(-?\s?[0-9]+(\.[0-9]+)?)/.freeze
|
12
|
+
|
10
13
|
attr_reader :configuration
|
11
14
|
|
12
15
|
def initialize(options = {})
|
@@ -14,10 +17,11 @@ module Jekyll
|
|
14
17
|
end
|
15
18
|
|
16
19
|
def parse(text)
|
17
|
-
|
20
|
+
num = Parser.only_float_numbers(text)
|
21
|
+
|
22
|
+
return text unless Parser.number?(num)
|
18
23
|
|
19
24
|
begin
|
20
|
-
num = text.to_f
|
21
25
|
if num >= 1000000000000
|
22
26
|
'∞ 🚀'
|
23
27
|
elsif num >= 1000000000
|
@@ -43,9 +47,16 @@ module Jekyll
|
|
43
47
|
|
44
48
|
def self.number?(string)
|
45
49
|
true if Float(string)
|
50
|
+
# true if Float(Parser.only_float_numbers(string))
|
46
51
|
rescue StandardError
|
47
52
|
false
|
48
53
|
end
|
54
|
+
|
55
|
+
def self.only_float_numbers(input)
|
56
|
+
input.to_s.scan(DIGITS_AND_SINGLE_DOT_ESCAPE_REGEXP).first.first.to_f
|
57
|
+
rescue StandardError
|
58
|
+
input
|
59
|
+
end
|
49
60
|
end
|
50
61
|
end
|
51
62
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-kw-shorten
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Karg
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-01-
|
12
|
+
date: 2021-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jekyll
|