jekyll-chatgpt-translate 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad6aab5a14ab43febd8be49411b3cd30c89213140b5bc11d5ef0f2dd86c8de3f
4
- data.tar.gz: 396b48cfade277af37a5698049e1e8ed09c37b2777b4a009ac5561543a340708
3
+ metadata.gz: 38924a750a0276a65b25263ec22b74f92a2ccd652636a65ec0cf90a46bb45983
4
+ data.tar.gz: '058007955befb70a3323a3c68863b09621e63d52da65424383644c7751b47861'
5
5
  SHA512:
6
- metadata.gz: 4b6917658e850826539295bc02266bab962c411812ada39f78e219837587b5a481de3b55a9471926b674d4d14b377680d8957c7d7564e8cdbff2d983bdd3f85f
7
- data.tar.gz: aa290814eb9f36d3feafed043bb24b38d308b33f70cd732fa9136ddb50972142c06b6132542535e006c36735f02d698bb1f501381305a3a6c68d1d65a2a8218b
6
+ metadata.gz: 33e22f1a3f0055308860c966a3ea824bd336f2ef122902bc10e533692649bb55c13d422e8b0bcde148064646745865e403830458c61767ce072ba7cd4329f07f
7
+ data.tar.gz: 546dfbd3042bbf630ec7647096a879fc82d32368714057189b543abb6154ac6dca0fcf504220259ad9ca27182f52e4c432fcb7eeffbb535a93513004109f6c2e
@@ -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.9'
31
+ s.version = '0.0.10'
32
32
  s.license = 'MIT'
33
33
  s.summary = 'Translate Jekyll Pages Through ChatGPT'
34
34
  s.description = [
@@ -57,7 +57,7 @@ class GptTranslate::Generator < Jekyll::Generator
57
57
  plain = GptTranslate::Plain.new(doc.content).to_s
58
58
  config['targets'].each do |target|
59
59
  link = GptTranslate::Permalink.new(doc, target['permalink']).to_path
60
- next if GptTranslate::Ping.new(site, link).exists?
60
+ next if GptTranslate::Ping.new(site, link).found?(doc.path)
61
61
  lang = target['language']
62
62
  raise 'Language must be defined for each target' if target.nil?
63
63
  model = config['model'] || 'gpt-3.5-turbo'
@@ -106,9 +106,14 @@ class GptTranslate::Generator < Jekyll::Generator
106
106
  def api_key(config)
107
107
  file = config['api_key_file']
108
108
  key = if file.nil?
109
- ENV.fetch('OPENAI_API_KEY', nil)
109
+ k = ENV.fetch('OPENAI_API_KEY', nil)
110
+ Jekyll.logger.info('The key is found in the OPENAI_API_KEY env variable') unless k.nil?
111
+ k
110
112
  elsif File.exist?(file)
113
+ Jekyll.logger.info("Reading OpenAI key from the file: #{file}")
111
114
  File.read(file).strip
115
+ else
116
+ Jekyll.logger.info("The file is not found: #{file}")
112
117
  end
113
118
  if key.nil? && Jekyll.env == 'development'
114
119
  Jekyll.logger.info("OPENAI_API_KEY environment variable is not set, \
@@ -46,14 +46,23 @@ class GptTranslate::Ping
46
46
  @path = path
47
47
  end
48
48
 
49
- def exists?
49
+ def found?(file)
50
50
  home = @site.config['url']
51
51
  return false if home.nil?
52
52
  uri = Iri.new(home).path(@path)
53
53
  before = Net::HTTP.get_response(URI(uri.to_s))
54
- if before.is_a?(Net::HTTPSuccess) && before.body.include?("/#{GptTranslate::VERSION}")
55
- Jekyll.logger.info("No need to translate, page exists at #{uri} (#{before.body.split.count} words)")
56
- return true
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
62
+ end
63
+ Jekyll.logger.info("Re-translation required for #{uri}")
64
+ else
65
+ Jekyll.logger.info("The page is absent, will translate: #{uri}")
57
66
  end
58
67
  Jekyll.logger.debug("GET #{uri}: #{before.code}")
59
68
  false
data/test/test_ping.rb CHANGED
@@ -25,6 +25,7 @@
25
25
  require 'minitest/autorun'
26
26
  require 'webmock/minitest'
27
27
  require 'jekyll'
28
+ require 'tempfile'
28
29
  require_relative '../lib/jekyll-chatgpt-translate/ping'
29
30
 
30
31
  # Ping test.
@@ -44,14 +45,18 @@ class GptTranslate::PingTest < Minitest::Test
44
45
  stub_request(:any, 'https://www.yegor256.com/about-me.html')
45
46
  site = FakeSite.new({ 'url' => 'https://www.yegor256.com/' })
46
47
  ping = GptTranslate::Ping.new(site, '/about-me.html')
47
- assert(!ping.exists?)
48
+ Tempfile.open do |f|
49
+ assert(!ping.found?(f))
50
+ end
48
51
  end
49
52
 
50
53
  def test_when_not_exists
51
54
  stub_request(:any, 'https://www.yegor256.com/absent.html').to_return(status: 404)
52
55
  site = FakeSite.new({ 'url' => 'https://www.yegor256.com/' })
53
56
  ping = GptTranslate::Ping.new(site, '/absent.html')
54
- assert(!ping.exists?)
57
+ Tempfile.open do |f|
58
+ assert(!ping.found?(f))
59
+ end
55
60
  end
56
61
 
57
62
  def test_relative_path
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.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko