jekyll-chatgpt-translate 0.0.17 → 0.0.18

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: f48ffb6334ada2deb878ede0622065326b23ed765946070aff20c9ce5888715d
4
- data.tar.gz: df98890a24fb215b1ba1efc2794a6e4bf1cb0b9949efb94648b267c343052562
3
+ metadata.gz: 1f593e5927f89dc9fe25dcbe28cc61ed938b3fdc42aee742d9ec31ebc86417fe
4
+ data.tar.gz: c5486a9adaf6e838bd016ea01175169786dbdd1807601cf922b0acc065c0a337
5
5
  SHA512:
6
- metadata.gz: 158df2fdeb7459cace117be39d3e94f9830c852034719ae049777b863bbbc61dc869c362534cc651f53e21af1fa37203865ec7b295254768274921a406cf858f
7
- data.tar.gz: f8e34b0bd3432d598b9e7b2f5582ede75231f0c8c9e3dd71db348a5711ddf56106f7685adbf28c02a84f8ef84c7589f4a4909c650afb08d9a110751a317b8bbd
6
+ metadata.gz: 794664182ebba232506ab97b026d02a7060ee369fb16756308d43362df24aed862703836fb0af142c07240fd1eeeeeb9305e43804ed5b34300ce2dff1c30a03c
7
+ data.tar.gz: f1db90b466e6ea441519ee35351a2bf62b9182ed772ab020b5cd4692fc8932a22115fb994089b1cb70724c92a4344865810312b7a58fe1fe666ba0e5c308aaeb
data/README.md CHANGED
@@ -50,6 +50,8 @@ to get the URL of the page that was translated.
50
50
 
51
51
  You can also use `{{ page.chatgpt-model }}`
52
52
  inside both the original page and the translated one, to refer to the model of ChatGPT.
53
+ The presence of this attribute in the `{{ page }}` means that the
54
+ page was translated or the translated HTML was downloaded and placed into the `_site` directory.
53
55
 
54
56
  ## Options
55
57
 
@@ -62,6 +64,11 @@ Full list of options available to specify in `_config.yml`:
62
64
 
63
65
  * `source` (optional) — is the ISO-839-1 code of the source language.
64
66
 
67
+ * `no_download` (optional) — if this attribute is present, the plugin won't try
68
+ to find HTML versions of translated pages in the Internet and won't try to
69
+ download them and place into the `_site` directory. Thus, your entire site
70
+ will have to be re-translated on every build (might be very ineffective if the site is big!)
71
+
65
72
  * `layout` (optional) — is name of the file in `_layouts` directory, without the extension.
66
73
  This layout will be specified for the pages generated by this plugin.
67
74
 
@@ -40,7 +40,7 @@ Given(/^I have a "([^"]*)" file with content:$/) do |file, text|
40
40
  File.write(file, text.gsub('\\xFF', 0xFF.chr))
41
41
  end
42
42
 
43
- When(/^I build Jekyll site$/) do
43
+ When('I build Jekyll site') do
44
44
  @stdout = `jekyll build`
45
45
  @exitstatus = $CHILD_STATUS.exitstatus
46
46
  end
@@ -59,20 +59,16 @@ Then('File {string} contains {string}') do |string, string2|
59
59
  raise "The file \"#{string}\" doesn't contain \"#{string2}\":\n#{content}" unless content.include?(string2)
60
60
  end
61
61
 
62
- Then(/^Stdout is empty$/) do
63
- raise "STDOUT is not empty:\n#{@stdout}" unless @stdout == ''
64
- end
65
-
66
- Then(/^Exit code is zero$/) do
62
+ Then('Exit code is zero') do
67
63
  raise "Non-zero exit #{@exitstatus}:\n#{@stdout}" unless @exitstatus.zero?
68
64
  end
69
65
 
70
- Then(/^Exit code is not zero$/) do
66
+ Then('Exit code is not zero') do
71
67
  raise 'Zero exit code' if @exitstatus.zero?
72
68
  end
73
69
 
74
- When(/^I run bash with "([^"]*)"$/) do |text|
75
- @stdout = `#{text}`
70
+ When('I run bash with {string}') do |string|
71
+ @stdout = `#{string}`
76
72
  @exitstatus = $CHILD_STATUS.exitstatus
77
73
  end
78
74
 
@@ -81,7 +77,7 @@ When(/^I run bash with:$/) do |text|
81
77
  @exitstatus = $CHILD_STATUS.exitstatus
82
78
  end
83
79
 
84
- When(/^I copy this gem into temp dir$/) do
80
+ When('I copy this gem into temp dir') do
85
81
  FileUtils.copy_entry(@cwd, File.join(@dir, 'jekyll-chatgpt-translate'))
86
82
  end
87
83
 
@@ -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.17'
31
+ s.version = '0.0.18'
32
32
  s.license = 'MIT'
33
33
  s.summary = 'Translate Jekyll Pages Through ChatGPT'
34
34
  s.description = [
@@ -68,41 +68,42 @@ class GptTranslate::Generator < Jekyll::Generator
68
68
  FileUtils.mkdir_p(File.dirname(path))
69
69
  File.write(path, '') # in order to surpress warnings in Page ctor
70
70
  dest = Jekyll::Page.new(site, site.source, File.dirname(path), File.basename(path)).destination(site.dest)
71
- doc.data["translated-#{lang}-url"] = link
72
- doc.data['chatgpt-model'] = model
73
- if GptTranslate::Ping.new(site, link).found?(dest, version)
71
+ if config['no_download'].nil? && GptTranslate::Ping.new(site, link).found?(dest, version)
74
72
  copied += 1
73
+ elsif translated >= threshold
75
74
  next
75
+ else
76
+ gpt = GptTranslate::ChatGPT.new(
77
+ key,
78
+ model,
79
+ config['source'] || 'en',
80
+ lang
81
+ )
82
+ foreign = gpt.translate(plain)
83
+ File.write(
84
+ path,
85
+ [
86
+ '---',
87
+ "layout: #{target['layout'] || layout}",
88
+ "title: #{doc['title'].to_json}",
89
+ "description: #{doc['description'].to_json}",
90
+ "permalink: #{link.to_json}",
91
+ "translated-original-url: #{doc.url.to_json}",
92
+ "translated-language: #{lang.to_json}",
93
+ "chatgpt-model: #{model.to_json}",
94
+ '---',
95
+ '',
96
+ foreign,
97
+ '',
98
+ "#{marker} on #{Time.now.strftime('%d/%m/%Y %H:%M')}\n{: .jekyll-chatgpt-translate}"
99
+ ].join("\n")
100
+ )
101
+ site.pages << Jekyll::Page.new(site, site.source, File.dirname(path), File.basename(path))
102
+ translated += 1
103
+ Jekyll.logger.info("Translated via ChatGPT: #{path} (#{File.size(path)} bytes)")
76
104
  end
77
- next if translated >= threshold
78
- gpt = GptTranslate::ChatGPT.new(
79
- key,
80
- model,
81
- config['source'] || 'en',
82
- lang
83
- )
84
- foreign = gpt.translate(plain)
85
- File.write(
86
- path,
87
- [
88
- '---',
89
- "layout: #{target['layout'] || layout}",
90
- "title: #{doc['title'].to_json}",
91
- "description: #{doc['description'].to_json}",
92
- "permalink: #{link.to_json}",
93
- "translated-original-url: #{doc.url.to_json}",
94
- "translated-language: #{lang.to_json}",
95
- "chatgpt-model: #{model.to_json}",
96
- '---',
97
- '',
98
- foreign,
99
- '',
100
- "#{marker} on #{Time.now.strftime('%d/%m/%Y %H:%M')}\n{: .jekyll-chatgpt-translate}"
101
- ].join("\n")
102
- )
103
- site.pages << Jekyll::Page.new(site, site.source, File.dirname(path), File.basename(path))
104
- translated += 1
105
- Jekyll.logger.info("Translated via ChatGPT: #{path} (#{File.size(path)} bytes)")
105
+ doc.data["translated-#{lang}-url"] = link
106
+ doc.data['chatgpt-model'] = model
106
107
  end
107
108
  end
108
109
  Jekyll.logger.info("#{translated} pages translated and #{copied} pages copied in #{(Time.now - start).round(2)}s")
@@ -23,5 +23,5 @@
23
23
  # SOFTWARE.
24
24
 
25
25
  module GptTranslate
26
- VERSION = '0.0.17'
26
+ VERSION = '0.0.18'
27
27
  end
@@ -75,28 +75,23 @@ class GptTranslate::GeneratorTest < Minitest::Test
75
75
  end
76
76
 
77
77
  class FakeDocument
78
+ attr_reader :data
79
+
78
80
  def initialize(path)
79
81
  @path = path
82
+ @data = { 'date' => Time.now, 'title' => 'Hello!' }
80
83
  end
81
84
 
82
85
  def content
83
86
  'Hello, world!'
84
87
  end
85
88
 
86
- def data
87
- {}
89
+ def []=(key, value)
90
+ @data[key] = value
88
91
  end
89
92
 
90
- def []=(key, value); end
91
-
92
93
  def [](key)
93
- if key == 'date'
94
- Time.now
95
- elsif key == 'title'
96
- 'Hello!'
97
- else
98
- ''
99
- end
94
+ @data[key] || ''
100
95
  end
101
96
 
102
97
  def relative_path
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.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko