jekyll-chatgpt-translate 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e80c34ee1b28dc84b884ad53ef3f68d1b5bb9d0ba9620e1c50e7fe97abe6785
4
- data.tar.gz: d47885e2ac998c1d57004c784baba4ecb3988ec39d697771a0082a76a46097a2
3
+ metadata.gz: 3b2375ac0c0ab9bc728d9e1d6684b4cb1f1424ae5718095a8644a447b91487e8
4
+ data.tar.gz: bf13ed8a50dad4ca6f4cdd1d719728a57e0c7081a16eda4d56bb6dbbcae5bb3d
5
5
  SHA512:
6
- metadata.gz: 5cc86659f819d55cab262ce1658a70e25b1ba361ec46a03d43063e644bb2ba01d9e0e986a29fd1c85ca0867e87e00bd7dfb5852c448ec29ba9bd72f1c6d998a9
7
- data.tar.gz: b1735adc1ac05a53bb65a9e49467bd4aa79299ab9a0c9de1e68d199ce8852820ff8d9f260f8f9d5f7137432fbd27d69b69d18f3cbbaa3d5730e7439253764523
6
+ metadata.gz: 26dbc8403f36f4bfb8c127efac666dd8884823be38b9fda7a7c92800c50f6805cfe7aa8b04251830412025ae3582a799331fdff0e8336507a6c2004fbbbbf49c
7
+ data.tar.gz: 5f5cd81fd192d7945f57b23148df57ebd95f09ff8b917190ffd89cb2a8dc4d44f49afffc78d7032c0194a6a0e0aa25ce95b80d97a210cfd1cbfe9965e0a44f6c
@@ -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-chatgpt-translate'
31
- s.version = '0.0.5'
31
+ s.version = '0.0.6'
32
32
  s.license = 'MIT'
33
33
  s.summary = 'Translate Jekyll Pages Through ChatGPT'
34
34
  s.description = [
@@ -24,6 +24,7 @@
24
24
 
25
25
  require 'jekyll'
26
26
  require_relative 'chatgpt'
27
+ require_relative 'permalink'
27
28
  require_relative 'ping'
28
29
  require_relative 'plain'
29
30
  require_relative 'version'
@@ -60,7 +61,7 @@ but pages will be generated')
60
61
  site.posts.docs.each do |doc|
61
62
  plain = GptTranslate::Plain.new(doc.content).to_s
62
63
  config['targets'].each do |target|
63
- link = permalink(doc, target['permalink'])
64
+ link = GptTranslate::Permalink.new(doc, target['permalink']).to_s
64
65
  next if GptTranslate::Ping.new(site, link).exists?
65
66
  lang = target['language']
66
67
  raise 'Language must be defined for each target' if target.nil?
@@ -106,13 +107,4 @@ but pages will be generated')
106
107
  def config
107
108
  @config ||= @site.config['chatgpt-translate'] || {}
108
109
  end
109
-
110
- def permalink(doc, template)
111
- raise 'permalink must be defined for each target' if template.nil?
112
- template
113
- .gsub(':year', format('%04d', doc['date'].year))
114
- .gsub(':month', format('%02d', doc['date'].month))
115
- .gsub(':day', format('%02d', doc['date'].day))
116
- .gsub(':title', doc['title'])
117
- end
118
110
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ # (The MIT License)
4
+ #
5
+ # Copyright (c) 2023 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 'cgi'
26
+
27
+ # The module we are in.
28
+ module GptTranslate; end
29
+
30
+ # Permalink.
31
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
32
+ # Copyright:: Copyright (c) 2023 Yegor Bugayenko
33
+ # License:: MIT
34
+ class GptTranslate::Permalink
35
+ def initialize(doc, template)
36
+ @doc = doc
37
+ raise 'permalink must be defined for each target' if template.nil?
38
+ @template = template
39
+ end
40
+
41
+ def to_s
42
+ @template
43
+ .gsub(':year', format('%04d', @doc['date'].year))
44
+ .gsub(':month', format('%02d', @doc['date'].month))
45
+ .gsub(':day', format('%02d', @doc['date'].day))
46
+ .gsub(':title', CGI.escape(@doc['title']))
47
+ end
48
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # (The MIT License)
4
+ #
5
+ # Copyright (c) 2023 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 '../lib/jekyll-chatgpt-translate/permalink'
27
+
28
+ # Permalink test.
29
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
+ # Copyright:: Copyright (c) 2023 Yegor Bugayenko
31
+ # License:: MIT
32
+ class GptTranslate::PermalinkTest < Minitest::Test
33
+ def test_simple_link
34
+ assert_equal(
35
+ '/2023.html',
36
+ GptTranslate::Permalink.new(
37
+ { 'date' => Time.parse('2023-01-01'), 'title' => 'Hello' },
38
+ '/:year.html'
39
+ ).to_s
40
+ )
41
+ end
42
+
43
+ def test_unicode_link
44
+ assert_equal(
45
+ '/2023-%23%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82.html',
46
+ GptTranslate::Permalink.new(
47
+ { 'date' => Time.parse('2023-01-01'), 'title' => '#привет' },
48
+ '/:year-:title.html'
49
+ ).to_s
50
+ )
51
+ end
52
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-chatgpt-translate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -121,6 +121,7 @@ files:
121
121
  - lib/jekyll-chatgpt-translate.rb
122
122
  - lib/jekyll-chatgpt-translate/chatgpt.rb
123
123
  - lib/jekyll-chatgpt-translate/generator.rb
124
+ - lib/jekyll-chatgpt-translate/permalink.rb
124
125
  - lib/jekyll-chatgpt-translate/ping.rb
125
126
  - lib/jekyll-chatgpt-translate/plain.rb
126
127
  - lib/jekyll-chatgpt-translate/version.rb
@@ -128,6 +129,7 @@ files:
128
129
  - test/test__helper.rb
129
130
  - test/test_chatgpt.rb
130
131
  - test/test_generator.rb
132
+ - test/test_permalink.rb
131
133
  - test/test_ping.rb
132
134
  - test/test_plain.rb
133
135
  homepage: https://github.com/yegor256/jekyll-chatgpt-translate