Skip to content

Commit

Permalink
update pinned rule
Browse files Browse the repository at this point in the history
  • Loading branch information
zhgchgli0718 committed Aug 10, 2023
1 parent 7fd5d5b commit d003b27
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 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.3.0'
gem.version = '2.3.1'

gem.license = "MIT"

Expand Down
1 change: 1 addition & 0 deletions lib/Helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def self.createPostInfo(postInfo, isForJekyll)
end
if !postInfo.pinnedByCreatorAt.nil? && pinnedByCreatorAt > 0
result += "pin: true\r\n"
result += "pinned_at: #{postInfo.pinnedByCreatorAt.strftime('%Y-%m-%dT%H:%M:%S.%L%z')}\n"
end

if isForJekyll
Expand Down
13 changes: 9 additions & 4 deletions lib/ZMediumFetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,23 @@ def downloadPost(postURL, pathPolicy)
absolutePath = URI.decode(postPathPolicy.getAbsolutePath("#{postWithDatePath}")) + ".md"

fileLatestPublishedAt = nil

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

pinnedByCreatorAtLine = lines.select { |line| line.start_with?("pinned_at:") }.first
if !dateLine.nil?
fileLatestPublishedAt = Time.parse(dateLine[/^(last_modified_at:)\s+(\S*)/, 2]).to_i
filePinnedByCreatorAt = Time.parse(pinnedByCreatorAtLine[/^(pinned_at:)\s+(\S*)/, 2]).to_i
end
end
end

if !fileLatestPublishedAt.nil? && fileLatestPublishedAt >= postInfo.latestPublishedAt.to_i
if (!fileLatestPublishedAt.nil? && fileLatestPublishedAt >= postInfo.latestPublishedAt.to_i) && filePinnedByCreatorAt == postInfo.pinnedByCreatorAt.to_i
# Already downloaded and nothing has changed!, Skip!
progress.currentPostParagraphIndex = paragraphs.length
progress.message = "Skip, Post already downloaded and nothing has changed!"
Expand Down

0 comments on commit d003b27

Please sign in to comment.