jekyll-shorts 0.0.1 → 0.0.3

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: b3d8759f41c495c08a1001975d9a43dcf139f03355b21a9e9d79f698e7ab1877
4
- data.tar.gz: 6fb9f3a3ec31d2c485d03d8def545b2b73c0008b18a121033add28cbbe7a4f20
3
+ metadata.gz: ac906426e58ece9954aaad571009ae1ba16f00bcbf3727dcbcc9577a90750daa
4
+ data.tar.gz: 3af8f4e79b61334e857338bb6005557ae73c66b354640851d6166cd5fd7087bf
5
5
  SHA512:
6
- metadata.gz: 33b528a89955c8c9a4b4dae4f5daa07fd926881128dd697805036dbaa0273f20630e8f672d7d13c143ee089c4b1e34cfa6165d1437465230a04dac137ca7fc4f
7
- data.tar.gz: 9e30d54dbc5fbe3d5314bcf60af37e04516acd9b5a491eec163b070e6f438f0044d5b8b05a17edaf3229512db292ae0e98b1d12a53c7f090471ba2f7e44238a9
6
+ metadata.gz: 4dc03afd1f1d490fc670068fcd6dd3abc10cf350bea8b223f919732f514af098f16b0fe5a1017455b25752ded2cf8c17dc03ccca94e0e9c3311471e0b1d1519d
7
+ data.tar.gz: 518a229f1c3f4cbb698c730e53a0b9308f2c518e54ba8e46d9328dfe04fabf8f607e4f992bf94da9ab6e98055562ead84161d5dfc1553ac401490fcd67cfca6b
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.21.1', require: false
29
+ gem 'minitest', '5.22.1', require: false
30
30
  gem 'rake', '13.1.0', require: false
31
31
  gem 'rubocop', '1.59.0', require: false
32
32
  gem 'rubocop-rspec', '2.26.1', require: false
data/README.md CHANGED
@@ -25,10 +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
- * `:year` - the year of the post
29
- * `:month` - the year of the post
30
- * `:day` - the year of the post
31
- * `:position` - the unique position of the post in the entire list of them
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`
32
33
 
33
34
  Be careful with the `:position`, since it may change when you add a new post
34
35
  somewhere in the middle of existing flow of posts.
data/features/cli.feature CHANGED
@@ -8,13 +8,13 @@ Feature: Simple site building
8
8
  plugins:
9
9
  - jekyll-shorts
10
10
  shorts:
11
- permalink: :day.html
11
+ permalink: :y:m:d.html
12
12
  """
13
13
  And I have a "_layouts/default.html" file with content:
14
14
  """
15
15
  {{ content }}
16
16
  """
17
- And I have a "_posts/2023-01-01-hello.md" file with content:
17
+ And I have a "_posts/2023-07-29-hello.md" file with content:
18
18
  """
19
19
  ---
20
20
  title: Hello, world!
@@ -24,4 +24,4 @@ Feature: Simple site building
24
24
  """
25
25
  Then I build Jekyll site
26
26
  And Exit code is zero
27
- And File "_site/01.html" exists
27
+ And File "_site/230729.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.1'
31
+ s.version = '0.0.3'
32
32
  s.license = 'MIT'
33
33
  s.summary = 'Automatically generates short links for Jekyll website'
34
34
  s.description = [
@@ -50,10 +50,11 @@ class JekyllShorts::Generator < Jekyll::Generator
50
50
  short = Jekyll::URL.new(
51
51
  template: permalink,
52
52
  placeholders: {
53
- 'year' => doc.date.year.to_s,
54
- 'month' => doc.date.month.to_s.rjust(2, '0'),
55
- 'day' => doc.date.day.to_s.rjust(2, '0'),
56
- 'position' => pos.to_s
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
57
58
  }
58
59
  ).to_s
59
60
  site.static_files << ShortFile.new(site, short, long)
@@ -73,9 +74,22 @@ class JekyllShorts::Generator < Jekyll::Generator
73
74
 
74
75
  def write(_dest)
75
76
  FileUtils.mkdir_p(File.dirname(path))
76
- html = "<html> redirect to #{@long}</html>"
77
- File.write(path, html)
78
- Jekyll.logger.info("HTML #{path.inspect} -> #{@long.inspect}")
77
+ html = "<html><head><meta charset='utf-8'/>\
78
+ <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>\
79
+ <meta http-equiv='refresh' content='#{@long}'/></head></html>"
80
+ if File.exist?(path)
81
+ before = File.read(path)
82
+ if before != after
83
+ raise "It's impossible to generate a short link at #{path.inspect}, \
84
+ 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 \
86
+ probably means that previously generated short link will point to a different location \
87
+ than before. Try to run 'jekyll clean', it will help, if you know what you are doing."
88
+ end
89
+ else
90
+ File.write(path, html)
91
+ Jekyll.logger.debug("HTML #{path.inspect} -> #{@long.inspect}")
92
+ end
79
93
  true
80
94
  end
81
95
  end
@@ -23,5 +23,5 @@
23
23
  # SOFTWARE.
24
24
 
25
25
  module JekyllShorts
26
- VERSION = '0.0.1'
26
+ VERSION = '0.0.3'
27
27
  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.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko