jekyll-chatgpt-translate 0.0.7 → 0.0.8

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: ae5a29abd8e4cb757fa40d7b50c999a4453901b1be9a597f23e560fa3900416d
4
+ data.tar.gz: e1769e8544c657ad086c462a1d32652edd434ac26509b064d1441f8beb35ea28
5
5
  SHA512:
6
- metadata.gz: d94a2be708d58bb23427a707660276ce7d42dc90372924644b76558933c631834d3eeece4b1bb46c5b89221c3d758b62e71958137e355edb02451ef671fc9f03
7
- data.tar.gz: 623f0e383d89805288678b37d9304d365b3adf6995d60c9bec4e7a9e6c85e2be44cb51e4a1001892cb5919a55799f99dfe9e174c5edf931f9f2e641d24ffed37
6
+ metadata.gz: 97ac19fd067d197faf5fb5c2b541a0641b56c0ca0fbbef3f9fbfe02c4efacb89657fc9d9011bd10081ce6221807eba792be5ed8f12e9617a197c36574f668df4
7
+ data.tar.gz: 2f5251871b78f3052f33b7c1778318d89945b9874295fc36da9ae8f8d7fb34a720bb475210f0e1546ccf18c7a136ee2ed5e24d70aaa4630d5fe7e1f707d95bac
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
@@ -21,11 +21,14 @@ Feature: Simple site building
21
21
  """
22
22
  And I have a "_layouts/default.html" file with content:
23
23
  """
24
+ The Chinese: {{ page.translated-cn-url }}
25
+ The French: {{ page.translated-fr-url }}
24
26
  {{ content }}
25
27
  """
26
28
  And I have a "_layouts/chinese-translated.html" file with content:
27
29
  """
28
30
  Chinese: {{ content }}
31
+ The original: {{ page.translated-original-url }}
29
32
  """
30
33
  And I have a "_posts/2023-01-01-hello.md" file with content:
31
34
  """
@@ -38,7 +41,9 @@ Feature: Simple site building
38
41
  Then I build Jekyll site
39
42
  Then File "_chatgpt-translated/cn/2023-01-01-hello-cn.md" exists
40
43
  Then File "_site/2023/01/01/hello.html" exists
44
+ Then File "_site/2023/01/01/hello.html" contains "The Chinese: /2023-01-01-hello-chinese.html"
41
45
  Then File "_site/2023-01-01-hello-chinese.html" exists
46
+ Then File "_site/2023-01-01-hello-chinese.html" contains "The original: /2023/01/01/hello.html"
42
47
  Then File "_site/2023/hello-french.html" exists
43
48
  And Exit code is zero
44
49
 
@@ -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.8'
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
+ else
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.8
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