From d003b278958b2b99ceceee6f3f6767f806fae56d Mon Sep 17 00:00:00 2001 From: zhgchgli Date: Thu, 10 Aug 2023 22:35:12 +0800 Subject: [PATCH] update pinned rule --- ZMediumToMarkdown.gemspec | 2 +- lib/Helper.rb | 1 + lib/ZMediumFetcher.rb | 13 +++++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ZMediumToMarkdown.gemspec b/ZMediumToMarkdown.gemspec index ae1879d..6d586d5 100644 --- a/ZMediumToMarkdown.gemspec +++ b/ZMediumToMarkdown.gemspec @@ -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" diff --git a/lib/Helper.rb b/lib/Helper.rb index 2014658..16b7e11 100644 --- a/lib/Helper.rb +++ b/lib/Helper.rb @@ -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 diff --git a/lib/ZMediumFetcher.rb b/lib/ZMediumFetcher.rb index 111f385..31c8661 100644 --- a/lib/ZMediumFetcher.rb +++ b/lib/ZMediumFetcher.rb @@ -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!"