jekyll-chatgpt-translate 0.0.33 → 0.0.35
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/.github/workflows/rake.yml +1 -1
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/jekyll-chatgpt-translate.gemspec +1 -1
- data/lib/jekyll-chatgpt-translate/chatgpt.rb +4 -2
- data/lib/jekyll-chatgpt-translate/pars.rb +54 -0
- data/lib/jekyll-chatgpt-translate/plain.rb +1 -1
- data/lib/jekyll-chatgpt-translate/version.rb +1 -1
- data/test/test_pars.rb +74 -0
- data/test/test_plain.rb +7 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 841ab37ebdb5e4049f301883bd5d3c411dbf7719824c52f8fa3f3604aebb0109
|
4
|
+
data.tar.gz: e553ef7cdf4564adba5128bf9bb7eea90c59f7724fa72986427a5e31e7bf2bb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9a6c85190c260ba4770691f4810cbe775f6ae3b2aafba67f5f0081fb540e2a86dc817ae65fccb857643e39d446e4c62b2a98dabe8ce43a46df8a6786ac59b1b
|
7
|
+
data.tar.gz: dba3c7a5bd214a8f970fa623d7dc46779928ddf334fa10f3ca42cfafb61f9a7fae580cd86ed0f11d55f1a08082e0f04eead95ab098481231940e94216cdacaa0
|
data/.github/workflows/rake.yml
CHANGED
data/Gemfile
CHANGED
@@ -25,7 +25,7 @@
|
|
25
25
|
source 'https://rubygems.org'
|
26
26
|
gemspec
|
27
27
|
|
28
|
-
gem 'cucumber', '
|
28
|
+
gem 'cucumber', '9.0.1', require: false
|
29
29
|
gem 'kramdown-parser-gfm', '1.1.0', require: false
|
30
30
|
gem 'minitest', '5.19.0', require: false
|
31
31
|
gem 'rake', '13.0.6', require: false
|
data/README.md
CHANGED
@@ -50,7 +50,7 @@ to get the URL of the page that was translated.
|
|
50
50
|
|
51
51
|
You can also use `{{ page.chatgpt-translate.model }}`
|
52
52
|
inside both the original page and the translated one, to refer to the model of ChatGPT.
|
53
|
-
The presence of
|
53
|
+
The presence of `{{ page.chatgpt-translate }}` means that the
|
54
54
|
page was translated or the translated HTML was downloaded and placed into the `_site` directory.
|
55
55
|
|
56
56
|
## Options
|
@@ -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.35'
|
32
32
|
s.license = 'MIT'
|
33
33
|
s.summary = 'Translate Jekyll Pages Through ChatGPT'
|
34
34
|
s.description = [
|
@@ -25,6 +25,7 @@
|
|
25
25
|
require 'jekyll'
|
26
26
|
require 'openai'
|
27
27
|
require 'iso-639'
|
28
|
+
require_relative 'pars'
|
28
29
|
require_relative 'prompt'
|
29
30
|
|
30
31
|
# The module we are in.
|
@@ -51,7 +52,8 @@ class GptTranslate::ChatGPT
|
|
51
52
|
end
|
52
53
|
|
53
54
|
def translate(markdown, min: 32)
|
54
|
-
|
55
|
+
GptTranslate::Pars.new(markdown).to_a.map do |pa|
|
56
|
+
par = pa.dup
|
55
57
|
par.strip!
|
56
58
|
if @source == @target
|
57
59
|
Jekyll.logger.debug("No need to translate from #{@source.inspect} to #{@target.inspect}: #{par.inspect}")
|
@@ -59,7 +61,7 @@ class GptTranslate::ChatGPT
|
|
59
61
|
elsif par.length < min
|
60
62
|
Jekyll.logger.debug("Not translating this, b/c too short: #{par.inspect}")
|
61
63
|
par
|
62
|
-
elsif par.start_with?('```')
|
64
|
+
elsif par.start_with?('```')
|
63
65
|
Jekyll.logger.debug("Not translating this code block: #{par.inspect}")
|
64
66
|
par
|
65
67
|
elsif par =~ /^[^\p{Alnum}\*'"\[]/
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
# The module we are in.
|
26
|
+
module GptTranslate; end
|
27
|
+
|
28
|
+
# Markdown broken down ito pars.
|
29
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
+
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
31
|
+
# License:: MIT
|
32
|
+
class GptTranslate::Pars
|
33
|
+
# Ctor.
|
34
|
+
# +markdown+ The markdown
|
35
|
+
def initialize(markdown)
|
36
|
+
@markdown = markdown
|
37
|
+
end
|
38
|
+
|
39
|
+
# Returns an array of strings
|
40
|
+
def to_a
|
41
|
+
pars = []
|
42
|
+
inside = false
|
43
|
+
@markdown.strip.split(/\n{2,}/).compact.each do |par|
|
44
|
+
if inside
|
45
|
+
pars[pars.size - 1] = "#{pars[pars.size - 1]}\n\n#{par}"
|
46
|
+
else
|
47
|
+
pars << par
|
48
|
+
end
|
49
|
+
inside = true if par.start_with?('```') && !inside
|
50
|
+
inside = false if par.end_with?('```') && inside
|
51
|
+
end
|
52
|
+
pars
|
53
|
+
end
|
54
|
+
end
|
@@ -42,7 +42,7 @@ class GptTranslate::Plain
|
|
42
42
|
def to_s
|
43
43
|
Redcarpet::Markdown.new(Strip).render(
|
44
44
|
@markdown
|
45
|
-
.gsub(/([^\n])\n(\s*\* )/, "\\1\n\n\\2")
|
45
|
+
.gsub(/([^\n])\n(\s*\* )/, "\\1\n\n\\2") # condensed list into item-per-par
|
46
46
|
.gsub(/<!--.+?-->/m, '')
|
47
47
|
.gsub(/{{[^}]+}}/, '')
|
48
48
|
.gsub(/{%.+?%}/, '')
|
data/test/test_pars.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'minitest/autorun'
|
26
|
+
require_relative 'test__helper'
|
27
|
+
require_relative '../lib/jekyll-chatgpt-translate/pars'
|
28
|
+
|
29
|
+
# Test for Pars.
|
30
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
+
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
32
|
+
# License:: MIT
|
33
|
+
class GptTranslate::ParsTest < Minitest::Test
|
34
|
+
def test_simple_cases
|
35
|
+
assert_equal(1, GptTranslate::Pars.new('Hello, **world**!').to_a.size)
|
36
|
+
assert_equal(2, GptTranslate::Pars.new("Hello,\n\n**world**!").to_a.size)
|
37
|
+
assert_equal(2, GptTranslate::Pars.new("\n\n\nHello,\n\n**world**\n!\n\n").to_a.size)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_returns_unfrozen_strings
|
41
|
+
GptTranslate::Pars.new("Hi, world!\n\n```\ntest\n```\n\nBye\n").to_a.map(&:strip!)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_understands_code_block
|
45
|
+
pars = GptTranslate::Pars.new("Hello:\n\n```java\na\n\nb\n\nc\n```\n\nz").to_a
|
46
|
+
assert_equal(3, pars.size)
|
47
|
+
assert_equal('Hello:', pars[0])
|
48
|
+
assert_equal("```java\na\n\nb\n\nc\n```", pars[1])
|
49
|
+
assert_equal('z', pars[2])
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_understands_empty_block
|
53
|
+
pars = GptTranslate::Pars.new("Hello:\n\n```\n```\n\nz").to_a
|
54
|
+
assert_equal(3, pars.size)
|
55
|
+
assert_equal('Hello:', pars[0])
|
56
|
+
assert_equal("```\n```", pars[1])
|
57
|
+
assert_equal('z', pars[2])
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_understands_empty_block_with_type
|
61
|
+
pars = GptTranslate::Pars.new("Hello:\n\n```java\n```\n\nz").to_a
|
62
|
+
assert_equal(3, pars.size)
|
63
|
+
assert_equal('Hello:', pars[0])
|
64
|
+
assert_equal("```java\n```", pars[1])
|
65
|
+
assert_equal('z', pars[2])
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_understands_two_blocks
|
69
|
+
pars = GptTranslate::Pars.new("```java\na\n\nb\n```\n\n```text\na\n\nb\n```").to_a
|
70
|
+
assert_equal(2, pars.size)
|
71
|
+
assert_equal("```java\na\n\nb\n```", pars[0])
|
72
|
+
assert_equal("```text\na\n\nb\n```", pars[1])
|
73
|
+
end
|
74
|
+
end
|
data/test/test_plain.rb
CHANGED
@@ -111,6 +111,13 @@ class GptTranslate::PlainTest < Minitest::Test
|
|
111
111
|
)
|
112
112
|
end
|
113
113
|
|
114
|
+
def test_code_block_with_empty_lines_inside
|
115
|
+
assert_equal(
|
116
|
+
"```\n\nhello\n\nworld!\n\n```",
|
117
|
+
GptTranslate::Plain.new("```\n\nhello\n\n\n\nworld!\n\n```").to_s
|
118
|
+
)
|
119
|
+
end
|
120
|
+
|
114
121
|
def test_titles
|
115
122
|
assert_equal('# Hello', GptTranslate::Plain.new('# Hello').to_s)
|
116
123
|
assert_equal('## Hello', GptTranslate::Plain.new('## Hello').to_s)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-chatgpt-translate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.35
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: iri
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- lib/jekyll-chatgpt-translate.rb
|
108
108
|
- lib/jekyll-chatgpt-translate/chatgpt.rb
|
109
109
|
- lib/jekyll-chatgpt-translate/generator.rb
|
110
|
+
- lib/jekyll-chatgpt-translate/pars.rb
|
110
111
|
- lib/jekyll-chatgpt-translate/permalink.rb
|
111
112
|
- lib/jekyll-chatgpt-translate/ping.rb
|
112
113
|
- lib/jekyll-chatgpt-translate/plain.rb
|
@@ -117,6 +118,7 @@ files:
|
|
117
118
|
- test/test__helper.rb
|
118
119
|
- test/test_chatgpt.rb
|
119
120
|
- test/test_generator.rb
|
121
|
+
- test/test_pars.rb
|
120
122
|
- test/test_permalink.rb
|
121
123
|
- test/test_ping.rb
|
122
124
|
- test/test_plain.rb
|