ZMediumToMarkdown 2.0.2 → 2.0.3
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/lib/Parsers/LinkParser.rb +25 -27
- 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: 2c6540c31739d0b7673b180fa73887641933b08f431346a7aa77e89c5188acb6
|
4
|
+
data.tar.gz: 9cd571bc32f08011d136d6814fadf8afb3ab3bc1251ea1476bc0144b30fc4461
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57162ffcec3607c5fdb654b984593eef97a6badbd1e3ebb8e11bb8be2ea1b7301f17aa51d93fa6d864a2db58bfbb45ceda6b3cade25a2ca633a5eb90d08c5240
|
7
|
+
data.tar.gz: 862072b9c0d384bf1a45f02590b5a0f9286d96ad480b8874670f067e56fc5c66b9c2c33e62f24d799871459504cb807e705d7876576c56f5e9317e80caa0a145
|
data/lib/Parsers/LinkParser.rb
CHANGED
@@ -10,43 +10,41 @@ class LinkParser
|
|
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
|
|