jekyll-recker 2.2.0 → 2.3.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/commands.rb +1 -1
- data/lib/jekyll_recker/date.rb +4 -0
- data/lib/jekyll_recker/entry.rb +16 -1
- data/lib/jekyll_recker/generators.rb +74 -63
- data/lib/jekyll_recker/graphs.rb +36 -27
- data/lib/jekyll_recker/logging.rb +5 -4
- data/lib/jekyll_recker/math.rb +8 -0
- data/lib/jekyll_recker/site.rb +47 -1
- data/lib/jekyll_recker/social.rb +18 -17
- data/lib/jekyll_recker/version.rb +1 -1
- metadata +2 -3
- data/lib/jekyll_recker/generators/image_resize.rb +0 -58
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7de0dd41444c7a9cec90c5dfc035b3544efc0096e2b36cab9131c50122ead0b7
|
4
|
+
data.tar.gz: ed2122a9180d19f534c5dded62a8abcef9b56a94aad951e63fcdd30b3cf6a22f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78c36674f14a242e76bc2c82ffa9410d70e0f5f1cc9da1bbd5a26c47a12609e583101b7876ed7d56ff8e1bb3da45cab7da207cf51d05b8651958a00acf276781
|
7
|
+
data.tar.gz: ba89a46a1c2c48a6484bbcfab4b3e62e34c344423c1707ccb6497c086bde93a127517b5bfbba10ba4f749cc6d78cffd6d30e048fa170a823e50c1bf7031d9cf4
|
data/lib/jekyll_recker/date.rb
CHANGED
data/lib/jekyll_recker/entry.rb
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
module JekyllRecker
|
4
4
|
# Entry
|
5
5
|
class Entry
|
6
|
+
include Date
|
7
|
+
include Filters
|
8
|
+
|
6
9
|
def initialize(doc)
|
7
10
|
@doc = doc
|
8
11
|
end
|
@@ -12,7 +15,19 @@ module JekyllRecker
|
|
12
15
|
end
|
13
16
|
|
14
17
|
def date
|
15
|
-
@date ||=
|
18
|
+
@date ||= time_to_date(@doc.date)
|
19
|
+
end
|
20
|
+
|
21
|
+
def title
|
22
|
+
uyd_date(date)
|
23
|
+
end
|
24
|
+
|
25
|
+
def subtitle
|
26
|
+
@doc.data['title']
|
27
|
+
end
|
28
|
+
|
29
|
+
def url
|
30
|
+
@doc.url
|
16
31
|
end
|
17
32
|
|
18
33
|
def words
|
@@ -1,93 +1,53 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'bundler'
|
4
|
-
|
5
3
|
module JekyllRecker
|
6
4
|
# Generators Module
|
7
5
|
module Generators
|
8
|
-
# Base Generator
|
6
|
+
# Base Generator
|
9
7
|
module Base
|
10
8
|
include Date
|
11
9
|
include Logging
|
12
10
|
include Math
|
13
|
-
|
14
|
-
def production?
|
15
|
-
ENV['JEKYLL_ENV'] == 'production'
|
16
|
-
end
|
17
|
-
|
18
|
-
def word_counts
|
19
|
-
@word_counts ||= bodies.map(&:split).map(&:size)
|
20
|
-
end
|
21
|
-
|
22
|
-
def words
|
23
|
-
bodies.map(&:split).flatten
|
24
|
-
end
|
25
|
-
|
26
|
-
def bodies
|
27
|
-
entries.collect(&:content)
|
28
|
-
end
|
29
|
-
|
30
|
-
def entries
|
31
|
-
@site.posts.docs.select(&:published?).sort_by(&:date).reverse
|
32
|
-
end
|
33
|
-
|
34
|
-
def dates
|
35
|
-
entries.collect(&:date).map { |t| ::Date.new(t.year, t.month, t.day) }
|
36
|
-
end
|
37
11
|
end
|
38
12
|
|
39
13
|
# Stats Generator
|
40
14
|
class Stats < Jekyll::Generator
|
41
15
|
include Base
|
42
|
-
|
16
|
+
|
17
|
+
attr_reader :site
|
43
18
|
|
44
19
|
def generate(site)
|
45
|
-
@site = site
|
46
|
-
|
47
|
-
@site.
|
48
|
-
|
49
|
-
logger.info 'production detected. skipping graphs'
|
20
|
+
@site = Site.new(site)
|
21
|
+
generate_stats!
|
22
|
+
if @site.production?
|
23
|
+
info 'production detected. skipping graphs'
|
50
24
|
else
|
51
|
-
|
52
|
-
|
53
|
-
generate_graphs(entries, swear_results, graphs_dir)
|
25
|
+
info 'generating graphs'
|
26
|
+
Graphs.generate_graphs(@site)
|
54
27
|
end
|
55
28
|
end
|
56
29
|
|
57
|
-
def
|
58
|
-
|
59
|
-
|
60
|
-
'
|
61
|
-
'
|
62
|
-
'
|
63
|
-
'
|
64
|
-
|
65
|
-
'words' => swear_results
|
66
|
-
}
|
30
|
+
def generate_stats!
|
31
|
+
info 'calculating statistics'
|
32
|
+
site.data['stats'] = {
|
33
|
+
'total_words' => total(site.word_counts),
|
34
|
+
'average_words' => average(site.word_counts),
|
35
|
+
'total_posts' => site.entries.size,
|
36
|
+
'consecutive_posts' => calculate_streaks(site.dates).first['days'],
|
37
|
+
'swears' => calculate_swears
|
67
38
|
}
|
68
39
|
end
|
69
40
|
|
70
41
|
private
|
71
42
|
|
72
|
-
def
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
def graphs_dir
|
77
|
-
recker = @site.config.fetch('recker', {})
|
78
|
-
recker.fetch('graphs', 'assets/images/graphs/')
|
43
|
+
def calculate_swears
|
44
|
+
results = Hash[count_swears]
|
45
|
+
results['total'] = total(results.values)
|
46
|
+
results
|
79
47
|
end
|
80
48
|
|
81
49
|
def count_swears
|
82
|
-
|
83
|
-
bodies.map(&:split).each do |words|
|
84
|
-
words = words.map(&:downcase)
|
85
|
-
swears.each do |swear|
|
86
|
-
count = words.count(swear)
|
87
|
-
results[swear] += count
|
88
|
-
end
|
89
|
-
end
|
90
|
-
results.reject { |_k, v| v.zero? }.sort_by { |_k, v| -v }
|
50
|
+
occurences(swears, site.words).reject { |_k, v| v.zero? }.sort_by { |_k, v| -v }
|
91
51
|
end
|
92
52
|
|
93
53
|
def swears
|
@@ -107,6 +67,57 @@ module JekyllRecker
|
|
107
67
|
]
|
108
68
|
end
|
109
69
|
end
|
110
|
-
|
70
|
+
|
71
|
+
# Image Resize Generator
|
72
|
+
class ImageResize < Jekyll::Generator
|
73
|
+
include Base
|
74
|
+
|
75
|
+
attr_reader :site
|
76
|
+
|
77
|
+
def generate(site)
|
78
|
+
@site = Site.new(site)
|
79
|
+
|
80
|
+
if @site.production?
|
81
|
+
info 'production detected, skipping images'
|
82
|
+
return
|
83
|
+
end
|
84
|
+
|
85
|
+
load_deps!
|
86
|
+
|
87
|
+
info 'checking images'
|
88
|
+
resizeable_images.each do |f, d|
|
89
|
+
info "resizing #{f} to fit #{d}"
|
90
|
+
image = MiniMagick::Image.new(f)
|
91
|
+
image.resize d
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def too_big?(width, height)
|
96
|
+
width > 800 || height > 800
|
97
|
+
end
|
98
|
+
|
99
|
+
def load_deps!
|
100
|
+
require 'fastimage'
|
101
|
+
require 'mini_magick'
|
102
|
+
end
|
103
|
+
|
104
|
+
def graph?(file)
|
105
|
+
file.include?('/graphs/')
|
106
|
+
end
|
107
|
+
|
108
|
+
def resizeable_images
|
109
|
+
without_graphs = site.images.reject { |i| graph?(i) }
|
110
|
+
with_sizes = without_graphs.map { |f| [f, FastImage.size(f)].flatten }
|
111
|
+
with_sizes.select! { |f| too_big?(f[1], f[2]) }
|
112
|
+
with_sizes.map do |f, w, h|
|
113
|
+
dimensions = if w > h
|
114
|
+
'800x600'
|
115
|
+
else
|
116
|
+
'600x800'
|
117
|
+
end
|
118
|
+
[f, dimensions]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
111
122
|
end
|
112
123
|
end
|
data/lib/jekyll_recker/graphs.rb
CHANGED
@@ -5,44 +5,55 @@ require 'bundler'
|
|
5
5
|
module JekyllRecker
|
6
6
|
# Graphs module
|
7
7
|
module Graphs
|
8
|
-
def generate_graphs(
|
9
|
-
|
10
|
-
|
8
|
+
def self.generate_graphs(site)
|
9
|
+
require 'gruff'
|
10
|
+
WordCount.new(site).write
|
11
|
+
Swears.new(site).write
|
12
|
+
end
|
13
|
+
|
14
|
+
# Base Graph
|
15
|
+
module Base
|
16
|
+
attr_reader :site
|
17
|
+
|
18
|
+
def graphs_join(path)
|
19
|
+
File.join Bundler.root, @graphs_dir, path
|
20
|
+
end
|
11
21
|
end
|
12
22
|
|
13
23
|
# Word Count Graph
|
14
24
|
class WordCount
|
15
|
-
|
16
|
-
|
17
|
-
|
25
|
+
include Base
|
26
|
+
|
27
|
+
def initialize(site)
|
28
|
+
@site = site
|
29
|
+
@graphs_dir = site.graphs_dir
|
18
30
|
end
|
19
31
|
|
20
|
-
def
|
21
|
-
|
32
|
+
def posts
|
33
|
+
site.entries[0..6].reverse
|
34
|
+
end
|
35
|
+
|
36
|
+
def word_counts
|
37
|
+
site.word_counts[0..6].reverse
|
22
38
|
end
|
23
39
|
|
24
40
|
def title
|
25
41
|
format = '%m/%d/%y'
|
26
|
-
first =
|
27
|
-
last =
|
42
|
+
first = posts.first.date.strftime(format)
|
43
|
+
last = posts.last.date.strftime(format)
|
28
44
|
"Word Count: #{first} - #{last}"
|
29
45
|
end
|
30
46
|
|
31
47
|
def labels
|
32
|
-
Hash[
|
33
|
-
end
|
34
|
-
|
35
|
-
# TODO: copied from jekyll
|
36
|
-
def number_of_words(input)
|
37
|
-
input.split.length
|
48
|
+
Hash[posts.each_with_index.map { |p, i| [i, p.date.strftime('%a')] }]
|
38
49
|
end
|
39
50
|
|
40
51
|
def write
|
41
|
-
g = Gruff::Line.new('800x600')
|
52
|
+
g = ::Gruff::Line.new('800x600')
|
42
53
|
g.theme = Gruff::Themes::PASTEL
|
43
54
|
g.hide_legend = true
|
44
55
|
g.labels = labels
|
45
|
-
g.data :words,
|
56
|
+
g.data :words, word_counts
|
46
57
|
g.title = title
|
47
58
|
g.x_axis_label = 'Day'
|
48
59
|
g.y_axis_label = 'Word Count'
|
@@ -53,20 +64,18 @@ module JekyllRecker
|
|
53
64
|
|
54
65
|
# Swears Chart
|
55
66
|
class Swears
|
56
|
-
|
67
|
+
include Base
|
57
68
|
|
58
|
-
|
59
|
-
@results = results
|
60
|
-
@graphs_dir = graphs_dir
|
61
|
-
end
|
69
|
+
attr_reader :results
|
62
70
|
|
63
|
-
|
64
|
-
|
65
|
-
|
71
|
+
def initialize(site)
|
72
|
+
@results = site.data['stats']['swears'].clone
|
73
|
+
@results.delete('total')
|
74
|
+
@graphs_dir = site.graphs_dir
|
66
75
|
end
|
67
76
|
|
68
77
|
def write
|
69
|
-
g = Gruff::Pie.new('800x600')
|
78
|
+
g = ::Gruff::Pie.new('800x600')
|
70
79
|
g.theme = Gruff::Themes::PASTEL
|
71
80
|
g.hide_legend = false
|
72
81
|
g.legend_at_bottom = true
|
@@ -9,11 +9,12 @@ module JekyllRecker
|
|
9
9
|
base.extend(self)
|
10
10
|
end
|
11
11
|
|
12
|
+
def info(msg)
|
13
|
+
Jekyll.logger.info 'jekyll-recker:', msg
|
14
|
+
end
|
15
|
+
|
12
16
|
def logger
|
13
|
-
|
14
|
-
STDOUT,
|
15
|
-
formatter: proc { |_severity, _datetime, _progname, msg| "jekyll-recker: #{msg}\n" }
|
16
|
-
)
|
17
|
+
::Jekyll.logger
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
data/lib/jekyll_recker/math.rb
CHANGED
@@ -11,5 +11,13 @@ module JekyllRecker
|
|
11
11
|
def total(numlist)
|
12
12
|
numlist.inject(0) { |sum, x| sum + x }
|
13
13
|
end
|
14
|
+
|
15
|
+
def occurences(keys, targets)
|
16
|
+
results = Hash.new(0)
|
17
|
+
targets.each do |target|
|
18
|
+
results[target] += 1 if keys.include? target
|
19
|
+
end
|
20
|
+
results
|
21
|
+
end
|
14
22
|
end
|
15
23
|
end
|
data/lib/jekyll_recker/site.rb
CHANGED
@@ -11,14 +11,60 @@ module JekyllRecker
|
|
11
11
|
@entries ||= build_entries
|
12
12
|
end
|
13
13
|
|
14
|
+
def latest
|
15
|
+
entries.first
|
16
|
+
end
|
17
|
+
|
18
|
+
|
14
19
|
def production?
|
15
20
|
ENV['JEKYLL_ENV'] == 'production'
|
16
21
|
end
|
17
22
|
|
23
|
+
def data
|
24
|
+
@site.data
|
25
|
+
end
|
26
|
+
|
27
|
+
def url
|
28
|
+
@site.config['url']
|
29
|
+
end
|
30
|
+
|
31
|
+
def word_counts
|
32
|
+
entries.collect(&:word_count)
|
33
|
+
end
|
34
|
+
|
35
|
+
def words
|
36
|
+
entries.collect(&:words).flatten
|
37
|
+
end
|
38
|
+
|
39
|
+
def dates
|
40
|
+
entries.collect(&:date)
|
41
|
+
end
|
42
|
+
|
43
|
+
def images
|
44
|
+
exts = ['.jpg', 'jpeg', '.png', '.svg']
|
45
|
+
@site.static_files.collect(&:path).select { |f| exts.include? File.extname(f) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def recker_config
|
49
|
+
@site.config.fetch('recker', {})
|
50
|
+
end
|
51
|
+
|
52
|
+
def config
|
53
|
+
@site.config
|
54
|
+
end
|
55
|
+
|
56
|
+
def graphs_dir
|
57
|
+
recker_config.fetch('graphs', 'assets/images/graphs/')
|
58
|
+
end
|
59
|
+
|
18
60
|
private
|
19
61
|
|
20
62
|
def build_entries
|
21
|
-
@site.posts.docs
|
63
|
+
@site.posts.docs
|
64
|
+
.select(&:published?)
|
65
|
+
.sort_by(&:date)
|
66
|
+
.reverse
|
67
|
+
.map { |p| Entry.new(p) }
|
22
68
|
end
|
23
69
|
end
|
24
70
|
end
|
data/lib/jekyll_recker/social.rb
CHANGED
@@ -19,17 +19,19 @@ module JekyllRecker
|
|
19
19
|
class Share
|
20
20
|
include Logging
|
21
21
|
|
22
|
+
attr_reader :site
|
23
|
+
|
22
24
|
def self.share(site, dry: false)
|
23
25
|
backend = new(site, dry: dry)
|
24
|
-
|
26
|
+
info "#{backend.name} - building configuration"
|
25
27
|
backend.configure!
|
26
28
|
|
27
|
-
|
29
|
+
info "#{backend.name} - sharing \"#{backend.latest_title}\""
|
28
30
|
backend.post!
|
29
31
|
end
|
30
32
|
|
31
33
|
def initialize(site, dry: false)
|
32
|
-
@site = site
|
34
|
+
@site = Site.new(site)
|
33
35
|
@dry = dry
|
34
36
|
end
|
35
37
|
|
@@ -38,29 +40,28 @@ module JekyllRecker
|
|
38
40
|
end
|
39
41
|
|
40
42
|
def config
|
41
|
-
|
43
|
+
site.recker_config.fetch(config_key, {})
|
42
44
|
end
|
43
45
|
|
44
46
|
def config_key
|
45
47
|
self.class.const_get(:KEY)
|
46
48
|
end
|
47
|
-
alias name :config_key
|
49
|
+
alias :name :config_key
|
48
50
|
|
49
51
|
def post_body
|
50
|
-
url = File.join @site.config['url'], latest.url
|
51
52
|
<<~BODY
|
52
|
-
#{latest.
|
53
|
-
#{latest.
|
54
|
-
#{url}
|
53
|
+
#{latest.title}
|
54
|
+
#{latest.subtitle}
|
55
|
+
#{File.join site.url, latest.url}
|
55
56
|
BODY
|
56
57
|
end
|
57
58
|
|
58
|
-
def
|
59
|
-
|
59
|
+
def latest_title
|
60
|
+
latest.title
|
60
61
|
end
|
61
62
|
|
62
|
-
def
|
63
|
-
latest
|
63
|
+
def latest
|
64
|
+
site.latest
|
64
65
|
end
|
65
66
|
|
66
67
|
def configure!
|
@@ -91,9 +92,9 @@ module JekyllRecker
|
|
91
92
|
def post!
|
92
93
|
message_body = ::Slack::Notifier::Util::LinkFormatter.format(post_body)
|
93
94
|
workspaces.each do |key, config|
|
94
|
-
|
95
|
+
info "posting to #{key} workspace"
|
95
96
|
if @dry
|
96
|
-
|
97
|
+
puts "BEGIN MESSAGE\n#{message_body.strip}\nEND MESSAGE"
|
97
98
|
else
|
98
99
|
::Slack::Notifier.new(
|
99
100
|
@creds[key].strip,
|
@@ -139,8 +140,8 @@ module JekyllRecker
|
|
139
140
|
|
140
141
|
def post!
|
141
142
|
if dry?
|
142
|
-
|
143
|
-
|
143
|
+
info('tweeting in dry mode, printing message')
|
144
|
+
puts "BEGIN TWEET\n#{post_body}END TWEET"
|
144
145
|
else
|
145
146
|
@client.update(post_body)
|
146
147
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-recker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Recker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -37,7 +37,6 @@ files:
|
|
37
37
|
- lib/jekyll_recker/entry.rb
|
38
38
|
- lib/jekyll_recker/filters.rb
|
39
39
|
- lib/jekyll_recker/generators.rb
|
40
|
-
- lib/jekyll_recker/generators/image_resize.rb
|
41
40
|
- lib/jekyll_recker/graphs.rb
|
42
41
|
- lib/jekyll_recker/logging.rb
|
43
42
|
- lib/jekyll_recker/math.rb
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module JekyllRecker
|
4
|
-
module Generators
|
5
|
-
# Image Resize Generator
|
6
|
-
class ImageResize < Jekyll::Generator
|
7
|
-
include Base
|
8
|
-
|
9
|
-
def generate(site)
|
10
|
-
@site = site
|
11
|
-
if production?
|
12
|
-
logger.info 'production detected, skipping images'
|
13
|
-
return
|
14
|
-
else
|
15
|
-
logger.info 'loading image resizing deps'
|
16
|
-
require 'fastimage'
|
17
|
-
require 'mini_magick'
|
18
|
-
end
|
19
|
-
logger.info 'checking images'
|
20
|
-
resizeable_images.each do |f, d|
|
21
|
-
logger.info "resizing #{f} to fit #{d}"
|
22
|
-
image = MiniMagick::Image.new(f)
|
23
|
-
image.resize d
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def image?(file)
|
28
|
-
['.jpg', 'jpeg', '.png', '.svg'].include? File.extname(file)
|
29
|
-
end
|
30
|
-
|
31
|
-
def too_big?(width, height)
|
32
|
-
width > 800 || height > 800
|
33
|
-
end
|
34
|
-
|
35
|
-
def graph?(file)
|
36
|
-
file.include?('/graphs/')
|
37
|
-
end
|
38
|
-
|
39
|
-
def images
|
40
|
-
@site.static_files.collect(&:path).select { |f| image?(f) }
|
41
|
-
end
|
42
|
-
|
43
|
-
def resizeable_images
|
44
|
-
without_graphs = images.reject { |i| graph?(i) }
|
45
|
-
with_sizes = without_graphs.map { |f| [f, FastImage.size(f)].flatten }
|
46
|
-
with_sizes.select! { |f| too_big?(f[1], f[2]) }
|
47
|
-
with_sizes.map do |f, w, h|
|
48
|
-
dimensions = if w > h
|
49
|
-
'800x600'
|
50
|
-
else
|
51
|
-
'600x800'
|
52
|
-
end
|
53
|
-
[f, dimensions]
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|