Skip to content

Commit

Permalink
add nil handle
Browse files Browse the repository at this point in the history
  • Loading branch information
zhgchgli0718 committed Mar 17, 2023
1 parent 8854712 commit fc5bbdb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ZMediumToMarkdown.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
gem.files = Dir['lib/**/*.*']
gem.executables = ['ZMediumToMarkdown']
gem.name = 'ZMediumToMarkdown'
gem.version = '2.1.2'
gem.version = '2.1.3'

gem.license = "MIT"

Expand Down
14 changes: 7 additions & 7 deletions lib/Helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,22 @@ def self.downloadLatestVersion()
end

def self.createPostInfo(postInfo, isForJekyll)
title = postInfo.title.gsub("[","")
title = title.gsub("]","")
title = postInfo.title&.gsub("[","")
title = title&.gsub("]","")

tags = ""
if !postInfo.tags.nil? && postInfo.tags.length > 0
tags = "\"#{postInfo.tags.map { |tag| tag.gsub("\"", "\\\"") }.join("\",\"")}\""
tags = "\"#{postInfo.tags.map { |tag| tag&.gsub("\"", "\\\"") }.join("\",\"")}\""
end

result = "---\n"
result += "title: \"#{title.gsub("\"", "\\\"")}\"\n"
result += "author: \"#{postInfo.creator.gsub("\"", "\\\"")}\"\n"
result += "title: \"#{title&.gsub("\"", "\\\"")}\"\n"
result += "author: \"#{postInfo.creator&.gsub("\"", "\\\"")}\"\n"
result += "date: #{postInfo.firstPublishedAt.strftime('%Y-%m-%dT%H:%M:%S.%L%z')}\n"
result += "last_modified_at: #{postInfo.latestPublishedAt.strftime('%Y-%m-%dT%H:%M:%S.%L%z')}\n"
result += "categories: \"#{postInfo.collectionName.gsub("\"", "\\\"")}\"\n"
result += "categories: \"#{postInfo.collectionName&.gsub("\"", "\\\"")}\"\n"
result += "tags: [#{tags}]\n"
result += "description: \"#{postInfo.description.gsub("\"", "\\\"")}\"\n"
result += "description: \"#{postInfo.description&.gsub("\"", "\\\"")}\"\n"
if !postInfo.previewImage.nil?
result += "image:\r\n"
result += " path: #{postInfo.previewImage}\r\n"
Expand Down
2 changes: 1 addition & 1 deletion lib/ZMediumFetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def downloadPost(postURL, pathPolicy)

if File.file?(absolutePath)
lines = File.foreach(absolutePath).first(15)
if lines.first.start_with?("---")
if lines.first&.start_with?("---")
dateLine = lines.select { |line| line.start_with?("last_modified_at:") }.first
if !dateLine.nil?
fileLatestPublishedAt = Time.parse(dateLine[/^(last_modified_at:)\s+(\S*)/, 2]).to_i
Expand Down

0 comments on commit fc5bbdb

Please sign in to comment.