ZMediumToMarkdown 2.0.2 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/Parsers/LinkParser.rb +26 -28
- data/lib/ZMediumFetcher.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d39b14b2d274522cbd880b0673012c40b749e693d706d8f6906e8df4f19d640
|
4
|
+
data.tar.gz: 5225ba58b765a96a4894f28cae5cb1394aca8d92dbce5bb7e8bfa74bbe48aa30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ab477a2f0bb769e53eccc479e3839a7963c98ef97a0d46e51d3bf26f04e8cbd555c4f515d5518dba455754a6e29d20044cc87e60e1ae1a9256d286ebdf455db
|
7
|
+
data.tar.gz: a7ed47c1335ffca2ff33a5a21046c06c5689b6cd4225a4d26854b0ee334eb77aa3c04e5bda8c77d829ad64b55857ccaa14897681859c96a4e6b0dcce1af1b12c
|
data/lib/Parsers/LinkParser.rb
CHANGED
@@ -6,47 +6,45 @@ class LinkParser
|
|
6
6
|
attr_accessor :usersPostURLs, :isForJekyll
|
7
7
|
|
8
8
|
def initialize()
|
9
|
-
@usersPostURLs =
|
9
|
+
@usersPostURLs = []
|
10
10
|
@isForJekyll = false
|
11
11
|
end
|
12
12
|
|
13
|
-
def parse(markdownString
|
14
|
-
|
15
|
-
|
16
|
-
if !matchLinks.nil?
|
13
|
+
def parse(markdownString)
|
14
|
+
matchLinks = markdownString.scan(/\[[^\]]*\]\(([^\)]+)\)/m)
|
15
|
+
if !matchLinks.nil?
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
matchLinks.each do |matchLink|
|
18
|
+
link = matchLink[0]
|
19
|
+
linkMarkdown = "(#{link})"
|
20
|
+
newLinkMarkdown = linkMarkdown
|
21
|
+
|
22
|
+
if isForJekyll
|
23
|
+
newLinkMarkdown = "(#{link}){:target=\"_blank\"}"
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
if !usersPostURLs.nil?
|
28
|
+
# if have provide user's post urls
|
29
|
+
# find & replace medium url to local post url if matched
|
22
30
|
|
23
31
|
if isForJekyll
|
24
|
-
|
32
|
+
postPath = link.split("/").last.split("-").last
|
33
|
+
else
|
34
|
+
postPath = link.split("/").last
|
25
35
|
end
|
26
36
|
|
27
|
-
|
28
|
-
if !usersPostURLs.nil?
|
29
|
-
# if have provide user's post urls
|
30
|
-
# find & replace medium url to local post url if matched
|
31
|
-
|
37
|
+
if !usersPostURLs.find { |usersPostURL| usersPostURL.split("/").last.split("-").last == postPath.split("-").last }.nil?
|
32
38
|
if isForJekyll
|
33
|
-
|
39
|
+
newLinkMarkdown = "(../#{postPath}/)"
|
34
40
|
else
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
if !usersPostURLs.find { |usersPostURL| usersPostURL.split("/").last.split("-").last == postPath.split("-").last }.nil?
|
39
|
-
if isForJekyll
|
40
|
-
newLinkMarkdown = "(../#{postPath})"
|
41
|
-
else
|
42
|
-
newLinkMarkdown = "(#{postPath})"
|
43
|
-
end
|
41
|
+
newLinkMarkdown = "(#{postPath})"
|
44
42
|
end
|
45
43
|
end
|
44
|
+
end
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
end
|
46
|
+
if linkMarkdown != newLinkMarkdown
|
47
|
+
markdownString = markdownString.sub! linkMarkdown, newLinkMarkdown
|
50
48
|
end
|
51
49
|
end
|
52
50
|
end
|
data/lib/ZMediumFetcher.rb
CHANGED
@@ -236,7 +236,7 @@ class ZMediumFetcher
|
|
236
236
|
if lines.first.start_with?("---")
|
237
237
|
dateLine = lines.select { |line| line.start_with?("last_modified_at:") }.first
|
238
238
|
if !dateLine.nil?
|
239
|
-
|
239
|
+
fileLatestPublishedAt = Time.parse(dateLine[/^(last_modified_at:)\s+(\S*)/, 2]).to_i
|
240
240
|
end
|
241
241
|
end
|
242
242
|
end
|
@@ -264,7 +264,7 @@ class ZMediumFetcher
|
|
264
264
|
end
|
265
265
|
|
266
266
|
result = startParser.parse(paragraph)
|
267
|
-
result = linkParser.parse(result
|
267
|
+
result = linkParser.parse(result)
|
268
268
|
|
269
269
|
file.puts(result)
|
270
270
|
|