jekyll-chatgpt-translate 0.0.7 → 0.0.9

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: 951ecc1df96633e4552be477e42c43977b0187282978d9cb1c07bedc3913e8fa
4
- data.tar.gz: 9fb20f291797eaee903f0ca20aaf0adcc7ed65fd77626dda6afbe3c6390418cd
3
+ metadata.gz: ad6aab5a14ab43febd8be49411b3cd30c89213140b5bc11d5ef0f2dd86c8de3f
4
+ data.tar.gz: 396b48cfade277af37a5698049e1e8ed09c37b2777b4a009ac5561543a340708
5
5
  SHA512:
6
- metadata.gz: d94a2be708d58bb23427a707660276ce7d42dc90372924644b76558933c631834d3eeece4b1bb46c5b89221c3d758b62e71958137e355edb02451ef671fc9f03
7
- data.tar.gz: 623f0e383d89805288678b37d9304d365b3adf6995d60c9bec4e7a9e6c85e2be44cb51e4a1001892cb5919a55799f99dfe9e174c5edf931f9f2e641d24ffed37
6
+ metadata.gz: 4b6917658e850826539295bc02266bab962c411812ada39f78e219837587b5a481de3b55a9471926b674d4d14b377680d8957c7d7564e8cdbff2d983bdd3f85f
7
+ data.tar.gz: aa290814eb9f36d3feafed043bb24b38d308b33f70cd732fa9136ddb50972142c06b6132542535e006c36735f02d698bb1f501381305a3a6c68d1d65a2a8218b
data/.rubocop.yml CHANGED
@@ -27,3 +27,9 @@ Layout/EmptyLineAfterGuardClause:
27
27
  Enabled: false
28
28
  Naming/FileName:
29
29
  Enabled: false
30
+ Layout/IndentationWidth:
31
+ Enabled: false
32
+ Layout/ElseAlignment:
33
+ Enabled: false
34
+ Layout/EndAlignment:
35
+ Enabled: false
data/Gemfile CHANGED
@@ -29,7 +29,7 @@ gem 'cucumber', '8.0.0', 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
32
- gem 'rubocop', '1.55.1', require: false
32
+ gem 'rubocop', '1.56.0', require: false
33
33
  gem 'rubocop-rspec', '2.23.2', require: false
34
34
  gem 'simplecov', '0.22.0', require: false
35
35
  gem 'webmock', '3.18.1', require: false
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ <img src="logo.png" style="width:256px;"/>
2
+
1
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)
2
4
  [![Gem Version](https://badge.fury.io/rb/jekyll-chatgpt-translate.svg)](http://badge.fury.io/rb/jekyll-chatgpt-translate)
3
5
 
@@ -20,7 +22,7 @@ chatgpt-translate:
20
22
  targets:
21
23
  -
22
24
  language: cn
23
- permalink: :year-:month-:day-:title-chinese.html
25
+ permalink: :year-:month-:day-:slug-chinese.html
24
26
  layout: chinese-translated
25
27
  -
26
28
  language: fr
@@ -34,14 +36,18 @@ OpenAI API KEY must be set in `OPENAI_API_KEY` environment variable, otherwise
34
36
  the plugin will not do any translation and won't generate translated pages.
35
37
  You can get your key [here](https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key).
36
38
 
37
- The plugin is compatible with
38
- [Jekyll 3.9.3](https://jekyllrb.com/news/2023/01/29/jekyll-3-9-3-released/) and
39
- [Jekyll 4.3.2](https://jekyllrb.com/news/2023/01/20/jekyll-4-3-2-released/).
39
+ Inside the original page you can use `{{ page.translated-XX-url }}` in order to render the URL
40
+ of the translated page, where `XX` is the ISO-839-1 code of the target language..
41
+ Inside the translated page you can use `{{ page.translated-original-url }}` in order
42
+ to get the URL of the page that was translated.
40
43
 
41
44
  ## Options
42
45
 
43
46
  Full list of options available to specify in `_config.yml`:
44
47
 
48
+ * `api_key_file` (optional) — the file with OpenAI API key. If this option is not specified,
49
+ it is expected to have the key in the `OPENAI_API_KEY` environment variable.
50
+
45
51
  * `model` (optional) — specifies the model to use by ChatGPT.
46
52
 
47
53
  * `source` (optional) — is the ISO-839-1 code of the source language.
@@ -61,7 +67,7 @@ This layout will be specified for the pages generated by this plugin.
61
67
 
62
68
  ## How to Contribute
63
69
 
64
- Test is like this:
70
+ Make a fork and then test it locally like this:
65
71
 
66
72
  ```bash
67
73
  $ bundle update
data/features/cli.feature CHANGED
@@ -8,6 +8,7 @@ Feature: Simple site building
8
8
  plugins:
9
9
  - jekyll-chatgpt-translate
10
10
  chatgpt-translate:
11
+ api_key_file: the-file-is-absent.txt
11
12
  source: en
12
13
  layout: translated
13
14
  targets:
@@ -21,11 +22,14 @@ Feature: Simple site building
21
22
  """
22
23
  And I have a "_layouts/default.html" file with content:
23
24
  """
25
+ The Chinese: {{ page.translated-cn-url }}
26
+ The French: {{ page.translated-fr-url }}
24
27
  {{ content }}
25
28
  """
26
29
  And I have a "_layouts/chinese-translated.html" file with content:
27
30
  """
28
31
  Chinese: {{ content }}
32
+ The original: {{ page.translated-original-url }}
29
33
  """
30
34
  And I have a "_posts/2023-01-01-hello.md" file with content:
31
35
  """
@@ -38,7 +42,9 @@ Feature: Simple site building
38
42
  Then I build Jekyll site
39
43
  Then File "_chatgpt-translated/cn/2023-01-01-hello-cn.md" exists
40
44
  Then File "_site/2023/01/01/hello.html" exists
45
+ Then File "_site/2023/01/01/hello.html" contains "The Chinese: /2023-01-01-hello-chinese.html"
41
46
  Then File "_site/2023-01-01-hello-chinese.html" exists
47
+ Then File "_site/2023-01-01-hello-chinese.html" contains "The original: /2023/01/01/hello.html"
42
48
  Then File "_site/2023/hello-french.html" exists
43
49
  And Exit code is zero
44
50
 
@@ -53,6 +53,11 @@ Then(/^File "([^"]*)" exists$/) do |name|
53
53
  raise "The file \"#{name}\" is absent:\n#{`tree`}" unless File.exist?(name)
54
54
  end
55
55
 
56
+ Then(/^File "([^"]*)" contains "([^"]*)"$/) do |name, text|
57
+ content = File.read(name)
58
+ raise "The file \"#{name}\" doesn't contain \"#{text}\":\n#{content}" unless content.include?(text)
59
+ end
60
+
56
61
  Then(/^Stdout is empty$/) do
57
62
  raise "STDOUT is not empty:\n#{@stdout}" unless @stdout == ''
58
63
  end
@@ -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.7'
31
+ s.version = '0.0.9'
32
32
  s.license = 'MIT'
33
33
  s.summary = 'Translate Jekyll Pages Through ChatGPT'
34
34
  s.description = [
@@ -42,15 +42,9 @@ class GptTranslate::Generator < Jekyll::Generator
42
42
 
43
43
  # Main plugin action, called by Jekyll-core
44
44
  def generate(site)
45
- @site = site
45
+ config ||= site.config['chatgpt-translate'] || {}
46
46
  home = '_chatgpt-translated'
47
- key = ENV.fetch('OPENAI_API_KEY', nil)
48
- if key.nil? && Jekyll.env == 'development'
49
- Jekyll.logger.info("OPENAI_API_KEY environment variable is not set and \
50
- we are in development mode, no actual translation will happen, \
51
- but pages will be generated")
52
- key = ''
53
- end
47
+ key = api_key(config)
54
48
  if key.nil?
55
49
  Jekyll.logger.info('jekyll-chatgpt-translate requires OPENAI_API_KEY environment variable')
56
50
  return
@@ -87,6 +81,7 @@ but pages will be generated")
87
81
  "layout: #{target['layout'] || layout}",
88
82
  "title: #{doc.data['title']}",
89
83
  "permalink: #{link}",
84
+ "translated-original-url: #{doc.url}",
90
85
  '---',
91
86
  '',
92
87
  translated,
@@ -94,8 +89,10 @@ but pages will be generated")
94
89
  "Translated by ChatGPT #{model}/#{GptTranslate::VERSION}\n{: .jekyll-chatgpt-translate}"
95
90
  ].join("\n")
96
91
  )
92
+ doc.data["translated-#{lang}-url"] = link
97
93
  site.pages << Jekyll::Page.new(site, site.source, File.dirname(path), File.basename(path))
98
94
  total += 1
95
+ Jekyll.logger.info("Translated via ChatGPT: #{path}")
99
96
  end
100
97
  break if total >= threshold
101
98
  end
@@ -104,8 +101,22 @@ but pages will be generated")
104
101
 
105
102
  private
106
103
 
107
- # Returns the plugin's config or an empty hash if not set
108
- def config
109
- @config ||= @site.config['chatgpt-translate'] || {}
104
+ # Try to find the KEY, either in the environment, a file, etc.
105
+ # If not found, return NIL.
106
+ def api_key(config)
107
+ file = config['api_key_file']
108
+ key = if file.nil?
109
+ ENV.fetch('OPENAI_API_KEY', nil)
110
+ elsif File.exist?(file)
111
+ File.read(file).strip
112
+ end
113
+ if key.nil? && Jekyll.env == 'development'
114
+ Jekyll.logger.info("OPENAI_API_KEY environment variable is not set, \
115
+ the `api_key_file` option is not specified in the _config.yml, and \
116
+ we are in development mode, that's why no actual translation will happen, \
117
+ but .md pages will be generated")
118
+ key = ''
119
+ end
120
+ key
110
121
  end
111
122
  end
data/logo.png ADDED
Binary file
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.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -125,6 +125,7 @@ files:
125
125
  - lib/jekyll-chatgpt-translate/ping.rb
126
126
  - lib/jekyll-chatgpt-translate/plain.rb
127
127
  - lib/jekyll-chatgpt-translate/version.rb
128
+ - logo.png
128
129
  - renovate.json
129
130
  - test/test__helper.rb
130
131
  - test/test_chatgpt.rb