jekyll-chatgpt-translate 0.0.18 → 0.0.19
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 +2 -0
- data/README.md +6 -0
- data/jekyll-chatgpt-translate.gemspec +1 -1
- data/lib/jekyll-chatgpt-translate/chatgpt.rb +3 -3
- data/lib/jekyll-chatgpt-translate/generator.rb +3 -2
- data/lib/jekyll-chatgpt-translate/plain.rb +10 -1
- data/lib/jekyll-chatgpt-translate/version.rb +1 -1
- data/test/test_plain.rb +13 -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: d7cc9cfc295b4eeb123b972094f4fa1c648a88f3df384a78b489b9b0bafbd0c1
|
4
|
+
data.tar.gz: 06cd12eabf0fbf6e77a64f52384609bcdc33edb8c6324aa4555de4f7fb275c99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0b55a94c132688afe28b9edbc4115570e6fd449b001bc606bf33c9d30712f2c1639fa8e0334652c0e8aa36b79e356f40845162e810e5b980f8b2dbcd7641746
|
7
|
+
data.tar.gz: e058ea19c7ffb630ab48bac0b433c8fde5f5b76d6087833cb2f7a70c04eaaca32f7273cacd881caf7b3b9355b5cb6a15f539060ff14bd3184baf5a6214b79914
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
[](http://badge.fury.io/rb/glogin)
|
1
2
|
<img src="logo.png" style="width:256px;"/>
|
2
3
|
|
3
4
|
[](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.
|
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
|
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
|
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
|
+
""
|
91
|
+
end
|
92
|
+
|
84
93
|
def raw_html(content)
|
85
94
|
content
|
86
95
|
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(
|
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('', GptTranslate::Plain.new('').to_s)
|
96
|
+
end
|
97
|
+
|
86
98
|
def test_html
|
87
99
|
assert_equal(
|
88
100
|
'This is picture: <img src="a"/>!',
|