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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76da34820682d38fd53ca0c5c02bf8d9e23f5665af2a6f0553f11a62d6fce452
4
- data.tar.gz: 413def3d7da352c1a6c2d7dbd67722329573732d53bfbae96a1bf86c39c9c16e
3
+ metadata.gz: bae88d4bb6c95da76a68c64321f5d308611a19981158f69cd2aa8763d0f4f8f0
4
+ data.tar.gz: b820a3d53adafd3ea91f365e95851bf848e05890281d1cc7d85bc6a19692af3b
5
5
  SHA512:
6
- metadata.gz: 715bdfed0bf33249c0091a66a0f338d89469aaa43db6fb6f80bf79a2e633d68ed0087997ce7b08b259bc24a47196061d3114d2c3f66ab8f1c7f76cc9758e0a2c
7
- data.tar.gz: 6a0eeb27d20053284535b0a053ab3e0832eb6e20477bb3451ac095ce5ab48e967b7e5e607aa777269475ce846b784414382e1367ceb88daf5e24ad458440c745
6
+ metadata.gz: 554c9a981763d2957c83b396098fec3b75c23fd98f73a180b33528db97a43406cc2b6595893b1e848a59829e614ec4eb4c70f50d63301d6b93047caf12a81e19
7
+ data.tar.gz: 695cbae5292d6e81ad69d81657e5ded96f69f2c970bfa2d0ad4b8da23c8c8f412cd77e3944ec09e064417114b0c2ae3518b61b80c3af3a2d4d376e0d0dd8c6b0
data/.rubocop.yml CHANGED
@@ -18,7 +18,7 @@ Layout/MultilineMethodCallIndentation:
18
18
  Metrics/AbcSize:
19
19
  Enabled: false
20
20
  Metrics/BlockLength:
21
- Max: 50
21
+ Max: 100
22
22
  Metrics/CyclomaticComplexity:
23
23
  Max: 20
24
24
  Metrics/PerceivedComplexity:
data/README.md CHANGED
@@ -1,4 +1,3 @@
1
- [![Gem Version](https://badge.fury.io/rb/glogin.svg)](http://badge.fury.io/rb/glogin)
2
1
  <img src="logo.png" style="width:256px;"/>
3
2
 
4
3
  [![rake](https://github.com/yegor256/jekyll-chatgpt-translate/actions/workflows/rake.yml/badge.svg)](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.20'
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 par.length < min
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(path, '') # in order to surpress warnings in Page ctor
71
- dest = Jekyll::Page.new(site, site.source, File.dirname(path), File.basename(path)).destination(site.dest)
72
- if config['no_download'].nil? && GptTranslate::Ping.new(site, link).found?(dest, version)
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
@@ -23,5 +23,5 @@
23
23
  # SOFTWARE.
24
24
 
25
25
  module GptTranslate
26
- VERSION = '0.0.20'
26
+ VERSION = '0.0.21'
27
27
  end
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.20
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko