jekyll-recker 1.7.0 → 1.8.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/lib/jekyll-recker.rb +17 -15
- data/lib/jekyll_recker/commands.rb +18 -22
- data/lib/jekyll_recker/configuration.rb +26 -28
- data/lib/jekyll_recker/error.rb +3 -5
- data/lib/jekyll_recker/extensions.rb +38 -0
- data/lib/jekyll_recker/filters.rb +7 -9
- data/lib/jekyll_recker/generators.rb +83 -85
- data/lib/jekyll_recker/mixins.rb +28 -30
- data/lib/jekyll_recker/shell.rb +5 -5
- data/lib/jekyll_recker/social.rb +128 -126
- data/lib/jekyll_recker/tags.rb +7 -9
- data/lib/jekyll_recker/utils.rb +37 -0
- data/lib/jekyll_recker/version.rb +2 -4
- metadata +3 -2
- data/lib/jekyll_recker/words.rb +0 -82
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78979b0c186d78e9296b547ead2c4f5a908945d7fe83fa498984e9dfa8766fc6
|
4
|
+
data.tar.gz: dc418d310aec0d6245d637e4ac5f20c428f07f954d7416cb03794781d58e263c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70a080461c6462a80c0296a5573f91f2d8f0eb5995d9fda6be73d018af4cd1999cd1816fb7ca18949a18abd06a05740daefc358f2db9f26e37d4249b21207ad4
|
7
|
+
data.tar.gz: 96d7b050be0ad82ae2da7d1e1cadfe4aa328f4f3a780a800243d2027646a16babc22c030619289f8122899accfc24c40546fa2fa443aa70373b15c0280facaa0
|
data/lib/jekyll-recker.rb
CHANGED
@@ -2,20 +2,22 @@
|
|
2
2
|
|
3
3
|
require 'jekyll'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
# jekyll-recker
|
6
|
+
#
|
7
|
+
# The greatest jekyll plugin in the world
|
8
|
+
module JekyllRecker
|
9
|
+
autoload :Configuration, 'jekyll_recker/configuration.rb'
|
10
|
+
autoload :Error, 'jekyll_recker/error.rb'
|
11
|
+
autoload :Mixins, 'jekyll_recker/mixins.rb'
|
12
|
+
autoload :Shell, 'jekyll_recker/shell.rb'
|
13
|
+
autoload :Social, 'jekyll_recker/social.rb'
|
14
|
+
autoload :VERSION, 'jekyll_recker/version.rb'
|
15
|
+
autoload :Utils, 'jekyll_recker/utils.rb'
|
9
16
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
require 'jekyll_recker/social.rb'
|
17
|
-
require 'jekyll_recker/tags.rb'
|
18
|
-
require 'jekyll_recker/version.rb'
|
19
|
-
require 'jekyll_recker/words.rb'
|
20
|
-
end
|
17
|
+
# Eager loads!
|
18
|
+
require 'jekyll_recker/commands.rb'
|
19
|
+
require 'jekyll_recker/extensions.rb'
|
20
|
+
require 'jekyll_recker/filters.rb'
|
21
|
+
require 'jekyll_recker/generators.rb'
|
22
|
+
require 'jekyll_recker/tags.rb'
|
21
23
|
end
|
@@ -1,30 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
include Mixins::Logging
|
3
|
+
module JekyllRecker
|
4
|
+
# Commands
|
5
|
+
module Commands
|
6
|
+
# Share
|
7
|
+
class Share < Jekyll::Command
|
8
|
+
include Mixins::Logging
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
10
|
+
def self.init_with_program(prog)
|
11
|
+
prog.command(:share) do |c|
|
12
|
+
c.syntax 'share'
|
13
|
+
c.description 'Share latest post with each configured backend'
|
14
|
+
c.option 'dry', '-d', '--dry', 'perform dry run'
|
15
|
+
c.action { |args, opts| action(args, opts) }
|
18
16
|
end
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
logger.error e.message
|
26
|
-
exit 1
|
27
|
-
end
|
19
|
+
def self.action(args, options)
|
20
|
+
JekyllRecker::Social.action(args, options)
|
21
|
+
rescue ::JekyllRecker::Error => e
|
22
|
+
logger.error e.message
|
23
|
+
exit 1
|
28
24
|
end
|
29
25
|
end
|
30
26
|
end
|
@@ -1,39 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
3
|
+
module JekyllRecker
|
4
|
+
# Configuration
|
5
|
+
module Configuration
|
6
|
+
def self.jekyll
|
7
|
+
@jekyll ||= Jekyll.configuration
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def self.recker
|
11
|
+
jekyll.fetch('recker', {})
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def self.facebook
|
15
|
+
recker.fetch('facebook', {})
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def self.twitter
|
19
|
+
recker.fetch('twitter', {})
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
def self.slack
|
23
|
+
recker.fetch('slack', {})
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
def self.site
|
27
|
+
@site = Jekyll::Site.new(jekyll)
|
28
|
+
@site.reset
|
29
|
+
@site.read
|
30
|
+
@site
|
31
|
+
end
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
end
|
33
|
+
def self.latest_post
|
34
|
+
@latest_post ||= site.posts.docs.last
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
data/lib/jekyll_recker/error.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Integer extensions
|
4
|
+
class Integer
|
5
|
+
def pretty
|
6
|
+
JekyllRecker::Utils.prettify_number(self)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# String extensions
|
11
|
+
class String
|
12
|
+
def words
|
13
|
+
JekyllRecker::Utils.to_word_list(self)
|
14
|
+
end
|
15
|
+
|
16
|
+
def word_count
|
17
|
+
JekyllRecker::Utils.to_word_list(self).count
|
18
|
+
end
|
19
|
+
|
20
|
+
def pretty_path(home = nil)
|
21
|
+
JekyllRecker::Utils.prettify_path(self, home)
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_and_array
|
25
|
+
JekyllRecker::Utils.and_list_to_array(self)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Array extensions
|
30
|
+
class Array
|
31
|
+
def to_and_list
|
32
|
+
JekyllRecker::Utils.array_to_and_list(self)
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_weighted_list
|
36
|
+
JekyllRecker::Utils.to_weighted_list(self)
|
37
|
+
end
|
38
|
+
end
|
@@ -1,15 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
date.strftime('%A, %B %d %Y')
|
10
|
-
end
|
3
|
+
module JekyllRecker
|
4
|
+
# Filters
|
5
|
+
module Filters
|
6
|
+
# Converts a date object to standard Uhh Yeah Dude format.
|
7
|
+
def uyd_date(date)
|
8
|
+
date.strftime('%A, %B %d %Y')
|
11
9
|
end
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
15
|
-
Liquid::Template.register_filter(
|
13
|
+
Liquid::Template.register_filter(JekyllRecker::Filters)
|
@@ -1,111 +1,109 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
4
|
-
module
|
5
|
-
|
6
|
-
|
3
|
+
module JekyllRecker
|
4
|
+
module Generators
|
5
|
+
# Stats Module
|
6
|
+
#
|
7
|
+
# Functions for stats generators.
|
8
|
+
# @abstract
|
9
|
+
module Stats
|
10
|
+
include Mixins::Logging
|
11
|
+
include Jekyll::Filters
|
12
|
+
|
13
|
+
def key
|
14
|
+
self.class.const_get(:KEY)
|
15
|
+
end
|
16
|
+
|
17
|
+
def generate(site)
|
18
|
+
@site = site
|
19
|
+
logger.info "crunching stats.#{key}"
|
20
|
+
@site.data['stats'] ||= {}
|
21
|
+
@site.data['stats'][key] = crunch
|
22
|
+
end
|
23
|
+
|
24
|
+
def crunch
|
25
|
+
raise NotImplementedError, '#crunch not implemented!'
|
26
|
+
end
|
27
|
+
|
28
|
+
# Calculates the average of a list of numbers.
|
7
29
|
#
|
8
|
-
#
|
9
|
-
# @
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def key
|
15
|
-
self.class.const_get(:KEY)
|
16
|
-
end
|
30
|
+
# @param [Array<Numeric>] numlist list of numbers to be averaged.
|
31
|
+
# @return [Numeric] rounded, calculated average of numlist.
|
32
|
+
def average(numlist)
|
33
|
+
calc = numlist.inject { |sum, el| sum + el }.to_f / numlist.size
|
34
|
+
calc.round
|
35
|
+
end
|
17
36
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
37
|
+
# Calculates the total of a list of numbers.
|
38
|
+
#
|
39
|
+
# @param [Array<Numeric>] numlist list of numbers to be totaled.
|
40
|
+
# @return [Numeric] calculated total of numlist.
|
41
|
+
def total(numlist)
|
42
|
+
numlist.inject(0) { |sum, x| sum + x }
|
43
|
+
end
|
24
44
|
|
25
|
-
|
26
|
-
|
27
|
-
|
45
|
+
def entries
|
46
|
+
@site.posts.docs.select(&:published?)
|
47
|
+
end
|
48
|
+
end
|
28
49
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
# @return [Numeric] rounded, calculated average of numlist.
|
33
|
-
def average(numlist)
|
34
|
-
calc = numlist.inject { |sum, el| sum + el }.to_f / numlist.size
|
35
|
-
calc.round
|
36
|
-
end
|
50
|
+
# Post Count Generator
|
51
|
+
class PostCount < Jekyll::Generator
|
52
|
+
include Stats
|
37
53
|
|
38
|
-
|
39
|
-
#
|
40
|
-
# @param [Array<Numeric>] numlist list of numbers to be totaled.
|
41
|
-
# @return [Numeric] calculated total of numlist.
|
42
|
-
def total(numlist)
|
43
|
-
numlist.inject(0) { |sum, x| sum + x }
|
44
|
-
end
|
54
|
+
KEY = 'posts'
|
45
55
|
|
46
|
-
|
47
|
-
|
48
|
-
end
|
56
|
+
def crunch
|
57
|
+
entries.count.pretty
|
49
58
|
end
|
59
|
+
end
|
50
60
|
|
51
|
-
|
52
|
-
|
53
|
-
|
61
|
+
# Word Count Generator
|
62
|
+
class Words < Jekyll::Generator
|
63
|
+
include Stats
|
54
64
|
|
55
|
-
|
65
|
+
KEY = 'words'
|
56
66
|
|
57
|
-
|
58
|
-
|
59
|
-
|
67
|
+
def crunch
|
68
|
+
total_counts = entries.collect(&:content).map { |c| number_of_words(c) }
|
69
|
+
{
|
70
|
+
'average' => average(total_counts).pretty,
|
71
|
+
'total' => total(total_counts).pretty
|
72
|
+
}
|
60
73
|
end
|
74
|
+
end
|
61
75
|
|
62
|
-
|
63
|
-
|
64
|
-
|
76
|
+
# Streak Count Generator
|
77
|
+
class Streaks < Jekyll::Generator
|
78
|
+
include Stats
|
65
79
|
|
66
|
-
|
80
|
+
KEY = 'days'
|
67
81
|
|
68
|
-
|
69
|
-
|
82
|
+
def crunch
|
83
|
+
streaks.take(1).map do |count, dates|
|
70
84
|
{
|
71
|
-
'
|
72
|
-
'
|
85
|
+
'days' => count.pretty,
|
86
|
+
'start' => dates[0],
|
87
|
+
'end' => dates[1]
|
73
88
|
}
|
74
|
-
end
|
89
|
+
end.first
|
75
90
|
end
|
76
91
|
|
77
|
-
|
78
|
-
class Streaks < Jekyll::Generator
|
79
|
-
include Stats
|
80
|
-
|
81
|
-
KEY = 'days'
|
82
|
-
|
83
|
-
def crunch
|
84
|
-
streaks.take(1).map do |count, dates|
|
85
|
-
{
|
86
|
-
'days' => count.pretty,
|
87
|
-
'start' => dates[0],
|
88
|
-
'end' => dates[1]
|
89
|
-
}
|
90
|
-
end.first
|
91
|
-
end
|
92
|
+
private
|
92
93
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
first, last = dates.minmax
|
101
|
-
_streaks << [(last - first).to_i, [first, last]]
|
102
|
-
end
|
103
|
-
_streaks
|
94
|
+
def streaks
|
95
|
+
_streaks = []
|
96
|
+
entry_dates.slice_when do |prev, curr|
|
97
|
+
curr != prev - 1
|
98
|
+
end.each do |dates|
|
99
|
+
first, last = dates.minmax
|
100
|
+
_streaks << [(last - first).to_i, [first, last]]
|
104
101
|
end
|
102
|
+
_streaks
|
103
|
+
end
|
105
104
|
|
106
|
-
|
107
|
-
|
108
|
-
end
|
105
|
+
def entry_dates
|
106
|
+
entries.collect(&:date).map { |t| Date.new(t.year, t.month, t.day) }.sort.reverse
|
109
107
|
end
|
110
108
|
end
|
111
109
|
end
|
data/lib/jekyll_recker/mixins.rb
CHANGED
@@ -2,43 +2,41 @@
|
|
2
2
|
|
3
3
|
require 'logger'
|
4
4
|
|
5
|
-
module
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
5
|
+
module JekyllRecker
|
6
|
+
module Mixins
|
7
|
+
# Descendants
|
8
|
+
module Descendants
|
9
|
+
def self.included(base)
|
10
|
+
base.extend(self)
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
end
|
13
|
+
def descendants
|
14
|
+
ObjectSpace.each_object(Class).select { |klass| klass < self }
|
17
15
|
end
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
# Introspection
|
19
|
+
module Introspection
|
20
|
+
def self.included(base)
|
21
|
+
base.extend(self)
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
end
|
24
|
+
def class_name
|
25
|
+
self.class.name.split('::').last
|
28
26
|
end
|
27
|
+
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
# Logging
|
30
|
+
module Logging
|
31
|
+
def self.included(base)
|
32
|
+
base.extend(self)
|
33
|
+
end
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
35
|
+
def logger
|
36
|
+
@logger ||= Logger.new(
|
37
|
+
STDOUT,
|
38
|
+
formatter: proc { |_severity, _datetime, _progname, msg| "jekyll-recker: #{msg}\n" }
|
39
|
+
)
|
42
40
|
end
|
43
41
|
end
|
44
42
|
end
|
data/lib/jekyll_recker/shell.rb
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
require 'open3'
|
4
4
|
|
5
|
-
module
|
6
|
-
#
|
7
|
-
module
|
5
|
+
module JekyllRecker
|
6
|
+
# Shell
|
7
|
+
module Shell
|
8
8
|
# ShellCommandFailed
|
9
|
-
class ShellCommandFailed <
|
9
|
+
class ShellCommandFailed < JekyllRecker::Error; end
|
10
10
|
|
11
|
-
def self.
|
11
|
+
def self.run(cmd)
|
12
12
|
out, err, status = Open3.capture3(cmd)
|
13
13
|
return out if status.success?
|
14
14
|
|
data/lib/jekyll_recker/social.rb
CHANGED
@@ -3,170 +3,172 @@
|
|
3
3
|
require 'slack-notifier'
|
4
4
|
require 'twitter'
|
5
5
|
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
6
|
+
module JekyllRecker
|
7
|
+
module Social
|
8
|
+
def self.action(args, options)
|
9
|
+
args += %w[slack twitter] if args.empty?
|
10
|
+
Slack.share(dry: options['dry']) if args.include?('slack')
|
11
|
+
Twitter.share(dry: options['dry']) if args.include?('twitter')
|
12
|
+
end
|
13
|
+
# Backend
|
14
|
+
#
|
15
|
+
# Backend base class for social sharing backends.
|
16
|
+
# @abstract
|
17
|
+
class Share
|
18
|
+
include Mixins::Introspection
|
19
|
+
include Mixins::Logging
|
20
|
+
|
21
|
+
def self.share(dry: false)
|
22
|
+
backend = new(dry: dry)
|
23
|
+
logger.info "#{backend.name} - building configuration"
|
24
|
+
backend.configure!
|
25
|
+
|
26
|
+
logger.info "#{backend.name} - sharing \"#{backend.latest_title}\""
|
27
|
+
backend.post!
|
28
|
+
end
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
+
def initialize(dry: false)
|
31
|
+
@dry = dry
|
32
|
+
end
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
def dry?
|
35
|
+
@dry
|
36
|
+
end
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
def config
|
39
|
+
@config ||= JekyllRecker::Configuration.recker.fetch(config_key)
|
40
|
+
end
|
38
41
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
42
|
+
def config_key
|
43
|
+
class_name.downcase
|
44
|
+
end
|
45
|
+
alias name config_key
|
43
46
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
+
def post_body
|
48
|
+
url = File.join Configuration.jekyll['url'], latest.url
|
49
|
+
<<~BODY
|
47
50
|
#{latest.data['date'].strftime('%A, %B %-d %Y')}
|
48
51
|
#{latest.data['title']}
|
49
52
|
#{url}
|
50
53
|
BODY
|
51
|
-
|
52
|
-
|
53
|
-
def latest
|
54
|
-
@latest ||= Configuration.latest_post
|
55
|
-
end
|
54
|
+
end
|
56
55
|
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
def latest
|
57
|
+
@latest ||= Configuration.latest_post
|
58
|
+
end
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
def latest_title
|
61
|
+
latest.data['title']
|
62
|
+
end
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
end
|
64
|
+
def configure!
|
65
|
+
raise NotImplementedError
|
68
66
|
end
|
69
67
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
def configure!
|
75
|
-
@creds = {}
|
76
|
-
workspaces.each do |key, data|
|
77
|
-
webhook = ENV["SLACK_#{key.upcase}_WEBHOOK"] || extract_from_config(data)
|
78
|
-
if webhook.nil?
|
79
|
-
raise ReckerError, "cannot find slack webhook for #{key} workspace!"
|
80
|
-
end
|
68
|
+
def post!
|
69
|
+
raise NotImplementedError
|
70
|
+
end
|
71
|
+
end
|
81
72
|
|
82
|
-
|
73
|
+
# Slack
|
74
|
+
#
|
75
|
+
# Slack social sharing backend
|
76
|
+
class Slack < Share
|
77
|
+
def configure!
|
78
|
+
@creds = {}
|
79
|
+
workspaces.each do |key, data|
|
80
|
+
webhook = ENV["SLACK_#{key.upcase}_WEBHOOK"] || extract_from_config(data)
|
81
|
+
if webhook.nil?
|
82
|
+
raise ReckerError, "cannot find slack webhook for #{key} workspace!"
|
83
83
|
end
|
84
|
+
|
85
|
+
@creds[key] = webhook
|
84
86
|
end
|
87
|
+
end
|
85
88
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
end
|
89
|
+
def post!
|
90
|
+
message_body = ::Slack::Notifier::Util::LinkFormatter.format(post_body)
|
91
|
+
workspaces.each do |key, config|
|
92
|
+
logger.info "posting to #{key} workspace"
|
93
|
+
if @dry
|
94
|
+
logger.info("BEGIN MESSAGE\n#{message_body.strip}\nEND MESSAGE")
|
95
|
+
else
|
96
|
+
::Slack::Notifier.new(
|
97
|
+
@creds[key].strip,
|
98
|
+
channel: config.fetch('channel'),
|
99
|
+
username: config.fetch('username'),
|
100
|
+
icon_emoji: config.fetch('emoji')
|
101
|
+
).post(text: message_body)
|
100
102
|
end
|
101
103
|
end
|
104
|
+
end
|
102
105
|
|
103
|
-
|
106
|
+
private
|
104
107
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
+
def extract_from_config(data)
|
109
|
+
cmd = data['webhook_cmd']
|
110
|
+
return nil if cmd.nil?
|
108
111
|
|
109
|
-
|
110
|
-
|
112
|
+
Shell.run(cmd)
|
113
|
+
end
|
111
114
|
|
112
|
-
|
113
|
-
|
114
|
-
end
|
115
|
+
def workspaces
|
116
|
+
config.each
|
115
117
|
end
|
118
|
+
end
|
116
119
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
120
|
+
# Twitter
|
121
|
+
#
|
122
|
+
# Twitter social sharing backend
|
123
|
+
class Twitter < Share
|
124
|
+
def configure!
|
125
|
+
creds = extract_from_env || extract_from_config
|
126
|
+
raise ReckerError, 'cannot find twitter credentials!' if creds.nil?
|
124
127
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
end
|
128
|
+
@client = ::Twitter::REST::Client.new do |settings|
|
129
|
+
settings.consumer_key = creds['consumer_api_key']
|
130
|
+
settings.consumer_secret = creds['consumer_api_secret']
|
131
|
+
settings.access_token = creds['access_token']
|
132
|
+
settings.access_token_secret = creds['access_token_secret']
|
131
133
|
end
|
134
|
+
end
|
132
135
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
end
|
136
|
+
def post!
|
137
|
+
if dry?
|
138
|
+
logger.info('tweeting in dry mode, printing message')
|
139
|
+
logger.info("BEGIN TWEET\n#{post_body}END TWEET")
|
140
|
+
else
|
141
|
+
@client.update(post_body)
|
140
142
|
end
|
143
|
+
end
|
141
144
|
|
142
|
-
|
145
|
+
private
|
143
146
|
|
144
|
-
|
145
|
-
|
147
|
+
def extract_from_env
|
148
|
+
values = cred_fieldnames.map { |k| ENV["TWITTER_#{k.upcase}"] }
|
146
149
|
|
147
|
-
|
150
|
+
return nil if values.any? { |v| v.nil? || v.empty? }
|
148
151
|
|
149
|
-
|
150
|
-
|
152
|
+
Hash[cred_fieldnames.zip(values)]
|
153
|
+
end
|
151
154
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
155
|
+
def extract_from_config
|
156
|
+
values = cred_fieldnames.map do |k|
|
157
|
+
Shell.run(Configuration.twitter["#{k}_cmd"]).strip
|
158
|
+
end
|
156
159
|
|
157
|
-
|
160
|
+
return nil if values.any? { |v| v.nil? || v.empty? }
|
158
161
|
|
159
|
-
|
160
|
-
|
162
|
+
Hash[cred_fieldnames.zip(values)]
|
163
|
+
end
|
161
164
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
end
|
165
|
+
def cred_fieldnames
|
166
|
+
[
|
167
|
+
'access_token_secret',
|
168
|
+
'access_token',
|
169
|
+
'consumer_api_key',
|
170
|
+
'consumer_api_secret'
|
171
|
+
]
|
170
172
|
end
|
171
173
|
end
|
172
174
|
end
|
data/lib/jekyll_recker/tags.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
VERSION
|
10
|
-
end
|
3
|
+
module JekyllRecker
|
4
|
+
module Tags
|
5
|
+
# Returns the VERSION of the running jekyll-recker gem.
|
6
|
+
class Version < Liquid::Tag
|
7
|
+
def render(_context)
|
8
|
+
VERSION
|
11
9
|
end
|
12
10
|
end
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
16
|
-
Liquid::Template.register_tag('recker_version',
|
14
|
+
Liquid::Template.register_tag('recker_version', JekyllRecker::Tags::Version)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JekyllRecker
|
4
|
+
# Utils
|
5
|
+
module Utils
|
6
|
+
def self.array_to_and_list(array)
|
7
|
+
case array.length
|
8
|
+
when 0
|
9
|
+
''
|
10
|
+
when 1
|
11
|
+
array.first
|
12
|
+
when 2
|
13
|
+
"#{array.first} and #{array.last}"
|
14
|
+
else
|
15
|
+
array[0...-1].join(', ') + ", and #{array.last}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.and_list_to_array(str)
|
20
|
+
str = str.gsub(' and ', ', ')
|
21
|
+
str.split(',').map(&:strip).reject(&:empty?)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.prettify_number(number)
|
25
|
+
number.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.prettify_path(path, home = nil)
|
29
|
+
home ||= File.expand_path('~/')
|
30
|
+
path.sub(home, '~')
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.to_word_list(str)
|
34
|
+
str.split(' ')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-recker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Recker
|
@@ -158,14 +158,15 @@ files:
|
|
158
158
|
- lib/jekyll_recker/commands.rb
|
159
159
|
- lib/jekyll_recker/configuration.rb
|
160
160
|
- lib/jekyll_recker/error.rb
|
161
|
+
- lib/jekyll_recker/extensions.rb
|
161
162
|
- lib/jekyll_recker/filters.rb
|
162
163
|
- lib/jekyll_recker/generators.rb
|
163
164
|
- lib/jekyll_recker/mixins.rb
|
164
165
|
- lib/jekyll_recker/shell.rb
|
165
166
|
- lib/jekyll_recker/social.rb
|
166
167
|
- lib/jekyll_recker/tags.rb
|
168
|
+
- lib/jekyll_recker/utils.rb
|
167
169
|
- lib/jekyll_recker/version.rb
|
168
|
-
- lib/jekyll_recker/words.rb
|
169
170
|
homepage: https://www.github.com/arecker/jekyll-recker/
|
170
171
|
licenses:
|
171
172
|
- GPLv3
|
data/lib/jekyll_recker/words.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
module Recker
|
5
|
-
# Words
|
6
|
-
module Words
|
7
|
-
def self.array_to_and_list(array)
|
8
|
-
case array.length
|
9
|
-
when 0
|
10
|
-
''
|
11
|
-
when 1
|
12
|
-
array.first
|
13
|
-
when 2
|
14
|
-
"#{array.first} and #{array.last}"
|
15
|
-
else
|
16
|
-
array[0...-1].join(', ') + ", and #{array.last}"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.and_list_to_array(str)
|
21
|
-
str = str.gsub(' and ', ', ')
|
22
|
-
str.split(',').map(&:strip).reject(&:empty?)
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.prettify_number(number)
|
26
|
-
number.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.prettify_path(path, home = nil)
|
30
|
-
home ||= File.expand_path('~/')
|
31
|
-
path.sub(home, '~')
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.to_word_list(str)
|
35
|
-
str.split(' ')
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.to_weighted_list(arr)
|
39
|
-
arr.uniq.map do |word|
|
40
|
-
[word, arr.count(word)]
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# Array extensions
|
48
|
-
class Array
|
49
|
-
def to_and_list
|
50
|
-
Jekyll::Recker::Words.array_to_and_list(self)
|
51
|
-
end
|
52
|
-
|
53
|
-
def to_weighted_list
|
54
|
-
Jekyll::Recker::Words.to_weighted_list(self)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Integer extensions
|
59
|
-
class Integer
|
60
|
-
def pretty
|
61
|
-
Jekyll::Recker::Words.prettify_number(self)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# String extensions
|
66
|
-
class String
|
67
|
-
def words
|
68
|
-
Jekyll::Recker::Words.to_word_list(self)
|
69
|
-
end
|
70
|
-
|
71
|
-
def word_count
|
72
|
-
Jekyll::Recker::Words.to_word_list(self).count
|
73
|
-
end
|
74
|
-
|
75
|
-
def pretty_path(home = nil)
|
76
|
-
Jekyll::Recker::Words.prettify_path(self, home)
|
77
|
-
end
|
78
|
-
|
79
|
-
def to_and_array
|
80
|
-
Jekyll::Recker::Words.and_list_to_array(self)
|
81
|
-
end
|
82
|
-
end
|