Skip to content

Commit

Permalink
#97 only
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Apr 20, 2024
1 parent 187e40a commit e9f33e2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Metrics/AbcSize:
Metrics/BlockLength:
Max: 100
Metrics/CyclomaticComplexity:
Max: 30
Max: 35
Metrics/PerceivedComplexity:
Max: 40
Layout/EmptyLineAfterGuardClause:
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ chatgpt-translate:
permalink: :year-:month-:day-:slug-chinese.html
layout: chinese-translated
-
only: ru-post
language: fr
permalink: :year-:month-:day-:title-french.html
```
Expand Down Expand Up @@ -112,6 +113,10 @@ If this option is not specified,
* `targets` (mandatory) — an array of target languages, each of
which has the following attributes

* `only` (optional) —
it this is present, only the posts with the provided "layout"
will be translated to this target

* `language` (mandatory) —
[ISO-639-1][iso-639] code of the target language

Expand Down
6 changes: 6 additions & 0 deletions lib/jekyll-chatgpt-translate/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,17 @@ def generate(site)
marker = "Translated by ChatGPT #{model}#{version.empty? ? '' : "/#{version}"}"
site.posts.docs.shuffle.each_with_index do |doc, pos|
plain = GptTranslate::Plain.new(doc.content).to_s
layout = doc['layout']
config['targets'].each do |target|
pstart = Time.now
link = GptTranslate::Permalink.new(doc, target['permalink']).to_path
lang = target['language']
raise 'Language must be defined for each target' if target.nil?
only = target['only']
if !only.nil? && layout != only
Jekyll.logger.debug("Not translating #{link.inspect}, b/c 'only' set to '#{only}'")
next
end
path = File.join(home, lang, doc.basename.gsub(/\.md$/, "-#{lang}.md"))
FileUtils.mkdir_p(File.dirname(path))
File.write(
Expand Down

0 comments on commit e9f33e2

Please sign in to comment.