jekyll-chatgpt-translate 0.0.20 → 0.0.21
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 +4 -4
- data/.rubocop.yml +1 -1
- data/README.md +0 -1
- data/features/cli.feature +1 -1
- data/jekyll-chatgpt-translate.gemspec +1 -1
- data/lib/jekyll-chatgpt-translate/chatgpt.rb +4 -1
- data/lib/jekyll-chatgpt-translate/generator.rb +20 -14
- data/lib/jekyll-chatgpt-translate/ping.rb +1 -1
- data/lib/jekyll-chatgpt-translate/version.rb +1 -1
- 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: bae88d4bb6c95da76a68c64321f5d308611a19981158f69cd2aa8763d0f4f8f0
|
4
|
+
data.tar.gz: b820a3d53adafd3ea91f365e95851bf848e05890281d1cc7d85bc6a19692af3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 554c9a981763d2957c83b396098fec3b75c23fd98f73a180b33528db97a43406cc2b6595893b1e848a59829e614ec4eb4c70f50d63301d6b93047caf12a81e19
|
7
|
+
data.tar.gz: 695cbae5292d6e81ad69d81657e5ded96f69f2c970bfa2d0ad4b8da23c8c8f412cd77e3944ec09e064417114b0c2ae3518b61b80c3af3a2d4d376e0d0dd8c6b0
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
[](http://badge.fury.io/rb/glogin)
|
2
1
|
<img src="logo.png" style="width:256px;"/>
|
3
2
|
|
4
3
|
[](https://github.com/yegor256/jekyll-chatgpt-translate/actions/workflows/rake.yml)
|
data/features/cli.feature
CHANGED
@@ -40,6 +40,7 @@ Feature: Simple site building
|
|
40
40
|
Hello, world!
|
41
41
|
"""
|
42
42
|
Then I build Jekyll site
|
43
|
+
And Exit code is zero
|
43
44
|
And File "_chatgpt-translated/zh/2023-01-01-hello-zh.md" exists
|
44
45
|
And File "_chatgpt-translated/zh/2023-01-01-hello-zh.md" contains "/2023-01-01-hello-chinese.html"
|
45
46
|
And File "_chatgpt-translated/zh/2023-01-01-hello-zh.md" contains "translated-language: \"zh\""
|
@@ -48,5 +49,4 @@ Feature: Simple site building
|
|
48
49
|
And File "_site/2023-01-01-hello-chinese.html" exists
|
49
50
|
And File "_site/2023-01-01-hello-chinese.html" contains "The original: /2023/01/01/hello.html"
|
50
51
|
And File "_site/2023/hello-french.html" exists
|
51
|
-
And Exit code is zero
|
52
52
|
|
@@ -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.21'
|
32
32
|
s.license = 'MIT'
|
33
33
|
s.summary = 'Translate Jekyll Pages Through ChatGPT'
|
34
34
|
s.description = [
|
@@ -50,7 +50,10 @@ class GptTranslate::ChatGPT
|
|
50
50
|
def translate(markdown, min: 32)
|
51
51
|
markdown.split(/\n{2,}/).compact.map do |par|
|
52
52
|
par.strip!
|
53
|
-
if
|
53
|
+
if @source == @target
|
54
|
+
Jekyll.logger.debug("No need to translate from #{@source.inspect} to #{@target.inspect}: #{par.inspect}")
|
55
|
+
par
|
56
|
+
elsif par.length < min
|
54
57
|
Jekyll.logger.debug("Not translating this, b/c too short: #{par.inspect}")
|
55
58
|
par
|
56
59
|
elsif par.start_with?('```') || par.end_with?('```')
|
@@ -58,7 +58,7 @@ class GptTranslate::Generator < Jekyll::Generator
|
|
58
58
|
translated = 0
|
59
59
|
copied = 0
|
60
60
|
model = config['model'] || 'gpt-3.5-turbo'
|
61
|
-
marker = "Translated by ChatGPT #{model}/#{version}"
|
61
|
+
marker = "Translated by ChatGPT #{model}#{version.empty? ? '' : "/#{version}"}"
|
62
62
|
site.posts.docs.shuffle.each do |doc|
|
63
63
|
plain = GptTranslate::Plain.new(doc.content).to_s
|
64
64
|
config['targets'].each do |target|
|
@@ -67,9 +67,23 @@ class GptTranslate::Generator < Jekyll::Generator
|
|
67
67
|
raise 'Language must be defined for each target' if target.nil?
|
68
68
|
path = File.join(home, lang, doc.basename.gsub(/\.md$/, "-#{lang}.md"))
|
69
69
|
FileUtils.mkdir_p(File.dirname(path))
|
70
|
-
File.write(
|
71
|
-
|
72
|
-
|
70
|
+
File.write(
|
71
|
+
path,
|
72
|
+
[
|
73
|
+
'---',
|
74
|
+
"layout: #{target['layout'] || layout}",
|
75
|
+
"title: #{doc['title'].to_json}",
|
76
|
+
"description: #{doc['description'].to_json}",
|
77
|
+
"permalink: #{link.to_json}",
|
78
|
+
"translated-original-url: #{doc.url.to_json}",
|
79
|
+
"translated-language: #{lang.to_json}",
|
80
|
+
"chatgpt-model: #{model.to_json}",
|
81
|
+
'---'
|
82
|
+
].join("\n")
|
83
|
+
)
|
84
|
+
url = Jekyll::Page.new(site, site.source, File.dirname(path), File.basename(path)).url
|
85
|
+
ping = GptTranslate::Ping.new(site, link)
|
86
|
+
if config['no_download'].nil? && ping.found?(File.join(site.dest, url), version.empty? ? '' : marker)
|
73
87
|
copied += 1
|
74
88
|
elsif translated >= threshold
|
75
89
|
next
|
@@ -84,20 +98,12 @@ class GptTranslate::Generator < Jekyll::Generator
|
|
84
98
|
File.write(
|
85
99
|
path,
|
86
100
|
[
|
87
|
-
'---',
|
88
|
-
"layout: #{target['layout'] || layout}",
|
89
|
-
"title: #{doc['title'].to_json}",
|
90
|
-
"description: #{doc['description'].to_json}",
|
91
|
-
"permalink: #{link.to_json}",
|
92
|
-
"translated-original-url: #{doc.url.to_json}",
|
93
|
-
"translated-language: #{lang.to_json}",
|
94
|
-
"chatgpt-model: #{model.to_json}",
|
95
|
-
'---',
|
96
101
|
'',
|
97
102
|
foreign,
|
98
103
|
'',
|
99
104
|
"#{marker} on #{Time.now.strftime('%Y-%m-%d at %H:%M')}\n{: .jekyll-chatgpt-translate}"
|
100
|
-
].join("\n")
|
105
|
+
].join("\n"),
|
106
|
+
mode: 'a+'
|
101
107
|
)
|
102
108
|
site.pages << Jekyll::Page.new(site, site.source, File.dirname(path), File.basename(path))
|
103
109
|
translated += 1
|
@@ -64,7 +64,7 @@ class GptTranslate::Ping
|
|
64
64
|
end
|
65
65
|
Jekyll.logger.info("Re-translation required for #{uri.inspect}")
|
66
66
|
else
|
67
|
-
Jekyll.logger.info("The page is absent, will translate #{uri.inspect}")
|
67
|
+
Jekyll.logger.info("The page is absent, will translate #{uri.inspect} (#{before.code})")
|
68
68
|
end
|
69
69
|
Jekyll.logger.debug("GET #{uri.inspect}: #{before.code}")
|
70
70
|
rescue StandardError => e
|