jekyll-chatgpt-translate 0.0.12 → 0.0.13
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/ping.rb +17 -13
- data/lib/jekyll-chatgpt-translate/version.rb +1 -1
- data/test/test_ping.rb +9 -0
- 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: 864696015c8e2b7ee1abba3e5bd8aee3310d7d9d3d85721b5a082b45eef6cd0b
|
4
|
+
data.tar.gz: cfc8b8d09865af57aea8202be714c0ee7211da0fc2121873b8004f37cf40a507
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83cbb3ae370b246351ce64302e48b0d5c4b94fcc985fb7c239f36f7c2767e5779fa45998ae6b808b8c8e973369ee6d6f21c9a62b241cb5459fb235eb9a424d01
|
7
|
+
data.tar.gz: 9400ee361c82cf27582e416a607d292f16850269fa204a837ff40f052917692dbb0a8d9f3aade9d21d0c2d74870028d6c8c4aec50b4b0efd177f6efc6a220e5c
|
@@ -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.13'
|
32
32
|
s.license = 'MIT'
|
33
33
|
s.summary = 'Translate Jekyll Pages Through ChatGPT'
|
34
34
|
s.description = [
|
@@ -51,21 +51,25 @@ class GptTranslate::Ping
|
|
51
51
|
home = @site.config['url']
|
52
52
|
return false if home.nil?
|
53
53
|
uri = Iri.new(home).path(@path)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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}\"")
|
63
68
|
end
|
64
|
-
Jekyll.logger.
|
65
|
-
|
66
|
-
Jekyll.logger.info("
|
69
|
+
Jekyll.logger.debug("GET \"#{uri}\": #{before.code}")
|
70
|
+
rescue StandardError => e
|
71
|
+
Jekyll.logger.info("Failed to ping \"#{uri}\": #{e.message}")
|
67
72
|
end
|
68
|
-
Jekyll.logger.debug("GET #{uri}: #{before.code}")
|
69
73
|
false
|
70
74
|
end
|
71
75
|
end
|
data/test/test_ping.rb
CHANGED
@@ -59,6 +59,15 @@ class GptTranslate::PingTest < Minitest::Test
|
|
59
59
|
end
|
60
60
|
end
|
61
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, ''))
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
62
71
|
def test_relative_path
|
63
72
|
assert_raises do
|
64
73
|
GptTranslate::Ping.new({}, '404.html')
|