ZMediumToMarkdown 1.6.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6026b5ebd732b82696ca5a7de549e5167067336998152c8a5e7bed751d610b78
4
- data.tar.gz: 76c24779eaceb1763225f6e5e274fb5177685b0be9f75390ce189ec047278c21
3
+ metadata.gz: 92b412153da4daf0a7594c1558a847412863405eec14da02325984a22bc855a8
4
+ data.tar.gz: ccdf1c0e166323323f55b91fc0991b3eae1da0ad070e2b884b3b30266661c03b
5
5
  SHA512:
6
- metadata.gz: db56b44ece9656eb90f703a6416c54a163f54e0208981ebf37029af9491fb39e30252b564e5d63f6defc63c72c51f3c3f944f531dfbd77ed10ba06b59abbd511
7
- data.tar.gz: b71cc148ded49d5e3bd1ab8e72d915a5b8716de041cba43d39158fd47f451ce4c52ad0d671462a3dca7571879c744fa029b0af7a7e45d2fea92788d5ee858f0b
6
+ metadata.gz: 120c75b800992a2a815c058430326f6b279f52f08ba4484465fdf7eca31b8460f1170bdd30956c1bfd771a3fbb0d5763a21e9327530e80e76250d52551a4ec9f
7
+ data.tar.gz: ffb13239eabe2a6f302a093dfea6309eaaaa3eee0ffb960ee9798f96969c922de6a287b3c8ac47aca1c8b4af2f51adcc52bdf2470e59f8cf12420338a03e019b
data/lib/Helper.rb CHANGED
@@ -77,10 +77,15 @@ class Helper
77
77
  end
78
78
 
79
79
  def self.createPostInfo(postInfo)
80
+
81
+ title = postInfo.title.gsub("[","")
82
+ title = title.gsub("]","")
83
+
80
84
  result = "---\n"
81
- result += "title: #{postInfo.title}\n"
85
+ result += "title: #{title}\n"
82
86
  result += "author: #{postInfo.creator}\n"
83
87
  result += "date: #{postInfo.firstPublishedAt.strftime('%Y-%m-%dT%H:%M:%S.%LZ')}\n"
88
+ result += "categories: #{postInfo.collectionName}\n"
84
89
  result += "tags: [#{postInfo.tags.join(",")}]\n"
85
90
  result += "---\n"
86
91
  result += "\r\n"
@@ -18,11 +18,16 @@ class IMGParser < Parser
18
18
  imagePathPolicy = PathPolicy.new(pathPolicy.getAbsolutePath(nil), paragraph.postID)
19
19
  absolutePath = imagePathPolicy.getAbsolutePath(fileName)
20
20
 
21
+ comment = ""
22
+ if paragraph.text != ""
23
+ comment = " \"#{paragraph.text}\""
24
+ end
25
+
21
26
  if ImageDownloader.download(absolutePath, imageURL)
22
27
  relativePath = "#{pathPolicy.getRelativePath(nil)}/#{imagePathPolicy.getRelativePath(fileName)}"
23
- "![#{paragraph.text}](#{relativePath} \"#{paragraph.text}\")"
28
+ "![#{paragraph.text}](/#{relativePath}#{comment})"
24
29
  else
25
- "![#{paragraph.text}](#{imageURL} \"#{paragraph.text}\")"
30
+ "![#{paragraph.text}](#{imageURL}#{comment})"
26
31
  end
27
32
  else
28
33
  if !nextParser.nil?
@@ -55,7 +55,7 @@ class IframeParser < Parser
55
55
  gistHTML.search('a').each do |a|
56
56
  if a.text == 'view raw'
57
57
  gistRAW = Request.body(Request.URL(a['href']))
58
- result = "```#{lang}\n#{gistRAW}\n```"
58
+ result = "```#{lang.downcase}\n#{gistRAW}\n```"
59
59
  end
60
60
  end
61
61
  end
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
12
+ attr_accessor :title, :tags, :creator, :firstPublishedAt, :latestPublishedAt, :collectionName
13
13
  end
14
14
 
15
15
  def self.getPostIDFromPostURLString(postURLString)
@@ -68,6 +68,13 @@ class Post
68
68
  postInfo.creator = content&.dig(creatorRef, "name")
69
69
  end
70
70
 
71
+ colletionRef = content&.dig("Post:#{postID}", "collection", "__ref")
72
+ if !colletionRef.nil?
73
+ postInfo.collectionName = content&.dig(colletionRef, "name")
74
+ end
75
+
76
+
77
+
71
78
  firstPublishedAt = content&.dig("Post:#{postID}", "firstPublishedAt")
72
79
  if !firstPublishedAt.nil?
73
80
  postInfo.firstPublishedAt = Time.at(0, firstPublishedAt, :millisecond)
@@ -26,6 +26,7 @@ require "PathPolicy"
26
26
  require "Request"
27
27
  require "Post"
28
28
  require "User"
29
+ require 'date'
29
30
 
30
31
  class ZMediumFetcher
31
32
 
@@ -204,7 +205,7 @@ class ZMediumFetcher
204
205
 
205
206
  postPathPolicy = PathPolicy.new(pathPolicy.getAbsolutePath(nil), "posts")
206
207
 
207
- imagePathPolicy = PathPolicy.new(postPathPolicy.getAbsolutePath(nil), "images")
208
+ imagePathPolicy = PathPolicy.new(postPathPolicy.getAbsolutePath(nil), "assets")
208
209
  startParser = buildParser(imagePathPolicy)
209
210
 
210
211
  progress.totalPostParagraphsLength = paragraphs.length
@@ -212,7 +213,9 @@ class ZMediumFetcher
212
213
  progress.message = "Converting Post..."
213
214
  progress.printLog()
214
215
 
215
- absolutePath = postPathPolicy.getAbsolutePath("#{postPath}.md")
216
+ postWithDatePath = "#{postInfo.firstPublishedAt.strftime("%Y-%m-%d")}-#{postPath}"
217
+
218
+ absolutePath = postPathPolicy.getAbsolutePath("#{postWithDatePath}.md")
216
219
 
217
220
  # if markdown file is exists and last modification time is >= latestPublishedAt(last update post time on medium)
218
221
  if File.file?(absolutePath) && File.mtime(absolutePath) >= postInfo.latestPublishedAt
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.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZhgChgLi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-06 00:00:00.000000000 Z
11
+ date: 2022-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri