ZMediumToMarkdown 1.9.5 → 1.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/ZMediumToMarkdown +0 -1
- data/lib/Helper.rb +17 -10
- data/lib/Parsers/CodeBlockParser.rb +10 -2
- data/lib/Parsers/IframeParser.rb +6 -1
- data/lib/Parsers/PREParser.rb +9 -1
- data/lib/Post.rb +2 -1
- data/lib/ZMediumFetcher.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cc121cbe8d2f06e2e6421872ff2f6950addd4affd46fe928172b9848da8e1517
|
|
4
|
+
data.tar.gz: 62e35936912a730a37c2424d6028fd3a780fe41aa0048ed717e81df02910dff2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6e76c68cc1c4f1f56bf35bc6517a0814c8263367f6ebda4e33591dd29667ae597a7a0b6da1ca1485245522e45d1a7dfbe739e9e996c0addb8ffc6d1600b1940b
|
|
7
|
+
data.tar.gz: cfe0bce95d184b67fb1afb2c84407478384b617665162dae9908fda1cfd8ff68094bbde65016b2872eea9d91e5e5987890f04e41e572175712cf0cdfa6210064
|
data/bin/ZMediumToMarkdown
CHANGED
|
@@ -65,7 +65,6 @@ class Main
|
|
|
65
65
|
|
|
66
66
|
opts.on('-v', '--version', 'Print current ZMediumToMarkdown Version & Output Path') do
|
|
67
67
|
puts "Version:#{Helper.getLocalVersion().to_s}"
|
|
68
|
-
puts "Output Path:#{outputFilePath.getAbsolutePath(nil)}"
|
|
69
68
|
|
|
70
69
|
Helper.printNewVersionMessageIfExists()
|
|
71
70
|
end
|
data/lib/Helper.rb
CHANGED
|
@@ -98,7 +98,7 @@ class Helper
|
|
|
98
98
|
end
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
-
def self.createPostInfo(postInfo)
|
|
101
|
+
def self.createPostInfo(postInfo, isForJekyll)
|
|
102
102
|
|
|
103
103
|
title = postInfo.title.gsub("[","")
|
|
104
104
|
title = title.gsub("]","")
|
|
@@ -109,6 +109,10 @@ class Helper
|
|
|
109
109
|
result += "date: #{postInfo.firstPublishedAt.strftime('%Y-%m-%dT%H:%M:%S.%LZ')}\n"
|
|
110
110
|
result += "categories: #{postInfo.collectionName}\n"
|
|
111
111
|
result += "tags: [#{postInfo.tags.join(",")}]\n"
|
|
112
|
+
result += "description: #{postInfo.description}\n"
|
|
113
|
+
if isForJekyll
|
|
114
|
+
result += "render_with_liquid: false\n"
|
|
115
|
+
end
|
|
112
116
|
result += "---\n"
|
|
113
117
|
result += "\r\n"
|
|
114
118
|
|
|
@@ -182,16 +186,19 @@ class Helper
|
|
|
182
186
|
|
|
183
187
|
|
|
184
188
|
def self.createWatermark(postURL)
|
|
185
|
-
text = "
|
|
186
|
-
|
|
187
|
-
text += "\r\n"
|
|
188
|
-
text += "
|
|
189
|
-
text += "
|
|
190
|
-
text += "\r\n"
|
|
191
|
-
text += "
|
|
192
|
-
text += "
|
|
193
|
-
text += "\r\n"
|
|
189
|
+
text = ""
|
|
190
|
+
|
|
191
|
+
# text += "\r\n\r\n\r\n"
|
|
192
|
+
# text += "+-----------------------------------------------------------------------------------+"
|
|
193
|
+
# text += "\r\n"
|
|
194
|
+
# text += "\r\n"
|
|
195
|
+
# text += "| **[View original post on Medium](#{postURL}) - Converted by [ZhgChgLi](https://zhgchg.li)/[ZMediumToMarkdown](https://github.com/ZhgChgLi/ZMediumToMarkdown)** |"
|
|
196
|
+
# text += "\r\n"
|
|
197
|
+
# text += "\r\n"
|
|
198
|
+
# text += "+-----------------------------------------------------------------------------------+"
|
|
199
|
+
# text += "\r\n"
|
|
194
200
|
|
|
201
|
+
# no need to show any watermark :)
|
|
195
202
|
text
|
|
196
203
|
end
|
|
197
204
|
end
|
|
@@ -4,7 +4,11 @@ require "Parsers/Parser"
|
|
|
4
4
|
require 'Models/Paragraph'
|
|
5
5
|
|
|
6
6
|
class CodeBlockParser < Parser
|
|
7
|
-
attr_accessor :nextParser
|
|
7
|
+
attr_accessor :nextParser, :isForJekyll
|
|
8
|
+
|
|
9
|
+
def initialize(isForJekyll)
|
|
10
|
+
@isForJekyll = isForJekyll
|
|
11
|
+
end
|
|
8
12
|
|
|
9
13
|
def self.getTypeString()
|
|
10
14
|
'CODE_BLOCK'
|
|
@@ -20,7 +24,11 @@ class CodeBlockParser < Parser
|
|
|
20
24
|
|
|
21
25
|
def parse(paragraph)
|
|
22
26
|
if CodeBlockParser.isCodeBlock(paragraph)
|
|
23
|
-
"```\n
|
|
27
|
+
result = "```\n"
|
|
28
|
+
|
|
29
|
+
result += paragraph.text.chomp
|
|
30
|
+
|
|
31
|
+
result += "\n```"
|
|
24
32
|
else
|
|
25
33
|
if !nextParser.nil?
|
|
26
34
|
nextParser.parse(paragraph)
|
data/lib/Parsers/IframeParser.rb
CHANGED
|
@@ -74,7 +74,12 @@ class IframeParser < Parser
|
|
|
74
74
|
gistHTML.search('a').each do |a|
|
|
75
75
|
if a.text == 'view raw'
|
|
76
76
|
gistRAW = Request.body(Request.URL(a['href']))
|
|
77
|
-
|
|
77
|
+
|
|
78
|
+
result = "```#{lang}\n"
|
|
79
|
+
|
|
80
|
+
result += gistRAW.chomp
|
|
81
|
+
|
|
82
|
+
result += "\n```"
|
|
78
83
|
end
|
|
79
84
|
end
|
|
80
85
|
else
|
data/lib/Parsers/PREParser.rb
CHANGED
|
@@ -4,7 +4,11 @@ require "Parsers/Parser"
|
|
|
4
4
|
require 'Models/Paragraph'
|
|
5
5
|
|
|
6
6
|
class PREParser < Parser
|
|
7
|
-
attr_accessor :nextParser
|
|
7
|
+
attr_accessor :nextParser, :isForJekyll
|
|
8
|
+
|
|
9
|
+
def initialize(isForJekyll)
|
|
10
|
+
@isForJekyll = isForJekyll
|
|
11
|
+
end
|
|
8
12
|
|
|
9
13
|
def self.isPRE(paragraph)
|
|
10
14
|
if paragraph.nil?
|
|
@@ -17,10 +21,14 @@ class PREParser < Parser
|
|
|
17
21
|
def parse(paragraph)
|
|
18
22
|
if PREParser.isPRE(paragraph)
|
|
19
23
|
result = "```\n"
|
|
24
|
+
|
|
20
25
|
paragraph.text.each_line do |p|
|
|
21
26
|
result += p
|
|
22
27
|
end
|
|
28
|
+
|
|
29
|
+
result = result.chomp
|
|
23
30
|
result += "\n```"
|
|
31
|
+
|
|
24
32
|
result
|
|
25
33
|
else
|
|
26
34
|
if !nextParser.nil?
|
data/lib/Post.rb
CHANGED
|
@@ -9,7 +9,7 @@ require 'date'
|
|
|
9
9
|
class Post
|
|
10
10
|
|
|
11
11
|
class PostInfo
|
|
12
|
-
attr_accessor :title, :tags, :creator, :firstPublishedAt, :latestPublishedAt, :collectionName
|
|
12
|
+
attr_accessor :title, :tags, :creator, :firstPublishedAt, :latestPublishedAt, :collectionName, :description
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def self.getPostIDFromPostURLString(postURLString)
|
|
@@ -60,6 +60,7 @@ class Post
|
|
|
60
60
|
|
|
61
61
|
def self.parsePostInfoFromPostContent(content, postID)
|
|
62
62
|
postInfo = PostInfo.new()
|
|
63
|
+
postInfo.description = content&.dig("Post:#{postID}", "previewContent", "subtitle")
|
|
63
64
|
postInfo.title = content&.dig("Post:#{postID}", "title")
|
|
64
65
|
postInfo.tags = content&.dig("Post:#{postID}", "tags").map{ |tag| tag["__ref"].gsub! 'Tag:', '' }
|
|
65
66
|
|
data/lib/ZMediumFetcher.rb
CHANGED
|
@@ -50,9 +50,9 @@ class ZMediumFetcher
|
|
|
50
50
|
info += "-"
|
|
51
51
|
end
|
|
52
52
|
if !currentPostParagraphIndex.nil? && !totalPostParagraphsLength.nil?
|
|
53
|
-
info += "[#{postPath[0..
|
|
53
|
+
info += "[#{postPath[0..15]}...(#{currentPostParagraphIndex}/#{totalPostParagraphsLength})]"
|
|
54
54
|
else
|
|
55
|
-
info += "[#{postPath[0..
|
|
55
|
+
info += "[#{postPath[0..15]}...]"
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
|
|
@@ -101,9 +101,9 @@ class ZMediumFetcher
|
|
|
101
101
|
iframeParser.setNext(imgParser)
|
|
102
102
|
bqParser = BQParser.new()
|
|
103
103
|
imgParser.setNext(bqParser)
|
|
104
|
-
preParser = PREParser.new()
|
|
104
|
+
preParser = PREParser.new(isForJekyll)
|
|
105
105
|
bqParser.setNext(preParser)
|
|
106
|
-
codeBlockParser = CodeBlockParser.new()
|
|
106
|
+
codeBlockParser = CodeBlockParser.new(isForJekyll)
|
|
107
107
|
preParser.setNext(codeBlockParser)
|
|
108
108
|
fallbackParser = FallbackParser.new()
|
|
109
109
|
codeBlockParser.setNext(fallbackParser)
|
|
@@ -230,7 +230,7 @@ class ZMediumFetcher
|
|
|
230
230
|
absolutePath = postPathPolicy.getAbsolutePath("#{postWithDatePath}.md")
|
|
231
231
|
|
|
232
232
|
# if markdown file is exists and last modification time is >= latestPublishedAt(last update post time on medium)
|
|
233
|
-
if File.file?(absolutePath) && File.mtime(absolutePath) >= postInfo.latestPublishedAt
|
|
233
|
+
if File.file?(absolutePath) && File.mtime(absolutePath).to_time.to_i >= postInfo.latestPublishedAt.to_i
|
|
234
234
|
# Already downloaded and nothing has changed!, Skip!
|
|
235
235
|
progress.currentPostParagraphIndex = paragraphs.length
|
|
236
236
|
progress.message = "Skip, Post already downloaded and nothing has changed!"
|
|
@@ -239,7 +239,7 @@ class ZMediumFetcher
|
|
|
239
239
|
Helper.createDirIfNotExist(postPathPolicy.getAbsolutePath(nil))
|
|
240
240
|
File.open(absolutePath, "w+") do |file|
|
|
241
241
|
# write postInfo into top
|
|
242
|
-
file.puts(Helper.createPostInfo(postInfo))
|
|
242
|
+
file.puts(Helper.createPostInfo(postInfo, isForJekyll))
|
|
243
243
|
|
|
244
244
|
index = 0
|
|
245
245
|
paragraphs.each do |paragraph|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ZMediumToMarkdown
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.9.
|
|
4
|
+
version: 1.9.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ZhgChgLi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-
|
|
11
|
+
date: 2022-07-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: nokogiri
|