jekyll-chatgpt-translate 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/jekyll-chatgpt-translate.gemspec +1 -1
- data/lib/jekyll-chatgpt-translate/generator.rb +7 -2
- data/lib/jekyll-chatgpt-translate/ping.rb +13 -4
- data/test/test_ping.rb +7 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38924a750a0276a65b25263ec22b74f92a2ccd652636a65ec0cf90a46bb45983
|
4
|
+
data.tar.gz: '058007955befb70a3323a3c68863b09621e63d52da65424383644c7751b47861'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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).
|
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
|
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)
|
55
|
-
|
56
|
-
|
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
|
-
|
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
|
-
|
57
|
+
Tempfile.open do |f|
|
58
|
+
assert(!ping.found?(f))
|
59
|
+
end
|
55
60
|
end
|
56
61
|
|
57
62
|
def test_relative_path
|