jekyll-shorts 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6953f28017721d99160900b5a80a863ad67169fc9340082a05c93e4ea444f5c9
4
- data.tar.gz: f7e0bc60d2d07704eadc19900bc9ae086c7e870021202f01222796f5258fbad0
3
+ metadata.gz: b0865d5612007eb2f21897da52685a97e6555f305a34546f43541a7710349028
4
+ data.tar.gz: e0555698b8f494dbd5f8f77bb1d6974aebac77ef91deef65db05ecf53877ea71
5
5
  SHA512:
6
- metadata.gz: 7489a031c6a40d7697485957914044110b93e21820ad84f59998a3f81edd785858c307e4e30161ab54329a2b65dae3d29b8131eee76ba29aeff397f7dba9a236
7
- data.tar.gz: 3b41b144ac540a9ca2930e6b4cb1242c7511c4835b1a0e1714a94db1f940e60e02b9a6134f7f01a6679d71396bebd9b02ddfcf03e70d343df4ed2371eb72b0c8
6
+ metadata.gz: 99e93ff62eb54a5b88d7ce55dc94f662db5ea3956bd8fdf2d18990e4bb87f498e4a3ef991ab585a5aa08f55c89856d707013f0b2f24489ab5937250788db9116
7
+ data.tar.gz: ee1717e2a2b55080afd0b6ffba8740bcb5d29aa12e4b5a731b57c59424f6fe356b611d980ba8b6c0de3e9d708d7cda15fd7076de152867a3eecb9fa152d0994a
data/README.md CHANGED
@@ -25,11 +25,11 @@ shorts:
25
25
  Here, every page in the site will get a sibling with the name
26
26
  `:year:month:day.html`, which will redirect to the page itself. You can use:
27
27
 
28
- * `:Y` - the full year of the post, like `2022` or `1976`
29
- * `:y` - the short form of the year of the post, like `23` or `76`
30
- * `:m` - the month of the post, like `01` or `12`
31
- * `:d` - the day of the post, like `07` or `29`
32
- * `:pos` - the unique position of the post in the entire list of them, like `42` or `256`
28
+ * `:year` - the short form of the year of the post, like `23` or `76`
29
+ * `:month` - the month of the post, like `01` or `12`
30
+ * `:day` - the day of the post, like `07` or `29`
31
+ * `:position` - the unique position of the post in the entire list of them, like `42` or `256`
32
+ * `:letter` - one English letter inside a month
33
33
 
34
34
  Be careful with the `:position`, since it may change when you add a new post
35
35
  somewhere in the middle of existing flow of posts.
data/features/cli.feature CHANGED
@@ -8,7 +8,7 @@ Feature: Simple site building
8
8
  plugins:
9
9
  - jekyll-shorts
10
10
  shorts:
11
- permalink: :y:m:d.html
11
+ permalink: :year:month:day.html
12
12
  """
13
13
  And I have a "_layouts/default.html" file with content:
14
14
  """
@@ -25,3 +25,76 @@ Feature: Simple site building
25
25
  Then I build Jekyll site
26
26
  And Exit code is zero
27
27
  And File "_site/230729.html" exists
28
+ And I build Jekyll site
29
+ And Exit code is zero
30
+
31
+ Scenario: Simple site
32
+ Given I have a "_config.yml" file with content:
33
+ """
34
+ markdown: kramdown
35
+ plugins:
36
+ - jekyll-shorts
37
+ shorts:
38
+ permalink: :year.html
39
+ """
40
+ And I have a "_layouts/default.html" file with content:
41
+ """
42
+ {{ content }}
43
+ """
44
+ And I have a "_posts/2023-01-01-hello.md" file with content:
45
+ """
46
+ ---
47
+ title: Hello, world!
48
+ layout: default
49
+ ---
50
+ Hello, world!
51
+ """
52
+ Then I build Jekyll site
53
+ And Exit code is zero
54
+ And File "_site/23.html" exists
55
+ And I have a "_posts/2023-02-02-hello.md" file with content:
56
+ """
57
+ ---
58
+ title: Hello, world!
59
+ layout: default
60
+ ---
61
+ Hello, world!
62
+ """
63
+ And I build Jekyll site
64
+ And Exit code is not zero
65
+
66
+ Scenario: Simple site
67
+ Given I have a "_config.yml" file with content:
68
+ """
69
+ markdown: kramdown
70
+ plugins:
71
+ - jekyll-shorts
72
+ shorts:
73
+ permalink: :year:month:letter.html
74
+ """
75
+ And I have a "_layouts/default.html" file with content:
76
+ """
77
+ {{ content }}
78
+ """
79
+ And I have a "_posts/2023-01-01-apple.md" file with content:
80
+ """
81
+ ---
82
+ title: Hello, world!
83
+ layout: default
84
+ ---
85
+ Hello, world!
86
+ """
87
+ Then I build Jekyll site
88
+ And Exit code is zero
89
+ And I have a "_posts/2023-01-02-apple.md" file with content:
90
+ """
91
+ ---
92
+ title: Hello, world!
93
+ layout: default
94
+ ---
95
+ Hello, world!
96
+ """
97
+ And I build Jekyll site
98
+ And Exit code is zero
99
+ And File "_site/2301a.html" exists
100
+ And File "_site/2301b.html" exists
@@ -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.4'
31
+ s.version = '0.0.6'
32
32
  s.license = 'MIT'
33
33
  s.summary = 'Automatically generates short links for Jekyll website'
34
34
  s.description = [
@@ -45,20 +45,24 @@ class JekyllShorts::Generator < Jekyll::Generator
45
45
  permalink ||= config['permalink'] || ':year:month:day'
46
46
  start = Time.now
47
47
  total = 0
48
+ months = {}
48
49
  site.posts.docs.sort_by(&:url).each_with_index do |doc, pos|
49
50
  long = doc.url
51
+ month = doc.date.strftime('%Y%m')
52
+ months[month] = 0 if months[month].nil?
50
53
  short = Jekyll::URL.new(
51
54
  template: permalink,
52
55
  placeholders: {
53
- 'Y' => doc.date.year.to_s,
54
- 'y' => doc.date.year.to_s[2..],
55
- 'm' => doc.date.month.to_s.rjust(2, '0'),
56
- 'd' => doc.date.day.to_s.rjust(2, '0'),
57
- 'pos' => pos.to_s
56
+ 'year' => doc.date.year.to_s[2..],
57
+ 'month' => doc.date.month.to_s.rjust(2, '0'),
58
+ 'day' => doc.date.day.to_s.rjust(2, '0'),
59
+ 'letter' => (months[month] + 'a'.ord).chr,
60
+ 'position' => pos.to_s
58
61
  }
59
62
  ).to_s
60
63
  site.static_files << ShortFile.new(site, short, long)
61
64
  doc.data['short-url'] = short
65
+ months[month] += 1
62
66
  total += 1
63
67
  end
64
68
  Jekyll.logger.info("jekyll-shorts #{JekyllShorts::VERSION}: \
@@ -82,7 +86,7 @@ class JekyllShorts::Generator < Jekyll::Generator
82
86
  if before != html
83
87
  raise "It's impossible to generate a short link at #{path.inspect}, \
84
88
  because the file already exists and the content \
85
- of the it differs from what we are going to write into it now (#{long}). This most \
89
+ of the it differs from what we are going to write into it now (#{@long}). This most \
86
90
  probably means that previously generated short link will point to a different location \
87
91
  than before. Try to run 'jekyll clean', it will help, if you know what you are doing."
88
92
  end
@@ -23,5 +23,5 @@
23
23
  # SOFTWARE.
24
24
 
25
25
  module JekyllShorts
26
- VERSION = '0.0.4'
26
+ VERSION = '0.0.6'
27
27
  end
@@ -49,4 +49,24 @@ class JekyllShorts::GeneratorTest < Minitest::Test
49
49
  gen.generate(site)
50
50
  end
51
51
  end
52
+
53
+ def test_two_similar_posts
54
+ Dir.mktmpdir do |home|
55
+ first = File.join(home, '2023-01-01-first.md')
56
+ File.write(first, "---\ntitle: Hello\n---\n\nHello, world!")
57
+ second = File.join(home, '2023-01-01-second.md')
58
+ File.write(second, "---\ntitle: Hello\n---\n\nHello, world!")
59
+ site = JekyllShorts::FakeSite.new(
60
+ {
61
+ 'url' => 'https://www.yegor256.com/',
62
+ 'shorts' => {
63
+ 'permalink' => ':y:m:letter.html'
64
+ }
65
+ },
66
+ [first, second]
67
+ )
68
+ gen = JekyllShorts::Generator.new
69
+ gen.generate(site)
70
+ end
71
+ end
52
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-shorts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko