38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/jekyll-import/importers/dotclear.rb', line 38
def self.process(opts)
options = {
:datafile => opts.fetch("datafile", ""),
:mediafolder => opts.fetch("mediafolder", ""),
}
FileUtils.mkdir_p("_posts")
FileUtils.mkdir_p("_drafts")
type_data = ""
= {}
posts_and_drafts = {}
keywords = {}
File.readlines(options[:datafile]).each do |lineraw|
line = lineraw.strip.gsub(%r!\n$!, "")
next if line.empty?
if line.start_with?("[") type_data = line.split(" ").first[1..-1]
[type_data] = (line)
next
end
elts = (line)
if type_data == "post"
draft = (elts[[type_data].index("post_status")] != "1")
date_str = elts[[type_data].index("post_creadt")]
date_blank = (date_str.nil? || date_str.empty?)
date_str_formatted = date_blank ? Date.today : Date.parse(date_str).strftime("%Y-%m-%d")
title_param = elts[[type_data].index("post_title")].to_s.parameterize
content = elts[[type_data].index("post_content_xhtml")].to_s
content = content.gsub('\"', '"').gsub('\n', "\n").gsub("/public/", "/assets/images/")
filepath = File.join(Dir.pwd, (draft ? "_drafts" : "_posts"), "#{date_str_formatted}-#{title_param}.html")
entire_content_file = <<~POST_FILE
---
layout: post
title: "#{elts[[type_data].index("post_title")]}"
date: #{elts[[type_data].index("post_creadt")]} +0100
tags: ABC
---
#{content}
POST_FILE
posts_and_drafts[elts[[type_data].index("post_id")]] = { :path => filepath, :content => entire_content_file }
elsif type_data == "media"
elts[[type_data].index("media_title")]
mediafilepath = elts[[type_data].index("media_file")]
src_path = File.join(options[:mediafolder], mediafilepath)
dst_path = File.join(Dir.pwd, "assets", "images", mediafilepath.to_s)
FileUtils.mkdir_p(File.dirname(dst_path))
FileUtils.cp(src_path, dst_path)
elsif type_data == "meta"
keywords[elts[[type_data].index("post_id")]] ||= []
keywords[elts[[type_data].index("post_id")]] << elts[[type_data].index("meta_id")]
elsif type_data == "link"
elsif type_data == "setting"
elsif type_data == "comment"
end
end
posts_and_drafts.each do |post_id, hsh|
keywords_str = keywords[post_id].to_a.join(", ")
content_file = hsh[:content]
content_file = content_file.gsub("tags: ABC", "tags: [#{keywords_str}]")
File.open(hsh[:path], "wb") do |f|
f.write(content_file)
end
end
end
|