jekyll-chatgpt-translate 0.0.11 → 0.0.13

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: c02caba7176953aa1d0df4bbe92e40dcf7f1046b22f9f2af8dcd434179d36a00
4
- data.tar.gz: 6d510fbdc601a7f7174194b39a17402e8e3aff08ff40190e8799d897eaf1aded
3
+ metadata.gz: 864696015c8e2b7ee1abba3e5bd8aee3310d7d9d3d85721b5a082b45eef6cd0b
4
+ data.tar.gz: cfc8b8d09865af57aea8202be714c0ee7211da0fc2121873b8004f37cf40a507
5
5
  SHA512:
6
- metadata.gz: a4224dd0584ed1d6ed56e876e4678de0dcba0a2338dba08bfa61a3147365ddec617116ed92f4616799b182c127f5d4509ab114e02659ca87dad1cd1e6fe9825c
7
- data.tar.gz: ac6ed731ca359ccc2021be00c232c60271a212c0f68dd5ca4e0212ef7ebf6bb26c2a94decae2422fc17c80e5c880e52aea407d175b22a19ae0dd544da4d485e6
6
+ metadata.gz: 83cbb3ae370b246351ce64302e48b0d5c4b94fcc985fb7c239f36f7c2767e5779fa45998ae6b808b8c8e973369ee6d6f21c9a62b241cb5459fb235eb9a424d01
7
+ data.tar.gz: 9400ee361c82cf27582e416a607d292f16850269fa204a837ff40f052917692dbb0a8d9f3aade9d21d0c2d74870028d6c8c4aec50b4b0efd177f6efc6a220e5c
data/README.md CHANGED
@@ -68,6 +68,9 @@ This layout will be specified for the pages generated by this plugin.
68
68
  * `layout` (optional) — the name of the file in the `_layouts` directory
69
69
 
70
70
  * `threshold` (optional) — maximum number of pages to generate in one build cycle.
71
+ The default value is 1024. It is recommended to use smaller number, in order
72
+ to avoid too long builds. You can re-run the build again and missing pages
73
+ will be generated. Thus, in a few builds the entire site will be translated.
71
74
 
72
75
  * `version` (optional) — the version that will be attached to each generated page,
73
76
  in order to avoid repetitive translations on one hand and enable re-translations
@@ -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.11'
31
+ s.version = '0.0.13'
32
32
  s.license = 'MIT'
33
33
  s.summary = 'Translate Jekyll Pages Through ChatGPT'
34
34
  s.description = [
@@ -51,17 +51,18 @@ class GptTranslate::Generator < Jekyll::Generator
51
51
  end
52
52
  layout = config['layout'] || 'translated'
53
53
  version = config['version'] || GptTranslate::VERSION
54
- threshold = config['threshold'] || 1_000_000_000
54
+ threshold = config['threshold'] || 1024
55
55
  start = Time.now
56
56
  total = 0
57
- site.posts.docs.each do |doc|
57
+ model = config['model'] || 'gpt-3.5-turbo'
58
+ marker = "Translated by ChatGPT #{model}/#{version}"
59
+ site.posts.docs.shuffle.each do |doc|
58
60
  plain = GptTranslate::Plain.new(doc.content).to_s
59
61
  config['targets'].each do |target|
60
62
  link = GptTranslate::Permalink.new(doc, target['permalink']).to_path
61
- next if GptTranslate::Ping.new(site, link).found?(doc.path)
63
+ next if GptTranslate::Ping.new(site, link).found?(doc.path, version)
62
64
  lang = target['language']
63
65
  raise 'Language must be defined for each target' if target.nil?
64
- model = config['model'] || 'gpt-3.5-turbo'
65
66
  if total >= threshold
66
67
  Jekyll.logger.info("Already generated #{total} pages, that's enough for today")
67
68
  break
@@ -88,7 +89,7 @@ class GptTranslate::Generator < Jekyll::Generator
88
89
  '',
89
90
  translated,
90
91
  '',
91
- "Translated by ChatGPT #{model}/#{version}\n{: .jekyll-chatgpt-translate}"
92
+ "#{marker}\n{: .jekyll-chatgpt-translate}"
92
93
  ].join("\n")
93
94
  )
94
95
  doc.data["translated-#{lang}-url"] = link
@@ -25,6 +25,7 @@
25
25
  require 'iri'
26
26
  require 'net/http'
27
27
  require 'uri'
28
+ require 'fileutils'
28
29
  require_relative 'version'
29
30
 
30
31
  # see https://stackoverflow.com/a/6048451/187141
@@ -46,25 +47,29 @@ class GptTranslate::Ping
46
47
  @path = path
47
48
  end
48
49
 
49
- def found?(file)
50
+ def found?(file, marker)
50
51
  home = @site.config['url']
51
52
  return false if home.nil?
52
53
  uri = Iri.new(home).path(@path)
53
- before = Net::HTTP.get_response(URI(uri.to_s))
54
- if before.is_a?(Net::HTTPSuccess)
55
- html = before.body
56
- if html.include?("/#{GptTranslate::VERSION}")
57
- Jekyll.logger.info("No need to translate, the page exists at \
58
- #{uri} (#{html.split.count} words), saved to #{file}")
59
- File.mkdir_p(File.dirname(file))
60
- File.write(file, html)
61
- return true
54
+ begin
55
+ before = Net::HTTP.get_response(URI(uri.to_s))
56
+ if before.is_a?(Net::HTTPSuccess)
57
+ html = before.body
58
+ if html.include?(marker)
59
+ Jekyll.logger.info("No need to translate, the page exists at \
60
+ #{uri} (#{html.split.count} words), saved to #{file}")
61
+ FileUtils.mkdir_p(File.dirname(file))
62
+ File.write(file, html)
63
+ return true
64
+ end
65
+ Jekyll.logger.info("Re-translation required for \"#{uri}\"")
66
+ else
67
+ Jekyll.logger.info("The page is absent, will translate \"#{uri}\"")
62
68
  end
63
- Jekyll.logger.info("Re-translation required for #{uri}")
64
- else
65
- Jekyll.logger.info("The page is absent, will translate: #{uri}")
69
+ Jekyll.logger.debug("GET \"#{uri}\": #{before.code}")
70
+ rescue StandardError => e
71
+ Jekyll.logger.info("Failed to ping \"#{uri}\": #{e.message}")
66
72
  end
67
- Jekyll.logger.debug("GET #{uri}: #{before.code}")
68
73
  false
69
74
  end
70
75
  end
@@ -23,5 +23,5 @@
23
23
  # SOFTWARE.
24
24
 
25
25
  module GptTranslate
26
- VERSION = '0.0.11'
26
+ VERSION = '0.0.13'
27
27
  end
data/test/test_ping.rb CHANGED
@@ -46,7 +46,7 @@ class GptTranslate::PingTest < Minitest::Test
46
46
  site = FakeSite.new({ 'url' => 'https://www.yegor256.com/' })
47
47
  ping = GptTranslate::Ping.new(site, '/about-me.html')
48
48
  Tempfile.open do |f|
49
- assert(!ping.found?(f))
49
+ assert(ping.found?(f, ''))
50
50
  end
51
51
  end
52
52
 
@@ -55,7 +55,16 @@ class GptTranslate::PingTest < Minitest::Test
55
55
  site = FakeSite.new({ 'url' => 'https://www.yegor256.com/' })
56
56
  ping = GptTranslate::Ping.new(site, '/absent.html')
57
57
  Tempfile.open do |f|
58
- assert(!ping.found?(f))
58
+ assert(!ping.found?(f, ''))
59
+ end
60
+ end
61
+
62
+ def test_wrong_address
63
+ WebMock.allow_net_connect!
64
+ site = FakeSite.new({ 'url' => 'https://localhost:1/' })
65
+ ping = GptTranslate::Ping.new(site, '/boom.html')
66
+ Tempfile.open do |f|
67
+ assert(!ping.found?(f, ''))
59
68
  end
60
69
  end
61
70
 
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.11
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko