jekyll-shorts 0.0.9 → 0.0.10
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/Gemfile +1 -1
- data/README.md +8 -5
- data/features/cli.feature +1 -1
- data/jekyll-shorts.gemspec +1 -1
- data/lib/jekyll-shorts/generator.rb +8 -13
- data/lib/jekyll-shorts/letters.rb +44 -0
- data/lib/jekyll-shorts/version.rb +5 -1
- data/test/test_letters.rb +42 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20adc0bf33af94142a5e41d7a337b032373f6e1b9705ca4ac1e1628969b77c17
|
4
|
+
data.tar.gz: 9e8e2ce95972da6bb11f46d4348fbf6581c6de2d27929ef40a466b25a5182852
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e81e6ddeba6737fb4c2e4f0acd00ce00cb38f552c64c664e8fa52b96bbea720524e9f641f1a5d3e6d6c6b21f6d4aa360821c3aaebd423145d6651867a894b7be
|
7
|
+
data.tar.gz: 8b1a9f9a6b22dbae82dad7b4453f175f285b96e950bf295dcb47a31acda39b69d550c4169557ab4421862480892d578a996eb4ddf4650a568e4c931c779996fb
|
data/Gemfile
CHANGED
@@ -26,7 +26,7 @@ source 'https://rubygems.org'
|
|
26
26
|
gemspec
|
27
27
|
|
28
28
|
gem 'cucumber', '9.1.0', require: false
|
29
|
-
gem 'minitest', '5.22.
|
29
|
+
gem 'minitest', '5.22.2', require: false
|
30
30
|
gem 'rake', '13.1.0', require: false
|
31
31
|
gem 'rubocop', '1.60.2', require: false
|
32
32
|
gem 'rubocop-rspec', '2.26.1', require: false
|
data/README.md
CHANGED
@@ -19,7 +19,7 @@ plugins:
|
|
19
19
|
- ... your other plugins here ...
|
20
20
|
- jekyll-shorts
|
21
21
|
shorts:
|
22
|
-
permalink: :year:month:day.html
|
22
|
+
permalink: :year:month:day:letter.html
|
23
23
|
```
|
24
24
|
|
25
25
|
Here, every page in the site will get a sibling with the name
|
@@ -28,11 +28,14 @@ Here, every page in the site will get a sibling with the name
|
|
28
28
|
* `:year` - the short form of the year of the post, like `23` or `76`
|
29
29
|
* `:month` - the month of the post, like `01` or `12`
|
30
30
|
* `:day` - the day of the post, like `07` or `29`
|
31
|
-
* `:
|
32
|
-
* `:letter` - one English letter inside a month (empty instead of `a`)
|
31
|
+
* `:letter` - a unique English letter for a short URL, like `a`, `b`, etc.
|
33
32
|
|
34
|
-
|
35
|
-
|
33
|
+
If you don't use the `:letter`, you may end up with duplicated URLs. For example,
|
34
|
+
you have two pages written in 2023-11-23. Their URLs will be the same, if the
|
35
|
+
`permalink` is `:year:month:day.html`, as in the example above. With the help of the `:letter`,
|
36
|
+
two URLs become different.
|
37
|
+
|
38
|
+
Inside the Jekyll page, you can use `{{ page.short-url }}` for the value of the short URL.
|
36
39
|
|
37
40
|
## How to Contribute
|
38
41
|
|
data/features/cli.feature
CHANGED
data/jekyll-shorts.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
29
29
|
s.required_ruby_version = '>= 2.6'
|
30
30
|
s.name = 'jekyll-shorts'
|
31
|
-
s.version = '0.0.
|
31
|
+
s.version = '0.0.10'
|
32
32
|
s.license = 'MIT'
|
33
33
|
s.summary = 'Automatically generates short links for Jekyll website'
|
34
34
|
s.description = [
|
@@ -25,10 +25,9 @@
|
|
25
25
|
require 'jekyll'
|
26
26
|
require 'fileutils'
|
27
27
|
require 'json'
|
28
|
+
require 'securerandom'
|
28
29
|
require_relative 'version'
|
29
|
-
|
30
|
-
# The module we are in.
|
31
|
-
module JekyllShorts; end
|
30
|
+
require_relative 'letters'
|
32
31
|
|
33
32
|
# Pages generator.
|
34
33
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -40,30 +39,26 @@ class JekyllShorts::Generator < Jekyll::Generator
|
|
40
39
|
|
41
40
|
# Main plugin action, called by Jekyll-core
|
42
41
|
def generate(site)
|
43
|
-
Jekyll.logger.info("jekyll-shorts #{JekyllShorts::VERSION} starting...")
|
44
42
|
config ||= site.config['shorts'] || {}
|
45
|
-
permalink ||= config['permalink'] || ':year:month:day'
|
43
|
+
permalink ||= config['permalink'] || ':year:month:day:letter.html'
|
46
44
|
start = Time.now
|
47
45
|
total = 0
|
48
|
-
|
49
|
-
site.posts.docs.
|
46
|
+
letters = JekyllShorts::Letters.new
|
47
|
+
site.posts.docs.each do |doc|
|
50
48
|
long = doc.url
|
51
|
-
|
52
|
-
months[month] = 0 if months[month].nil?
|
53
|
-
raise 'Too many letters' if months[month] >= 26
|
49
|
+
re = SecureRandom.hex(64)
|
54
50
|
short = Jekyll::URL.new(
|
55
51
|
template: permalink,
|
56
52
|
placeholders: {
|
57
53
|
'year' => doc.date.year.to_s[2..],
|
58
54
|
'month' => doc.date.month.to_s.rjust(2, '0'),
|
59
55
|
'day' => doc.date.day.to_s.rjust(2, '0'),
|
60
|
-
'letter' =>
|
61
|
-
'position' => pos.to_s
|
56
|
+
'letter' => re
|
62
57
|
}
|
63
58
|
).to_s
|
59
|
+
short.sub!(re, letters.next(short.sub(re, '')))
|
64
60
|
site.static_files << ShortFile.new(site, short, long)
|
65
61
|
doc.data['short-url'] = short
|
66
|
-
months[month] += 1
|
67
62
|
total += 1
|
68
63
|
end
|
69
64
|
Jekyll.logger.info("jekyll-shorts #{JekyllShorts::VERSION}: \
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2024 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require_relative 'version'
|
26
|
+
|
27
|
+
# Letters
|
28
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
+
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
30
|
+
# License:: MIT
|
31
|
+
class JekyllShorts::Letters
|
32
|
+
def initialize
|
33
|
+
@mnemos = {}
|
34
|
+
end
|
35
|
+
|
36
|
+
# Next one for this mnemo.
|
37
|
+
def next(mnemo)
|
38
|
+
@mnemos[mnemo] = 0 if @mnemos[mnemo].nil?
|
39
|
+
raise 'Too many letters' if @mnemos[mnemo] >= 26
|
40
|
+
letter = @mnemos[mnemo].zero? ? '' : (@mnemos[mnemo] + 'a'.ord - 1).chr
|
41
|
+
@mnemos[mnemo] += 1
|
42
|
+
letter
|
43
|
+
end
|
44
|
+
end
|
@@ -22,6 +22,10 @@
|
|
22
22
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
23
|
# SOFTWARE.
|
24
24
|
|
25
|
+
# Our module.
|
26
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
27
|
+
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
28
|
+
# License:: MIT
|
25
29
|
module JekyllShorts
|
26
|
-
VERSION = '0.0.
|
30
|
+
VERSION = '0.0.10'
|
27
31
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2024 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'minitest/autorun'
|
26
|
+
require_relative 'test__helper'
|
27
|
+
require_relative '../lib/jekyll-shorts/letters'
|
28
|
+
|
29
|
+
# Letters test.
|
30
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
+
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
32
|
+
# License:: MIT
|
33
|
+
class JekyllShorts::LettersTest < Minitest::Test
|
34
|
+
def test_simple_scenario
|
35
|
+
letters = JekyllShorts::Letters.new
|
36
|
+
mnemo = 'hey'
|
37
|
+
assert_equal('', letters.next(mnemo))
|
38
|
+
assert_equal('a', letters.next(mnemo))
|
39
|
+
assert_equal('b', letters.next(mnemo))
|
40
|
+
assert_equal('', letters.next("#{mnemo}!"))
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-shorts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -53,10 +53,12 @@ files:
|
|
53
53
|
- jekyll-shorts.gemspec
|
54
54
|
- lib/jekyll-shorts.rb
|
55
55
|
- lib/jekyll-shorts/generator.rb
|
56
|
+
- lib/jekyll-shorts/letters.rb
|
56
57
|
- lib/jekyll-shorts/version.rb
|
57
58
|
- renovate.json
|
58
59
|
- test/test__helper.rb
|
59
60
|
- test/test_generator.rb
|
61
|
+
- test/test_letters.rb
|
60
62
|
homepage: https://github.com/yegor256/jekyll-shorts
|
61
63
|
licenses:
|
62
64
|
- MIT
|