md2site 0.1.2 → 0.1.4
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/.rubocop.yml +2 -19
- data/Gemfile +1 -1
- data/Gemfile.lock +21 -28
- data/bin/md2site +26 -31
- data/data/_x/diff.txt +337 -0
- data/data/_x/list.txt +495 -0
- data/data/_x/list2.txt +495 -0
- data/data/_x/list3.txt +415 -0
- data/data/_x/list4.txt +415 -0
- data/data/_x/list5.txt +392 -0
- data/data/_x/list6.txt +298 -0
- data/data/_x/list7.txt +201 -0
- data/data/_x/list8.txt +199 -0
- data/data/_x/outer_url.txt +94 -0
- data/data/_x/s.txt +140 -0
- data/data/conf/conf.sh +0 -2
- data/data/testdata/{conf-blog.yml → conf/conf-blog.yml} +0 -0
- data/data/testdata/{conf-download.yml → conf/conf-download.yml} +0 -0
- data/data/testdata/{conf-link.yml → conf/conf-link.yml} +0 -0
- data/data/testdata/{conf-profile.yml → conf/conf-profile.yml} +0 -0
- data/data/testdata/{conf-top.yml → conf/conf-top.yml} +0 -0
- data/data/testdata/{site.tsv → conf/site.tsv} +0 -0
- data/data/testdata0/{conf-appliction.yml → conf/conf-appliction.yml} +0 -0
- data/data/testdata0/{conf-attempt.yml → conf/conf-attempt.yml} +16 -16
- data/data/testdata0/conf/conf-autosar.yml +11 -0
- data/data/testdata0/{conf-community.yml → conf/conf-community.yml} +0 -0
- data/data/testdata0/{conf-document.yml → conf/conf-document.yml} +0 -0
- data/data/testdata0/{conf-download.yml → conf/conf-download.yml} +0 -0
- data/data/testdata0/{conf-edu.yml → conf/conf-edu.yml} +18 -19
- data/data/testdata0/{conf-etc.yml → conf/conf-etc.yml} +0 -0
- data/data/testdata0/{conf-members.yml → conf/conf-members.yml} +0 -0
- data/data/testdata0/{conf-product.yml → conf/conf-product.yml} +9 -9
- data/data/testdata0/{conf-project.yml → conf/conf-project.yml} +2 -2
- data/data/testdata0/conf/conf-rtk.yml +25 -0
- data/data/testdata0/conf/conf-sample.yml +5 -0
- data/data/testdata0/{conf-top.yml → conf/conf-top.yml} +0 -0
- data/data/testdata0/conf/conf.sh +32 -0
- data/data/testdata0/{setting.yml → conf/setting.yml} +11 -0
- data/data/testdata0/{site.tsv → conf/site.tsv} +109 -2
- data/data/testdata0/conf/status.txt +6 -0
- data/lib/md2site/env.rb +248 -276
- data/lib/md2site/envcheck.rb +186 -0
- data/lib/md2site/htmlutils0.rb +64 -2
- data/lib/md2site/info.rb +12 -0
- data/lib/md2site/init.rb +61 -5
- data/lib/md2site/listfile.rb +16 -0
- data/lib/md2site/make.rb +92 -31
- data/lib/md2site/nkfguess.rb +8 -0
- data/lib/md2site/setup.rb +104 -28
- data/lib/md2site/statusfile.rb +98 -6
- data/lib/md2site/testdata.rb +43 -3
- data/lib/md2site/testx.rb +28 -1
- data/lib/md2site/version.rb +1 -1
- data/lib/md2site.rb +93 -26
- data/md2site.gemspec +5 -6
- metadata +77 -76
- data/data/testdata0/conf-autosar.yml +0 -11
- data/data/testdata0/conf-rtk.yml +0 -25
data/lib/md2site/make.rb
CHANGED
@@ -5,6 +5,7 @@ module Md2site
|
|
5
5
|
class Make
|
6
6
|
#
|
7
7
|
# 初期化
|
8
|
+
#
|
8
9
|
# @param env [Env] Envクラスのインスタンス
|
9
10
|
# @param mes [Messagex] Messagexクラスのインスタンス
|
10
11
|
# @param verbose [Boolean] FileUtilsクラスのメソッドのverbose引数に与える値
|
@@ -24,8 +25,10 @@ module Md2site
|
|
24
25
|
|
25
26
|
#
|
26
27
|
# 引数optionでの指定に従いサブコマンドを実行
|
28
|
+
#
|
27
29
|
# @param target_command [String] ターゲットコマンド名
|
28
30
|
# @param subtarget_command [String] サブターゲットコマンド名
|
31
|
+
# @return [void]
|
29
32
|
def execute_subcommand(target_command, subtarget_command)
|
30
33
|
if subtarget_command == SUB_TARGET_COMMAND_OF_ALL
|
31
34
|
do_multiple_commands(target_command)
|
@@ -36,11 +39,13 @@ module Md2site
|
|
36
39
|
|
37
40
|
#
|
38
41
|
# 指定ターゲットコマンドに属する全サブターゲットコマンドを順次実行する
|
42
|
+
#
|
39
43
|
# @param target_command [String] ターゲットコマンド名
|
44
|
+
# @return [void]
|
40
45
|
def do_multiple_commands(target_command)
|
41
|
-
|
42
|
-
if !
|
43
|
-
|
46
|
+
subtarget_command_names = @env.get_subtarget_commands(target_command)
|
47
|
+
if !subtarget_command_names.empty?
|
48
|
+
subtarget_command_names.map do |subtarget_command|
|
44
49
|
@mes.output_info("#{target_command} #{subtarget_command}")
|
45
50
|
do_single_command(target_command, subtarget_command)
|
46
51
|
end
|
@@ -54,8 +59,10 @@ module Md2site
|
|
54
59
|
|
55
60
|
#
|
56
61
|
# ターゲットコマンド名、サブターゲットコマンド名の組み合わせを実行する
|
62
|
+
#
|
57
63
|
# @param target_command [String] ターゲットコマンド名
|
58
64
|
# @param subtarget_command [String] サブターゲットコマンド名
|
65
|
+
# @return [void]
|
59
66
|
def do_single_command(target_command, subtarget_command)
|
60
67
|
target, subtarget = @env.get_target_and_subtarget(target_command, subtarget_command)
|
61
68
|
@mes.output_info(%Q(target=#{target}))
|
@@ -75,6 +82,7 @@ module Md2site
|
|
75
82
|
|
76
83
|
#
|
77
84
|
# 指定パスが有効なファイルであるか調べる
|
85
|
+
#
|
78
86
|
# @param fname [String] ファイルのパス
|
79
87
|
# @return [Boolean] true:有効なファイルパスである false:有効なファイルパスでない
|
80
88
|
def check_valid_src_file(fname)
|
@@ -93,8 +101,10 @@ module Md2site
|
|
93
101
|
|
94
102
|
#
|
95
103
|
# eRubyスクリプトを用いてMarkdown形式ファイルを生成
|
104
|
+
#
|
96
105
|
# @param target_struct [Struct] ターゲットストラクト
|
97
106
|
# @param template_struct [Struct] テンプレートストラクト
|
107
|
+
# @return [void]
|
98
108
|
def execute_single_command_for_template(target_struct, template_struct)
|
99
109
|
# 既存のファイルを読み込む
|
100
110
|
if template_struct.kind == :INCLUDE
|
@@ -114,8 +124,10 @@ module Md2site
|
|
114
124
|
|
115
125
|
#
|
116
126
|
# Markdown形式ファイルをeRubyスクリプトを用いて
|
127
|
+
#
|
117
128
|
# @param target_struct [Struct] ターゲットストラクト
|
118
129
|
# @param subtarget_struct [Struct] サブターゲットストラクト
|
130
|
+
# @return [void]
|
119
131
|
def execute_single_command(target_struct, subtarget_struct)
|
120
132
|
# 設定されていれば、全テンプレートストラクトに対して、テンプレートを用いてMarkdown形式ファイルを生成
|
121
133
|
unless subtarget_struct.templates.empty?
|
@@ -147,12 +159,13 @@ module Md2site
|
|
147
159
|
|
148
160
|
#
|
149
161
|
# サブターゲットでエイリアスが指定されていれば、エイリアスを生成するサブターゲットを得る
|
162
|
+
#
|
150
163
|
# @param target_struct [Struct] ターゲットストラクト
|
151
164
|
# @param subtarget_struct [Struct] サブターゲットストラクト
|
152
165
|
# @return [Struct] 有効なサブターゲットストラクト
|
153
166
|
def get_effective_subtarget(target_struct, subtarget_struct)
|
154
167
|
if subtarget_struct.aliashtmldir == ""
|
155
|
-
if subtarget_struct.aliashtmlfile
|
168
|
+
if subtarget_struct.aliashtmlfile.empty?
|
156
169
|
htmlfpath = nil
|
157
170
|
else
|
158
171
|
htmlfpath = subtarget_struct.aliashtmlfile
|
@@ -172,9 +185,11 @@ module Md2site
|
|
172
185
|
|
173
186
|
#
|
174
187
|
# 指定されたパートに対応するHTMLファイルパスを得る
|
188
|
+
#
|
175
189
|
# @param target_struct [Struct] ターゲットストラクト
|
176
190
|
# @param subtarget_struct [Struct] サブターゲットストラクト
|
177
191
|
# @param kind [Symbol] :partA パートA :partB パートB
|
192
|
+
# @return [String] 指定されたパートに対応するHTMLファイルパス
|
178
193
|
def get_part_html(target_struct, subtarget_struct, kind)
|
179
194
|
subtarget_x = get_effective_subtarget(target_struct, subtarget_struct)
|
180
195
|
|
@@ -189,6 +204,16 @@ module Md2site
|
|
189
204
|
path
|
190
205
|
end
|
191
206
|
|
207
|
+
#
|
208
|
+
# Markdown形式ファイルの生成
|
209
|
+
#
|
210
|
+
# @param src_dir [String] 読込元ディレクトリ
|
211
|
+
# @param datafile [String] データファイル名
|
212
|
+
# @param outputfile [String] 出力ファイル名
|
213
|
+
# @param dataop [Symbol] データ操作種類
|
214
|
+
# @param templatefile [String] Markdown形成用eRubyスクリプトファイル名
|
215
|
+
# @param auxhs [Hash] 補助的置換用ハッシュ
|
216
|
+
# @return [void]
|
192
217
|
def command_make_md(src_dir, datafile, outputfile, dataop, templatefile, auxhs={})
|
193
218
|
@mes.output_info(%Q!command_make_md(#{datafile}, #{outputfile}, #{dataop}, #{templatefile}, #{auxhs}!)
|
194
219
|
if src_dir
|
@@ -196,9 +221,9 @@ module Md2site
|
|
196
221
|
outputfile = File.join(src_dir, outputfile) if outputfile
|
197
222
|
end
|
198
223
|
optsx = {}
|
199
|
-
optsx[
|
200
|
-
optsx[
|
201
|
-
optsx[
|
224
|
+
optsx[:data] = datafile
|
225
|
+
optsx[:output] = outputfile
|
226
|
+
optsx[:dataop] = dataop
|
202
227
|
|
203
228
|
mmt = Mdextab::Makemdtab.new(optsx, @str_variable, @str_static, @obj_by_yaml, @mes)
|
204
229
|
if templatefile
|
@@ -215,6 +240,13 @@ module Md2site
|
|
215
240
|
mmt.post_process
|
216
241
|
end
|
217
242
|
|
243
|
+
#
|
244
|
+
# Markdown形式ファイルからHTMLファイルへ変換
|
245
|
+
#
|
246
|
+
# @param inputmd [String] 入力Markdown形式ファイル
|
247
|
+
# @param output_htmlfname [String] 出力HTMLファイル
|
248
|
+
# @return [Boolean] true:成功 false:失敗
|
249
|
+
# @note 変換はpandocを利用するため、pandocがインストールされていることが前提である
|
218
250
|
def simple_md2html(inputmd, output_htmlfname)
|
219
251
|
@mes.output_info(%Q(pandoc -o #{output_htmlfname} -t html5 #{inputmd}))
|
220
252
|
ret = false
|
@@ -235,29 +267,47 @@ module Md2site
|
|
235
267
|
ret
|
236
268
|
end
|
237
269
|
|
238
|
-
|
270
|
+
#
|
271
|
+
# 3つの部分から1つの完結したHTMLファイルを作成
|
272
|
+
#
|
273
|
+
# @param out_htmlfname [String] 出力HTMLファイル
|
274
|
+
# @param mode [String] 出力ファイルオープン時のモード指定
|
275
|
+
# @param part_a [String] HTMLファイルの先頭部
|
276
|
+
# @param content [String] HTMLファイルの中間部
|
277
|
+
# @param part_b [String] HTMLファイルの末尾部
|
278
|
+
# @return [void]
|
279
|
+
def output_html(out_htmlfname, mode, part_a, content, part_b)
|
239
280
|
File.open(out_htmlfname, mode) do |f|
|
240
|
-
f.write(
|
281
|
+
f.write(part_a)
|
241
282
|
f.write(content)
|
242
|
-
f.write(
|
283
|
+
f.write(part_b)
|
243
284
|
end
|
244
285
|
end
|
245
286
|
|
246
|
-
|
287
|
+
#
|
288
|
+
# テーブル拡張Makrdown形式ファイルからら1つの完結したHTMLファイルを作成(ファイルが見つからなかったり、
|
289
|
+
# 出力に失敗すればexitする)
|
290
|
+
#
|
291
|
+
# @param inputmd [String] 入力Makrdown形式ファイル名
|
292
|
+
# @param out_htmlfname [String] 出力HTMLファイル名
|
293
|
+
# @param part_a [String] HTMLファイルの先頭部
|
294
|
+
# @param part_b [String] HTMLファイルの末尾部
|
295
|
+
# @return [void]
|
296
|
+
def md2html(inputmd, out_htmlfname, part_a, part_b)
|
247
297
|
tmpdir = File.dirname(out_htmlfname)
|
248
298
|
tmpbasename = File.basename(out_htmlfname)
|
249
299
|
|
250
300
|
content_htmlfname = File.join(tmpdir, tmpbasename + ".tmp")
|
251
|
-
unless
|
252
|
-
@mes.output_fatal("Can't find file(=#{
|
301
|
+
unless inputmd
|
302
|
+
@mes.output_fatal("Can't find file(=#{inputmd}")
|
253
303
|
exit(@mes.ec("EXIT_CODE_CANNOT_FIND_FILE"))
|
254
304
|
end
|
255
|
-
@mes.output_debug("
|
305
|
+
@mes.output_debug("inputmd=#{inputmd}")
|
256
306
|
@mes.output_debug("content_htmlfname=#{content_htmlfname}")
|
257
|
-
ret = simple_md2html(
|
307
|
+
ret = simple_md2html(inputmd, content_htmlfname)
|
258
308
|
return unless ret
|
259
309
|
|
260
|
-
ret = simple_md2html(
|
310
|
+
ret = simple_md2html(inputmd, "x.html")
|
261
311
|
unless ret
|
262
312
|
tmpf.close(true)
|
263
313
|
return
|
@@ -266,30 +316,41 @@ module Md2site
|
|
266
316
|
content = ""
|
267
317
|
@mes.exc_file_read(content_htmlfname) { content = File.readlines(content_htmlfname).join }
|
268
318
|
@mes.output_debug("file_read #{content_htmlfname}")
|
269
|
-
|
270
|
-
@mes.exc_file_write(out_htmlfname) { output_html(out_htmlfname, "w", parta, content, partb) }
|
319
|
+
@mes.exc_file_write(out_htmlfname) { output_html(out_htmlfname, "w", part_a, content, part_b) }
|
271
320
|
@mes.output_debug("file_write #{out_htmlfname}")
|
272
|
-
# File.unlink(content_htmlfname)
|
273
321
|
end
|
274
322
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
323
|
+
#
|
324
|
+
# Markdown形式ファイルの生成
|
325
|
+
#
|
326
|
+
# @param root_dir [String,nil] nilでなければルートディレクトリ
|
327
|
+
# @param inputfile_md [String] テーブル拡張Markdown形式ファイル名
|
328
|
+
# @param root_output_md [String] Markdown形式ファイル名(テーブル拡張をHTMLのTABLEタグに変換したもの)
|
329
|
+
# @param parta_html [String] HTMLファイルの先頭部ファイル
|
330
|
+
# @param partb_html [String] HTMLファイルの末尾部ファイル
|
331
|
+
# @param out_htmlfname [String] データファイル名
|
332
|
+
# @return [void]
|
333
|
+
def command_make_html(root_dir, inputfile_md, root_output_md, parta_html, partb_html, out_htmlfname)
|
334
|
+
@mes.output_info(%Q!command_makehtml(#{inputfile_md}, #{root_output_md}, #{parta_html} #{partb_html} #{out_htmlfname}!)
|
335
|
+
# ルートディレクトリが指定されていれば、引数の全てのファイルのパスを指定ルートディレクトリをその下に置く
|
336
|
+
if root_dir
|
337
|
+
inputfile_md = File.join(root_dir, inputfile_md) if inputfile_md
|
338
|
+
root_output_md = File.join(root_dir, root_output_md) if root_output_md
|
339
|
+
parta_html = File.join(root_dir, parta_html) if parta_html
|
340
|
+
partb_html = File.join(root_dir, partb_html) if partb_html
|
341
|
+
out_htmlfname = File.join(root_dir, out_htmlfname) if out_htmlfname
|
283
342
|
end
|
284
343
|
|
344
|
+
# テーブル拡張Markdown形式ファイルからMarkdown形式ファイル(HTMLのTABLEタグに変換)を生成する
|
285
345
|
optsx = {}
|
286
|
-
m = Mdextab::Mdextab.new(optsx,
|
346
|
+
m = Mdextab::Mdextab.new(optsx, inputfile_md, root_output_md, @mes)
|
287
347
|
m.parse(@obj_by_yaml)
|
288
348
|
m.post_process
|
289
349
|
|
350
|
+
# Markdown形式ファイルから1個のHTMLファイルを生成
|
290
351
|
parta = Filex::Filex.check_and_load_file(parta_html, @mes)
|
291
|
-
|
292
|
-
md2html(root_output_md, out_htmlfname, parta,
|
352
|
+
partb = Filex::Filex.check_and_load_file(partb_html, @mes)
|
353
|
+
md2html(root_output_md, out_htmlfname, parta, partb)
|
293
354
|
end
|
294
355
|
end
|
295
|
-
end
|
356
|
+
end
|
data/lib/md2site/nkfguess.rb
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
module Md2site
|
2
|
+
#
|
3
|
+
# NKF利用のエンコーディング推測モジュール
|
2
4
|
module Nkfguess
|
3
5
|
require "nkf"
|
4
6
|
|
7
|
+
#
|
8
|
+
# エンコーディング推測
|
9
|
+
#
|
10
|
+
# @param fname [String] エンコーディング推測対象ファイル名
|
11
|
+
# @param mes [Messagex] Messagexクラスのインスタンス
|
12
|
+
# @return [String] "ISO-2022-JP", "eucJP", "CP932", "UTF-8", "ASCII-8BIT"
|
5
13
|
def self.guess_file(fname, mes)
|
6
14
|
str = nil
|
7
15
|
mes.exc_file_read(fname) { File.open(fname) {|f| str = f.gets(nil) } }
|
data/lib/md2site/setup.rb
CHANGED
@@ -20,13 +20,13 @@ module Md2site
|
|
20
20
|
|
21
21
|
#
|
22
22
|
# 初期化
|
23
|
-
#
|
23
|
+
#
|
24
|
+
# @param env [Env] 環境クラスのメソッド
|
24
25
|
# @param mes [Messagex] Messagexクラスのインスタンス
|
25
26
|
def initialize(env, mes)
|
26
27
|
@env = env
|
27
28
|
@mes = mes
|
28
|
-
@
|
29
|
-
@category_x = @env.category_x
|
29
|
+
@category_target = @env.category_target
|
30
30
|
absolute_path_status_file = env.conf_hs["ABSOLUTE_PATH_STATUS_FILE"]
|
31
31
|
@url = @env.conf_hs["URL"]
|
32
32
|
@res = {}
|
@@ -36,12 +36,14 @@ module Md2site
|
|
36
36
|
@mes.add_exitcode("EXIT_CODE_CANNOT_FIND_DEST_DIR")
|
37
37
|
@mes.add_exitcode("EXIT_CODE_CANNOT_CONVERT_FROM_HTML_TO_MD")
|
38
38
|
@mes.add_exitcode("EXIT_CODE_PANDOC_EXIT_ABNORMALLY")
|
39
|
-
@status_file = StatusFile.new(absolute_path_status_file, @url, @mes)
|
39
|
+
@status_file = StatusFile.new(absolute_path_status_file, @env.absolutepath_root, @url, @mes)
|
40
40
|
end
|
41
41
|
|
42
42
|
#
|
43
43
|
# サブコマンド実行
|
44
|
+
#
|
44
45
|
# @param option [String] サブコマンドのオプション
|
46
|
+
# @return [void]
|
45
47
|
def execute_subcommand(option)
|
46
48
|
case option.name
|
47
49
|
when "contentUpdate"
|
@@ -67,6 +69,7 @@ module Md2site
|
|
67
69
|
|
68
70
|
#
|
69
71
|
# リモートサイトのファイル取得
|
72
|
+
#
|
70
73
|
# @param url [String] 取得先URL
|
71
74
|
# @return [Array] 第0要素:Datetime 第1要素:UNIXタイム 第2要素:HTTPボディ
|
72
75
|
def get_remote_file(url)
|
@@ -82,6 +85,7 @@ module Md2site
|
|
82
85
|
|
83
86
|
#
|
84
87
|
# HTTPヘッダの指定フィールドの値を文字列とUNITタイムで取得する
|
88
|
+
#
|
85
89
|
# @param headers [Hash] HTTPヘッダを表すハッシュ
|
86
90
|
# @param key [String] HTTPヘッダのフィールドを指定するキー
|
87
91
|
# @return [Array] 第0要素: 指定フィールドの値(String) 第1要素: 指定フィールドの値(UNIXタイム)
|
@@ -113,6 +117,7 @@ module Md2site
|
|
113
117
|
|
114
118
|
#
|
115
119
|
# HTTPヘッダのlast-modifiedフィールドの値を文字列とUNITタイムで取得
|
120
|
+
#
|
116
121
|
# @param headers [Hash] HTTPヘッダを表すハッシュ
|
117
122
|
# @return [Array] 第0要素: 指定フィールドの値(String) 第1要素: 指定フィールドの値(UNIXタイム)
|
118
123
|
def get_modified_in_datetime_from_header(headers)
|
@@ -121,6 +126,7 @@ module Md2site
|
|
121
126
|
|
122
127
|
#
|
123
128
|
# HTTPヘッダのdateフィールドの値を文字列とUNITタイムで取得
|
129
|
+
#
|
124
130
|
# @param headers [Hash] HTTPヘッダを表すハッシュ
|
125
131
|
# @return [Array] 第0要素: 指定フィールドの値(String) 第1要素: 指定フィールドの値(UNIXタイム)
|
126
132
|
def get_date_in_datetime_from_header(headers)
|
@@ -129,6 +135,7 @@ module Md2site
|
|
129
135
|
|
130
136
|
#
|
131
137
|
# HTTPヘッダから時刻を表すlast-modifiedフィールドまたはdateフィールのの値を文字列とUNIXタイムで取得
|
138
|
+
#
|
132
139
|
# @param headers [Hash] HTTPヘッダを表すハッシュ
|
133
140
|
# @return [Array] 第0要素: 指定フィールドの値(String) 第1要素: 指定フィールドの値(UNIXタイム)
|
134
141
|
def get_modified_in_datetime_or_date_in_datetime_from_header(headers)
|
@@ -141,6 +148,7 @@ module Md2site
|
|
141
148
|
|
142
149
|
#
|
143
150
|
# 指定URLのHTTPヘッダから時刻を表すlast-modifiedフィールドまたはdateフィールのの値を文字列とUNIXタイムで取得
|
151
|
+
#
|
144
152
|
# @param url [String] HTTPヘッダを取得したいURL
|
145
153
|
# @return [Array] 第0要素: 指定フィールドの値(String) 第1要素: 指定フィールドの値(UNIXタイム)
|
146
154
|
def get_modified_in_datetime_or_date_in_datetime(url)
|
@@ -155,6 +163,7 @@ module Md2site
|
|
155
163
|
|
156
164
|
#
|
157
165
|
# 時刻を"年月日-時分秒"の形式の文字列にする
|
166
|
+
#
|
158
167
|
# @param datetime [Datetime] Datetimeクラスのインスタンス
|
159
168
|
# @return [String] "年月日-時分秒"の形式の文字列
|
160
169
|
def get_datestring(datetime)
|
@@ -163,6 +172,7 @@ module Md2site
|
|
163
172
|
|
164
173
|
#
|
165
174
|
# 現在時刻をDatetimeクラスのインスタンスと文字列にする
|
175
|
+
#
|
166
176
|
# @return [Array] 第0要素: Datetimeクラスのインスタンス 第1要素: "年月日-時分秒"の形式の文字列
|
167
177
|
def current_time
|
168
178
|
datetime = DateTime.now
|
@@ -172,6 +182,7 @@ module Md2site
|
|
172
182
|
|
173
183
|
#
|
174
184
|
# 指定サイトでダウンロード指定された全URLのHTTPヘッダの時刻を取得して一覧をファイルに保存
|
185
|
+
#
|
175
186
|
# @param dir [String] HTTPヘッダ時刻一覧ファイルの保存先ディレクトリ
|
176
187
|
# @return [Array] 第0要素: Datetimeクラスのインスタンス 第1要素: "年月日-時分秒"の形式の文字列
|
177
188
|
# @note 一覧を保存するファイルのファイル名はsite-年月日-時分秒.tsvである
|
@@ -183,10 +194,10 @@ module Md2site
|
|
183
194
|
|
184
195
|
@mes.exc_file_write(fpath) do
|
185
196
|
File.open(fpath, "w") do |ofile|
|
186
|
-
@
|
187
|
-
v.each do |_k2,
|
188
|
-
filename =
|
189
|
-
next
|
197
|
+
@category_target.each do |_k, v|
|
198
|
+
v[:subTargets].each do |_k2, subtarget|
|
199
|
+
filename = subtarget.htmlfile
|
200
|
+
next unless subtarget.aliashtmlfile && !subtarget.aliashtmlfile&.empty?
|
190
201
|
|
191
202
|
if %r{/$}.match?(@url)
|
192
203
|
file_url = URI.join(@url, filename)
|
@@ -197,9 +208,8 @@ module Md2site
|
|
197
208
|
unless ary.all?
|
198
209
|
@mes.output_error("Can't find last-modified header from #{@url}")
|
199
210
|
end
|
200
|
-
v2.concat(ary)
|
201
211
|
|
202
|
-
ofile.puts(
|
212
|
+
ofile.puts([file_url].join("\t"))
|
203
213
|
end
|
204
214
|
end
|
205
215
|
end
|
@@ -212,32 +222,58 @@ module Md2site
|
|
212
222
|
|
213
223
|
#
|
214
224
|
# 引数で指定したファイルが書込み可能であるように書込み先ディレクトリを作成
|
225
|
+
#
|
215
226
|
# @param dir [String] ディレクトリ
|
216
227
|
# @param filename [String] ファイルへのパス(ファイル名のみも可)
|
217
|
-
def prepare_new_write_path(dir, filename)
|
228
|
+
def prepare_new_write_path(dir, filename, postfix=nil)
|
229
|
+
if postfix
|
230
|
+
extname = File.extname(filename)
|
231
|
+
basename = File.basename(filename, extname)
|
232
|
+
new_fname = %Q(#{basename}#{postfix}#{extname})
|
233
|
+
else
|
234
|
+
basename = File.basename(filename)
|
235
|
+
new_fname = basename
|
236
|
+
end
|
237
|
+
|
218
238
|
dirname = File.dirname(filename)
|
219
239
|
if dirname != "."
|
220
240
|
dirpath = File.join(dir, dirname)
|
221
241
|
@mes.exc_make_directory(dirpath) { FileUtils.mkdir_p(dirpath) }
|
222
|
-
|
223
|
-
fpath = File.join(dirpath, basename)
|
242
|
+
fpath = File.join(dirpath, new_fname)
|
224
243
|
else
|
225
|
-
fpath = File.join(dir,
|
244
|
+
fpath = File.join(dir, new_fname)
|
226
245
|
end
|
246
|
+
|
227
247
|
fpath
|
228
248
|
end
|
229
249
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
250
|
+
#
|
251
|
+
# 指定サイトでダウンロード指定された全URLのをファイルとして、保存先ディレクトリにダウンロードし、
|
252
|
+
# ダウンロードステータスファイルを更新
|
253
|
+
#
|
254
|
+
# @param subtarget_hash [Hash] サブターゲット名をキーとしてサブターゲットストラクトを値とするハッシュ
|
255
|
+
# @param listfile [Listfile] ダウンロードファイル一覧ファイル
|
256
|
+
# @param last_contents_path [String] ダウンロード保存先ディレクトリ
|
257
|
+
# @return [void]
|
258
|
+
def get_remote_contents_subtargets(subtarget_hash, listfile, last_contents_path)
|
259
|
+
subtarget_hash.each do |_, subtarget_struct|
|
260
|
+
# filename = target_def[@env.htmlfile_index]
|
261
|
+
unless subtarget_struct.htmldir&.empty?
|
262
|
+
filename = File.join(subtarget_struct.htmldir, subtarget_struct.htmlfile)
|
263
|
+
else
|
264
|
+
filename = subtarget_struct.htmlfile
|
265
|
+
end
|
266
|
+
next unless subtarget_struct.aliashtmlfile&.empty?
|
234
267
|
|
268
|
+
# file_urlが'//'とならないようにする
|
235
269
|
if %r{/$}.match?(@url)
|
236
270
|
file_url = URI.join(@url, filename)
|
237
271
|
else
|
238
272
|
file_url = URI.join(@url, "/", filename)
|
239
273
|
end
|
274
|
+
# file_urlをダウンロードする
|
240
275
|
remote_datetime_str, remote_datetime_unixtime, content = get_remote_file(file_url)
|
276
|
+
# ダウンロードできなかった場合はエラーメッセージを表示して、次のサブターゲットのダウンロードに移る
|
241
277
|
unless [remote_datetime_str, remote_datetime_unixtime].all?
|
242
278
|
@mes.output_error("Can't get content from #{file_url}")
|
243
279
|
listfile.add([filename, remote_datetime_str, remote_datetime_unixtime, nil])
|
@@ -245,8 +281,9 @@ module Md2site
|
|
245
281
|
sleep(ACCESS_WAIT_SEC)
|
246
282
|
next
|
247
283
|
end
|
248
|
-
fpath = prepare_new_write_path(last_contents_path, filename)
|
249
284
|
|
285
|
+
# ダウンロードした内容をファイルに書き込む
|
286
|
+
fpath = prepare_new_write_path(last_contents_path, filename)
|
250
287
|
@mes.exc_file_write(fpath) do
|
251
288
|
File.open(fpath, "w") do |ofile|
|
252
289
|
if content
|
@@ -254,10 +291,17 @@ module Md2site
|
|
254
291
|
end
|
255
292
|
end
|
256
293
|
end
|
294
|
+
# ダウンロードファイル一覧に追加
|
257
295
|
listfile.add([filename, remote_datetime_str, remote_datetime_unixtime, Digest::MD5.hexdigest(content)])
|
258
296
|
end
|
259
297
|
end
|
260
298
|
|
299
|
+
#
|
300
|
+
# 指定サイトでダウンロード指定された全URLのをファイルとして、指定ディレクトリ下にダウンロードし、
|
301
|
+
# ダウンロードファイル一覧ファイルを作成し、ダウンロードステータスファイルを更新
|
302
|
+
#
|
303
|
+
# @param dir [String] ダウンロードファイルの保存先ディレクトリ
|
304
|
+
# @return [void]
|
261
305
|
def get_remote_contents(dir)
|
262
306
|
_, datetimestr = current_time
|
263
307
|
|
@@ -267,15 +311,28 @@ module Md2site
|
|
267
311
|
last_contents_path = File.absolute_path(File.join(dir, datetimestr))
|
268
312
|
@mes.exc_make_directory(last_contents_path) { FileUtils.mkdir_p(last_contents_path) }
|
269
313
|
|
314
|
+
# 保存先ディレクトリ内にダウンロードファイル一覧ファイルを作成
|
270
315
|
lf = ListFile.new(last_contents_path, @mes)
|
271
|
-
@
|
272
|
-
|
316
|
+
@category_target.each do |_, target_struct|
|
317
|
+
# 各ターゲット毎にファイルをダウンロード
|
318
|
+
get_remote_contents_subtargets(target_struct[:subTargets], lf, last_contents_path)
|
273
319
|
end
|
274
320
|
lf.close
|
321
|
+
|
322
|
+
# ダウンロードステータスファイルを更新
|
275
323
|
@status_file.last_contents_path = last_contents_path
|
276
324
|
@status_file.update
|
277
325
|
end
|
278
326
|
|
327
|
+
#
|
328
|
+
# ダウンロード保存先ディレクトリから指定サブターゲットのHTMLファイルをサブターゲットで
|
329
|
+
# 指定されてディレクトリにコピーし、3分割し、中間部分をMarkdown形式に変換する
|
330
|
+
#
|
331
|
+
# @param subtarget [String] サブターゲットストラクト
|
332
|
+
# @param src_fpath [String] コピー元ファイルパス
|
333
|
+
# @return [void]
|
334
|
+
# @note HTMLファイルからMarkdown形式ファイルへの変換にはpandocを利用するため、pandoc
|
335
|
+
# がインストールされていることが前提
|
279
336
|
def update_htmlfiles_subtarget(subtarget, src_fpath)
|
280
337
|
dest_fpath = prepare_new_write_path(@env.absolutepath_root, subtarget.filedir.html_input)
|
281
338
|
unless dest_fpath
|
@@ -304,14 +361,19 @@ module Md2site
|
|
304
361
|
@mes.output_fatal("Can't find file(=#{in_html}")
|
305
362
|
exit(@mes.ec("EXIT_CODE_CANNOT_FIND_FILE"))
|
306
363
|
end
|
307
|
-
|
308
|
-
simple_html2md(in_html,
|
309
|
-
|
310
|
-
|
311
|
-
@mes.exc_make_directory(subtarget.workDir) { FileUtils.mkdir_p(path) }
|
364
|
+
out_orig_md = prepare_new_write_path(@env.absolutepath_root, subtarget.filedir.input_md, "_orig")
|
365
|
+
simple_html2md(in_html, out_orig_md)
|
366
|
+
out_md = File.join(@env.absolutepath_root, subtarget.filedir.input_md)
|
367
|
+
@mes.exc_file_copy(out_orig_md, out_md) { FileUtils.cp(out_orig_md, out_md) } unless File.exist?(out_md)
|
312
368
|
end
|
313
369
|
|
370
|
+
#
|
371
|
+
# ダウンロードステータスファイルを更新ダウンロード保存先ディレクトリから指定サブターゲットのHTMLファイルをサブターゲットで
|
372
|
+
# 指定されてディレクトリにコピーし、3分割し、中間部分をMarkdown形式に変換する
|
373
|
+
#
|
374
|
+
# @return [void]
|
314
375
|
def update_htmlfiles
|
376
|
+
# 有効なダウンロードステータスファイルが存在しなければexitする
|
315
377
|
if @status_file.nil? || @status_file.last_contents_path.nil? || @status_file.last_contents_path.empty?
|
316
378
|
@mes.output_info("@status_file=#{@status_file}")
|
317
379
|
unless @status_file.nil?
|
@@ -319,8 +381,14 @@ module Md2site
|
|
319
381
|
end
|
320
382
|
exit(@mes.ec("EXIT_CODE_EXECUTE_SETUP_BEFORE_UPDATE_HTMLFILES"))
|
321
383
|
else
|
322
|
-
|
384
|
+
# 全ターゲットの全サブターゲットのうち、エイリアスHTMLファイルが指定されておらず、かつ未ダウンロード
|
385
|
+
# のもののみをダウンロードする
|
386
|
+
@category_target.each do |_name, category_struct|
|
323
387
|
category_struct.subTargets.each do |_k, v|
|
388
|
+
# エイリアスHTMLファイルが指定されていても、ワークディレクトリは必要なため、ここで作成する
|
389
|
+
path = File.join(@env.absolutepath_root, v.workDir)
|
390
|
+
@mes.exc_make_directory(path) { FileUtils.mkdir_p(path) }
|
391
|
+
|
324
392
|
next unless v.aliashtmlfile.empty?
|
325
393
|
filename = v.htmlfile
|
326
394
|
next if filename.empty?
|
@@ -336,6 +404,14 @@ module Md2site
|
|
336
404
|
end
|
337
405
|
end
|
338
406
|
|
407
|
+
#
|
408
|
+
# HTMLファイルをMarkdown形式に変換する
|
409
|
+
#
|
410
|
+
# @param input_htmlfname [String] 変換元HTMLファイル名
|
411
|
+
# @param outputmd [String] 変換したMakrdown形式ファイル名
|
412
|
+
# @return [void]
|
413
|
+
# @note HTMLファイルからMarkdown形式ファイルへの変換にはpandocを利用するため、pandoc
|
414
|
+
# がインストールされていることが前提
|
339
415
|
def simple_html2md(input_htmlfname, outputmd)
|
340
416
|
ret = false
|
341
417
|
_, _, s = Open3.capture3(%Q(pandoc -o #{outputmd} -t markdown #{input_htmlfname}))
|
@@ -355,4 +431,4 @@ module Md2site
|
|
355
431
|
ret
|
356
432
|
end
|
357
433
|
end
|
358
|
-
end
|
434
|
+
end
|