jekyll-time-to-read 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/jekyll-time-to-read.rb +51 -0
  3. metadata +86 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d06eda2796d75024ea39be2abd06e4f39b08d4e4
4
+ data.tar.gz: e08be79ccb3864203a07eadd2ba3085ca4928b67
5
+ SHA512:
6
+ metadata.gz: a64f97150e9e1d68cbfa4ed87c83afb7619947a89f39b25c2aef4830e96494c15d19a0509f6db3638152534be7a8b2570b0427f4f7a5ab9c5e17351cdadff126
7
+ data.tar.gz: 4fbc0a1efb7c552727031604fe8ea7c03f93ffaf4eed02ac22a03fa21db48e5ac0f2c46d58b3d4040eb2c7536ad785fb4c9b3e994f6e3aff70f35d57c656b516
@@ -0,0 +1,51 @@
1
+ # Outputs the reading time, as a number
2
+
3
+ # Read this in "about 4 minutes"
4
+ # Put into your _plugins dir in your Jekyll site
5
+ # Usage: Read this in {{ page.content | reading_time_as_i }}
6
+
7
+ WORD_PER_MINUTE = 180
8
+
9
+ def calculate_time( input )
10
+ words = input.split.size;
11
+ minutes = ( words / WORD_PER_MINUTE ).floor
12
+ minutes_label = minutes == 1 ? "minute" : "minutes"
13
+ return minutes, minutes_label
14
+ end
15
+
16
+ module ReadingTimeFilterAsInteger
17
+ def reading_time_as_i( input )
18
+ minutes, minutes_label = calculate_time(input)
19
+ minutes > 0 ? "#{minutes} #{minutes_label}" : "less than 1 minute"
20
+ end
21
+
22
+ Liquid::Template.register_filter(ReadingTimeFilterAsInteger)
23
+ end
24
+
25
+ # Outputs the reading time, as a string
26
+
27
+ # Read this in "about four minutes"
28
+ # Put into your _plugins dir in your Jekyll site
29
+ # Usage: Read this in {{ page.content | reading_time_as_s }}
30
+
31
+ module ReadingTimeFilterAsString
32
+ def reading_time_as_s( input )
33
+ minutes, minutes_label = calculate_time(input)
34
+
35
+ case minutes
36
+ when 1 then minutes_s = 'one'
37
+ when 2 then minutes_s = 'two'
38
+ when 3 then minutes_s = 'three'
39
+ when 4 then minutes_s = 'four'
40
+ when 5 then minutes_s = 'five'
41
+ when 6 then minutes_s = 'six'
42
+ when 7 then minutes_s = 'seven'
43
+ when 8 then minutes_s = 'eight'
44
+ when 9 then minutes_s = 'nine'
45
+ end
46
+
47
+ minutes > 0 ? "#{minutes_s} #{minutes_label}" : "less than one minute"
48
+ end
49
+
50
+ Liquid::Template.register_filter(ReadingTimeFilterAsString)
51
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-time-to-read
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Garen J. Torikian
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-19 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.13.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.13.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - lib/jekyll-time-to-read.rb
62
+ homepage: https://github.com/gjtorikian/jekyll-time-to-read
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.0.3
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: A liquid tag for Jekyll to indicate the time it takes to read an article.
86
+ test_files: []