jekyll-chatgpt-translate 0.0.18 → 0.0.19

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: 1f593e5927f89dc9fe25dcbe28cc61ed938b3fdc42aee742d9ec31ebc86417fe
4
- data.tar.gz: c5486a9adaf6e838bd016ea01175169786dbdd1807601cf922b0acc065c0a337
3
+ metadata.gz: d7cc9cfc295b4eeb123b972094f4fa1c648a88f3df384a78b489b9b0bafbd0c1
4
+ data.tar.gz: 06cd12eabf0fbf6e77a64f52384609bcdc33edb8c6324aa4555de4f7fb275c99
5
5
  SHA512:
6
- metadata.gz: 794664182ebba232506ab97b026d02a7060ee369fb16756308d43362df24aed862703836fb0af142c07240fd1eeeeeb9305e43804ed5b34300ce2dff1c30a03c
7
- data.tar.gz: f1db90b466e6ea441519ee35351a2bf62b9182ed772ab020b5cd4692fc8932a22115fb994089b1cb70724c92a4344865810312b7a58fe1fe666ba0e5c308aaeb
6
+ metadata.gz: d0b55a94c132688afe28b9edbc4115570e6fd449b001bc606bf33c9d30712f2c1639fa8e0334652c0e8aa36b79e356f40845162e810e5b980f8b2dbcd7641746
7
+ data.tar.gz: e058ea19c7ffb630ab48bac0b433c8fde5f5b76d6087833cb2f7a70c04eaaca32f7273cacd881caf7b3b9355b5cb6a15f539060ff14bd3184baf5a6214b79914
data/.rubocop.yml CHANGED
@@ -33,3 +33,5 @@ Layout/ElseAlignment:
33
33
  Enabled: false
34
34
  Layout/EndAlignment:
35
35
  Enabled: false
36
+ Metrics/ClassLength:
37
+ Max: 200
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Gem Version](https://badge.fury.io/rb/glogin.svg)](http://badge.fury.io/rb/glogin)
1
2
  <img src="logo.png" style="width:256px;"/>
2
3
 
3
4
  [![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)
@@ -69,6 +70,11 @@ Full list of options available to specify in `_config.yml`:
69
70
  download them and place into the `_site` directory. Thus, your entire site
70
71
  will have to be re-translated on every build (might be very ineffective if the site is big!)
71
72
 
73
+ * `min_chars` (optional) — minimum number of chars that must be present in
74
+ a paragraph in order for it to be feasible to go to ChatGPT. The robot
75
+ doesn't translate short paragraphs pretty enough. It's better to keep this
76
+ number big enough, to avoid silly translations. The default is 128.
77
+
72
78
  * `layout` (optional) — is name of the file in `_layouts` directory, without the extension.
73
79
  This layout will be specified for the pages generated by this plugin.
74
80
 
@@ -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.18'
31
+ s.version = '0.0.19'
32
32
  s.license = 'MIT'
33
33
  s.summary = 'Translate Jekyll Pages Through ChatGPT'
34
34
  s.description = [
@@ -47,12 +47,12 @@ class GptTranslate::ChatGPT
47
47
  @target = target
48
48
  end
49
49
 
50
- def translate(text)
50
+ def translate(text, min: 32)
51
51
  text.split("\n\n").compact.map do |par|
52
- if par.length <= 32
52
+ if par.length < min
53
53
  Jekyll.logger.debug("Not translating this, b/c too short: \"#{par}\"")
54
54
  par
55
- elsif par !~ /^[[:alpha:]]/
55
+ elsif par !~ /^[[[:alpha:]]'"]/
56
56
  Jekyll.logger.debug("Not translating this, b/c it's not a plain text: \"#{par}\"")
57
57
  par
58
58
  elsif @key.empty?
@@ -53,6 +53,7 @@ class GptTranslate::Generator < Jekyll::Generator
53
53
  layout = config['layout'] || 'translated'
54
54
  version = config['version'] || GptTranslate::VERSION
55
55
  threshold = config['threshold'] || 1024
56
+ min_chars = config['min_chars'] || 128
56
57
  start = Time.now
57
58
  translated = 0
58
59
  copied = 0
@@ -79,7 +80,7 @@ class GptTranslate::Generator < Jekyll::Generator
79
80
  config['source'] || 'en',
80
81
  lang
81
82
  )
82
- foreign = gpt.translate(plain)
83
+ foreign = gpt.translate(plain, min: min_chars)
83
84
  File.write(
84
85
  path,
85
86
  [
@@ -95,7 +96,7 @@ class GptTranslate::Generator < Jekyll::Generator
95
96
  '',
96
97
  foreign,
97
98
  '',
98
- "#{marker} on #{Time.now.strftime('%d/%m/%Y %H:%M')}\n{: .jekyll-chatgpt-translate}"
99
+ "#{marker} on #{Time.now.strftime('%Y-%m-%d at %H:%M')}\n{: .jekyll-chatgpt-translate}"
99
100
  ].join("\n")
100
101
  )
101
102
  site.pages << Jekyll::Page.new(site, site.source, File.dirname(path), File.basename(path))
@@ -39,7 +39,7 @@ class GptTranslate::Plain
39
39
 
40
40
  def to_s
41
41
  # To turn compact lists into proper lists
42
- @markdown.gsub(/([^\n])\n(\s*\*)/, "\\1\n\n\\2").split(/\n{2,}/).compact.map do |par|
42
+ @markdown.gsub(/([^\n])\n(\s*\* )/, "\\1\n\n\\2").split(/\n{2,}/).compact.map do |par|
43
43
  par.strip!
44
44
  # Liquid tags are removed, but this implementation is primitive
45
45
  # Seehttps://stackoverflow.com/questions/
@@ -55,6 +55,7 @@ class GptTranslate::Plain
55
55
  end
56
56
 
57
57
  # Markdown to pain text.
58
+ # Motivated by https://github.com/vmg/redcarpet/blob/master/lib/redcarpet/render_strip.rb
58
59
  class Strip < Redcarpet::Render::Base
59
60
  %i[
60
61
  block_code block_quote
@@ -71,6 +72,10 @@ class GptTranslate::Plain
71
72
  end
72
73
  end
73
74
 
75
+ def header(text, level)
76
+ "#{'#' * level} #{text}"
77
+ end
78
+
74
79
  def codespan(content)
75
80
  if content.start_with?("\n")
76
81
  "```#{content}```"
@@ -81,6 +86,10 @@ class GptTranslate::Plain
81
86
  end
82
87
  end
83
88
 
89
+ def image(link, title, alt)
90
+ "![#{alt}](#{link} \"#{title}\")"
91
+ end
92
+
84
93
  def raw_html(content)
85
94
  content
86
95
  end
@@ -23,5 +23,5 @@
23
23
  # SOFTWARE.
24
24
 
25
25
  module GptTranslate
26
- VERSION = '0.0.18'
26
+ VERSION = '0.0.19'
27
27
  end
data/test/test_plain.rb CHANGED
@@ -31,8 +31,10 @@ require_relative '../lib/jekyll-chatgpt-translate/plain'
31
31
  # License:: MIT
32
32
  class GptTranslate::PlainTest < Minitest::Test
33
33
  def test_simple_map
34
- assert_equal('Hello, world!', GptTranslate::Plain.new('Hello, **world**!').to_s)
34
+ assert_equal('Hello, world!', GptTranslate::Plain.new("Hello,\n**world**!").to_s)
35
+ assert_equal('Hello, world!', GptTranslate::Plain.new("Hello,\n[world](/x.html)!").to_s)
35
36
  assert_equal('Hello, Jeff!', GptTranslate::Plain.new('Hello, _Jeff_!').to_s)
37
+ # assert_equal('Hello, Walter!', GptTranslate::Plain.new('Hello, ~Walter~!').to_s)
36
38
  assert_equal("Hi\n\nBye", GptTranslate::Plain.new(" Hi\n\nBye\n\n\n").to_s)
37
39
  assert_equal('Hi, dude!', GptTranslate::Plain.new(" Hi,\ndude!\n").to_s)
38
40
  end
@@ -83,6 +85,16 @@ class GptTranslate::PlainTest < Minitest::Test
83
85
  )
84
86
  end
85
87
 
88
+ def test_titles
89
+ assert_equal('# Hello', GptTranslate::Plain.new('# Hello').to_s)
90
+ assert_equal('## Hello', GptTranslate::Plain.new('## Hello').to_s)
91
+ assert_equal('### Hello', GptTranslate::Plain.new('### Hello').to_s)
92
+ end
93
+
94
+ def test_image
95
+ assert_equal('![alt](a.png "hello")', GptTranslate::Plain.new('![alt](a.png "hello")').to_s)
96
+ end
97
+
86
98
  def test_html
87
99
  assert_equal(
88
100
  'This is picture: <img src="a"/>!',
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.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko