Class: GptTranslate::Permalink

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-chatgpt-translate/permalink.rb

Overview

Permalink.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2023-2024 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(doc, template) ⇒ Permalink

Returns a new instance of Permalink.



35
36
37
38
39
# File 'lib/jekyll-chatgpt-translate/permalink.rb', line 35

def initialize(doc, template)
  @doc = doc
  raise 'permalink must be defined for each target' if template.nil?
  @template = template
end

Instance Method Details

#to_pathObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/jekyll-chatgpt-translate/permalink.rb', line 41

def to_path
  path = @template
    .gsub(':year', format('%04d', @doc['date'].year))
    .gsub(':month', format('%02d', @doc['date'].month))
    .gsub(':day', format('%02d', @doc['date'].day))
    .gsub(':title', CGI.escape(@doc['title']))
    .gsub(':slug', CGI.escape(@doc['slug']))
  path = "/#{path}" unless path.start_with?('/')
  path
end