jekyll-chatgpt-translate 0.0.11 → 0.0.12
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed6617e3b8bf46db264f484e1286ea1f91295f4fb47512cb983a6fc59c7922df
|
4
|
+
data.tar.gz: a0f6c744cd4bf2b2558d7b5568f1ca961a3f854e5264b9d64bb8b24249f03e3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d58f41b76840e524e9f1d72c2a4816b33d9e57ad6b207f54baa226abf68ae6cca848cb8cce80cf1f4502a3ad9b52871db7f7708463bf4101fdbf8c21e5f99bb
|
7
|
+
data.tar.gz: f85b41ad75176c9989a8a3715fd84485b3a2fcbe03e6cca879b7a201ac4b5745dda0aa16695f26cbaad1ec901b84c6837f983f7a04cee94aa26752d13ef41593
|
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.
|
31
|
+
s.version = '0.0.12'
|
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'] ||
|
54
|
+
threshold = config['threshold'] || 1024
|
55
55
|
start = Time.now
|
56
56
|
total = 0
|
57
|
-
|
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
|
-
"
|
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,17 +47,17 @@ 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
54
|
before = Net::HTTP.get_response(URI(uri.to_s))
|
54
55
|
if before.is_a?(Net::HTTPSuccess)
|
55
56
|
html = before.body
|
56
|
-
if html.include?(
|
57
|
+
if html.include?(marker)
|
57
58
|
Jekyll.logger.info("No need to translate, the page exists at \
|
58
59
|
#{uri} (#{html.split.count} words), saved to #{file}")
|
59
|
-
|
60
|
+
FileUtils.mkdir_p(File.dirname(file))
|
60
61
|
File.write(file, html)
|
61
62
|
return true
|
62
63
|
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(
|
49
|
+
assert(ping.found?(f, ''))
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -55,7 +55,7 @@ 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
59
|
end
|
60
60
|
end
|
61
61
|
|