forked from openhab/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare-docs.rb
633 lines (500 loc) · 27.8 KB
/
prepare-docs.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
# This will clone https://github.com/openhab/openhab-docs
# and migrate content into the website with some changes
require "fileutils"
require "net/http"
require "uri"
require "rexml/document"
# require "nokogiri"
$docs_repo = "https://github.com/openhab/openhab-docs"
$docs_repo_root = $docs_repo + "/blob/main"
$docs_repo_branch = "final"
$addons_repo_branch = "main"
$version = nil
$ignore_addons = ['transport.modbus', 'transport.feed', 'javasound', 'webaudio', 'oh2']
if ENV["OH_DOCS_VERSION"] then
puts ">>> Generating docs for version #{ENV["OH_DOCS_VERSION"]}"
$version = ENV["OH_DOCS_VERSION"]
$version += ".0" if $version.split(".").length == 2
end
if (ARGV[0] && ARGV[0] == "--no-clone" && Dir.exists?(".vuepress/openhab-docs")) then
puts ">>> Re-using existing clone"
else
puts ">>> Deleting .vuepress/openhab-docs if existing..."
FileUtils.rm_rf(".vuepress/openhab-docs")
puts ">>> Cloning openhab-docs"
`git clone --depth 1 --branch #{$version ? $version : $docs_repo_branch} https://github.com/openhab/openhab-docs .vuepress/openhab-docs`
end
# Get a list of sub-addons to transform them into links
def get_subs_links(parent_addon_id, search_dir)
sub_addons = []
Dir.glob("#{search_dir}/#{parent_addon_id}.*/**/readme.md").each { |sub_readme|
sub_addon_id = File.dirname(sub_readme).split('/').last
puts " -> expanding list of sub-addons: #{sub_addon_id}"
File.open(sub_readme).each { |line|
if line =~ /^# / then
sub_addons.push([sub_addon_id, line.gsub('# ', '').strip])
break
end
}
}
return sub_addons
end
def process_file(indir, file, outdir, source)
in_frontmatter = false
frontmatter_processed = false
has_source = false
has_logo = false
since_1x = false
obsolete_binding = false
og_title = 'openHAB'
og_description = 'a vendor and technology agnostic open source automation software for your home'
if !File.exists?("#{indir}/#{file}") then
puts "process_file: IGNORING (NON-EXISTING): #{indir}/#{file}"
return
end
FileUtils.mkdir_p(outdir)
File.open("#{outdir}/#{file}", "w+") { |out|
File.open("#{indir}/#{file}").each { |line|
next if line =~ /^layout: documentation/
next if line =~ /^layout: tutorial/
next if line =~ /^layout: developers/
next if line =~ /^layout: intro/
next if line =~ /^{% include base.html %}/
next if line =~ /\{: #/
next if line =~ /\{::options/
next if line =~ /TOC/
next if line =~ /no_toc/
has_source = true if in_frontmatter && line =~ /^source:/
has_logo = true if in_frontmatter && line =~ /^logo:/
since_1x = true if in_frontmatter && line =~ /^since: 1x/
if in_frontmatter && line =~ /^title:/ then
og_title = line.gsub('title: ', '').gsub("\n", "")
end
if in_frontmatter && line =~ /^description:/ then
og_description = line.gsub('description: ', '').gsub("\n", "").gsub('[', '').gsub(']', '').gsub(/\(http[:\/\-0-9A-Za-z\.]+\)/, '')
end
if line =~ /^---$/ then
if !in_frontmatter then
in_frontmatter = true
elsif !frontmatter_processed
if !has_source && source then
# Prefer already present source
out.puts "source: #{source}"
elsif !has_source
# Try to determine the source
outdir_parts = outdir.split('/')
outdir_parts[1] = "binding" if outdir_parts[1] == "bindings"
outdir_parts[1] = "transform" if outdir_parts[1] == "transformations"
outdir_parts[1] = "io" if outdir_parts[1] == "integrations"
if (outdir_parts[0] == "addons") then
addon_type = outdir_parts[1]
addon = file.split('/')[0]
source = ""
if addon == "habot" then
puts " (add-on is habot)"
source = "https://github.com/openhab/openhab-webui/blob/#{$addons_repo_branch}/bundles/org.openhab.ui.habot/README.md"
elsif addon == "habpanel" then
puts " (add-on is habpanel)"
source = "https://github.com/openhab/openhab-webui/blob/#{$addons_repo_branch}/bundles/org.openhab.ui.habpanel/README.md"
elsif addon == "zigbee" then
puts " (add-on is zigbee)"
source = "https://github.com/openhab/org.openhab.binding.zigbee/blob/#{$addons_repo_branch}/org.openhab.binding.zigbee/README.md"
elsif addon == "zwave" && !(file =~ /things/) then
puts " (add-on is zwave)"
source = "https://github.com/openhab/org.openhab.binding.zwave/blob/#{$addons_repo_branch}/README.md"
elsif !(file =~ /things/) then
source = "https://github.com/openhab/openhab-addons/blob/#{$addons_repo_branch}/bundles/org.openhab.#{addon_type}.#{addon}/README.md"
end
out.puts "source: #{source}" if source != ""
# For sub-bundles, set the "prev" link to the main add-on
out.puts "prev: ../#{addon.split('.')[0]}/" if addon.include?('.')
# Prev link to the main binding doc for zwave/doc/things.md
out.puts "prev: ../" if file == 'zwave/doc/things.md'
end
end
# Add OpenGraph tags
out.puts "meta:"
out.puts " - property: og:title"
out.puts " content: \"#{og_title.gsub('"', '\"')}\""
out.puts " - property: og:description"
out.puts " content: #{og_description}"
in_frontmatter = false
frontmatter_processed = true
end
end
# Replace the Jekyll "contribution wanted" include file by custom VuePress markup
line = "[[toc]]" if line =~ /\{:toc/
if line =~ /\{% include contribution-wanted.html %\}/
out.puts "::: tip Contribution Wanted"
out.puts "Please help us improve the documentation! "
out.puts "If you'd like to leave corrections, additions or comments for this article or any other part of this website, please drop a word at:"
out.puts "[Documentation Issue Tracker](#{$docs_repo}/issues)"
out.puts ":::"
next
end
# Actions and transformations are currently partly in add-ons, copy the content above the list of add-ons
break if line =~ /^More details regarding this and other Transformation services can be found in the individual transformation articles linked below./
break if line =~ /^## Installable Actions/
# Remove collapsibles in Linux install document and replace them by regular headings
next if line =~ /include collapsible/ && file =~ /linux/
line = "##### " + line if line =~ /^Apt Based Systems/ && file =~ /linux/
line = "##### " + line if line =~ /^Yum or Dnf Based Systems/ && file =~ /linux/
line = "##### " + line if line =~ /^Systems based on/ && file =~ /linux/
# Fix headers for some pages
line = line.gsub(/^##/, "#") if (outdir == "docs/configuration/ui" && (file =~ /basic/ || file =~ /classic/)) || file == 'astro1/readme.md'
# Fix broken links in the package selection article
if outdir == 'docs/configuration' && file =~ /packages/ then
line = line.gsub('(../addons/uis/paper/readme.html)', '(paperui.html)')
line = line.gsub('(../addons/uis/basic/readme.html)', '(ui/basic/)')
line = line.gsub('(../addons/uis/classic/readme.html)', '(ui/classic/)')
line = line.gsub('(../addons/uis/habmin/readme.html)', '(ui/habmin/)')
line = line.gsub('(../addons/uis/habpanel/readme.html)', '(habpanel.html)')
end
# Handle obsolete bindings
if in_frontmatter && (line =~ /label: / || line =~ /title: /) && outdir == 'addons/bindings' && file =~ /1\// then
addon = file.split('/')[0]
if !$ignore_addons.include?(addon.gsub('1', '')) && Dir.exists?("#{indir}/#{addon.gsub('1', '')}") then
line = line.gsub("\n", "") + ' (1.x)' if !(line =~ /1\.x/)
if !obsolete_binding then
obsolete_binding = true
out.puts "obsolete: true"
puts " obsolete!"
end
end
end
if !in_frontmatter && line =~ /^# / then
line = line.gsub("\n", "").gsub("\r", "") + ' <Badge type="warn" text="v1"/>' if since_1x
# Put a warning banner for obsolete bindings
out.puts line
if obsolete_binding then
out.puts
out.puts "::: danger OBSOLETE BINDING"
new_addon = file.split('/')[0].gsub('1', '')
out.puts "This 1.x binding is obsolete; it has been replaced by the 2.x [#{new_addon}](../#{new_addon}/) binding which you should use instead."
out.puts ":::"
out.puts
obsolete_binding = false
end
# Add the logo if specified
if has_logo then
out.puts
out.puts '<AddonLogo/>'
has_logo = false
end
next
end
# Expand <!--list-subs--> comments with a list of links
# (https://github.com/eclipse/smarthome/issues/5571)
if line =~ /<!--\s*list-subs\s*-->/ then
sub_addons = get_subs_links(file.split('/')[0], indir)
out.puts
sub_addons.each { |sub|
out.puts "- [#{sub[1]}](../#{sub[0]}/)"
}
out.puts
end
# Replace links to generated docs in ZWave's things.md by links to the internal viewer
line = line.gsub(/]\((.*)\/(.*)\)/, '](../thing.html?manufacturer=\1&file=\2)') if file == 'zwave/doc/things.md'
# Misc replaces (relative links, remove placeholder interpreted as custom tags)
line = line.gsub('http://docs.openhab.org/addons/uis/paper/readme.html', '/docs/configuration/paperui.html')
line = line.gsub('http://docs.openhab.org/addons/uis/habpanel/readme.html', '/docs/configuration/habpanel.html')
line = line.gsub('http://docs.openhab.org/addons/uis/habmin/readme.html', '/docs/configuration/habmin.html')
line = line.gsub('http://docs.openhab.org/addons/uis/basic/readme.html', '/docs/configuration/ui/basic/')
line = line.gsub(/http:\/\/docs\.openhab\.org\/addons\/(.*)\/(.*)\/readme\.html/, '/addons/\1/\2/')
line = line.gsub('http://docs.openhab.org/', '/docs/')
line = line.gsub('/addons/io/', '/addons/integrations/')
line = line.gsub("{{base}}/", "./docs/")
line = line.gsub("(images/", "(./images/")
line = line.gsub("src=\"images/", "src=\"./images/")
line = line.gsub("]:images/", "]:./images/")
line = line.gsub("](doc/", "](./doc/")
line = line.gsub("(diagrams/", "(./diagrams/")
line = line.gsub("./docs/tutorials/beginner/", "/docs/tutorial/")
line = line.gsub("./docs/", "/docs/")
line = line.gsub("<activeState>", '\<activeState\>')
line = line.gsub("<passiveState>", '\<passiveState\>')
line = line.gsub("<dimension>", '\<dimension\>')
line = line.gsub("<TransformProgram>", '\<TransformProgram\>')
line = line.gsub("<FlahshbriefingDeviceID>", '`<FlahshbriefingDeviceID>`') if file =~ /amazonechocontrol/
line = line.gsub("<SerialNumber>", '<SerialNumber>') if file =~ /airvisualnode/
line = line.gsub("<version>", '<version>') if file =~ /caldav/
line = line.gsub("by <step>", 'by `<step>`') if file =~ /ipx8001/
line = line.gsub("<BR>", '<BR/>')
line = line.gsub("'<package name>:<widget ID>'", '`<package name>:<widget ID>`') if file =~ /lametrictime/
line = line.gsub("<mac address of bridge>", '`<mac address of bridge>`') if file =~ /milight/
line = line.gsub("<mac>", '`<mac>`') if file =~ /milight/
line = line.gsub("<type of bulb>", '`<type of bulb>`') if file =~ /milight/
line = line.gsub("<IP-Address of bridge>", '`<IP-Address of bridge>`') if file =~ /milight/
line = line.gsub("<bulb>", '`<bulb>`') if file =~ /milight/
line = line.gsub("<zone>", '`<zone>`') if file =~ /milight/
line = line.gsub("[](", '[here](') if file =~ /powermax1/
line = line.gsub("<n>", '<n>') if file =~ /rfxcom/
line = line.gsub(" <value> ", ' <value> ') if file =~ /zibase/
line = line.gsub("<username>", '<username>') if file =~ /zoneminder/
line = line.gsub("<password>", '<password>') if file =~ /zoneminder/
line = line.gsub("<yourzmip>", '<yourzmip>') if file =~ /zoneminder/
line = line.gsub(" <chatId> ", ' <chatId> ') if file =~ /telegram/
line = line.gsub(" <token> ", ' <token> ') if file =~ /telegram/
line = line.gsub("<regular expression>", '\<regular expression\>')
line = line.gsub('src="images/', 'src="./images/') if outdir =~ /apps/
line = line.gsub('](/images/', '](./images/') if outdir =~ /google-assistant/
line = line.gsub(/\{:(style|target).*\}/, '') # Jekyll inline attributes syntax not supported
out.puts line
}
# Add the components for the versions dropdown and the edit link
out.puts
# Obsolete: the combobox for versions will be moved globally on the v3 site
# out.puts '<DocPreviousVersions/>' unless file == "introduction.md" and outdir == "docs"
out.puts '<EditPageLink/>'
}
end
puts ">>> Migrating the introduction article"
process_file(".vuepress/openhab-docs", "introduction.md", "docs", "https://github.com/openhab/openhab-docs/blob/main/introduction.md")
FileUtils.mv("docs/introduction.md", "docs/readme.md")
puts ">>> Migrating common images"
FileUtils.mkdir_p("docs/images")
FileUtils.cp_r(".vuepress/openhab-docs/images/distro.png", "docs/images")
FileUtils.cp_r(".vuepress/openhab-docs/images/dashboard.png", "docs/images")
puts ">>> Migrating logos"
FileUtils.cp_r(".vuepress/openhab-docs/images/addons", ".vuepress/public/logos")
puts ">>> Migrating the Concepts section"
Dir.glob(".vuepress/openhab-docs/concepts/*.md").each { |path|
file = File.basename(path)
puts " -> #{file}"
process_file(".vuepress/openhab-docs/concepts", file, "docs/concepts", "#{$docs_repo_root}/concepts/#{file}")
}
puts " -> images and diagrams"
FileUtils.cp_r(".vuepress/openhab-docs/concepts/images", "docs/concepts/images")
FileUtils.cp_r(".vuepress/openhab-docs/concepts/diagrams", "docs/concepts/diagrams")
puts ">>> Migrating the Installation section"
Dir.glob(".vuepress/openhab-docs/installation/*.md") { |path|
file = File.basename(path)
next if file == "designer.md"
puts " -> #{file}"
process_file(".vuepress/openhab-docs/installation", file, "docs/installation", "#{$docs_repo_root}/installation/#{file}")
}
puts " -> images"
FileUtils.cp_r(".vuepress/openhab-docs/installation/images", "docs/installation/images")
puts ">>> Migrating the Tutorial section"
Dir.glob(".vuepress/openhab-docs/tutorials/getting_started/*.md") { |path|
file = File.basename(path)
puts " -> #{file}"
process_file(".vuepress/openhab-docs/tutorials/getting_started", file, "docs/tutorial", "#{$docs_repo_root}/tutorials/getting_started/#{file}")
}
puts " -> images"
FileUtils.cp_r(".vuepress/openhab-docs/tutorials/getting_started/images", "docs/tutorial/images")
puts ">>> Migrating the Configuration section"
Dir.glob(".vuepress/openhab-docs/configuration/*.md") { |path|
file = File.basename(path)
next if file == "transform.md" # Useless, copy the one from addons
puts " -> #{file}"
process_file(".vuepress/openhab-docs/configuration", file, "docs/configuration", "#{$docs_repo_root}/configuration/#{file}")
}
puts " -> images"
FileUtils.cp_r(".vuepress/openhab-docs/configuration/images", "docs/configuration")
process_file(".vuepress/openhab-docs/addons", "actions.md", "docs/configuration", "#{$docs_repo_root}/addons/actions.md")
process_file(".vuepress/openhab-docs/addons", "transformations.md", "docs/configuration", "#{$docs_repo_root}/addons/transformations.md")
puts ">>> Migrating the Migration Tutorial section"
Dir.glob(".vuepress/openhab-docs/configuration/migration/*.md") { |path|
file = File.basename(path)
puts " -> #{file}"
process_file(".vuepress/openhab-docs/configuration/migration", file, "docs/configuration/migration", "#{$docs_repo_root}/configuration/migration/#{file}")
}
puts " -> images"
#FileUtils.cp_r(".vuepress/openhab-docs/configuration/migration/images", "docs/configuration/migration/") // no images placed yet
puts ">>> Migrating the UI section"
Dir.glob(".vuepress/openhab-docs/ui/*.md") { |path|
file = File.basename(path)
puts " -> #{file}"
process_file(".vuepress/openhab-docs/ui", file, "docs/ui", "#{$docs_repo_root}/ui/#{file}")
}
puts " -> images"
FileUtils.cp_r(".vuepress/openhab-docs/ui/images", "docs/ui/images")
puts " -> habpanel"
FileUtils.mkdir_p("docs/ui/habpanel")
process_file(".vuepress/openhab-docs/_addons_uis/habpanel/doc", "habpanel.md", "docs/ui/habpanel", "")
puts " -> images"
FileUtils.cp_r(".vuepress/openhab-docs/_addons_uis/habpanel/doc/images", "docs/ui/habpanel") if Dir.exists?(".vuepress/openhab-docs/_addons_uis/habpanel/doc/images")
puts " -> habot"
FileUtils.mkdir_p("docs/ui/habot")
process_file(".vuepress/openhab-docs/_addons_uis/habot", "readme.md", "docs/ui/habot", "")
puts " -> images"
puts " -> components"
FileUtils.mkdir_p("docs/ui/components")
Dir.glob(".vuepress/openhab-docs/_addons_uis/org.openhab.ui/doc/components/*.md") { |path|
file = File.basename(path)
puts " -> #{file}"
process_file(".vuepress/openhab-docs/_addons_uis/org.openhab.ui/doc/components", file, "docs/ui/components", "https://github.com/openhab/openhab-webui/blob/main/bundles/org.openhab.ui/doc/components/#{file}")
}
puts " -> images"
FileUtils.cp_r(".vuepress/openhab-docs/_addons_uis/org.openhab.ui/doc/components/images", "docs/ui/components/images") if Dir.exists?(".vuepress/openhab-docs/_addons_uis/org.openhab.ui/doc/components/images")
puts ">>> Migrating the Apps section"
Dir.glob(".vuepress/openhab-docs/addons/uis/apps/*.md") { |path|
file = File.basename(path)
puts " -> #{file}"
process_file(".vuepress/openhab-docs/addons/uis/apps", file, "docs/apps", "#{$docs_repo_root}/addons/uis/apps/#{file}")
}
puts " -> images"
FileUtils.cp_r(".vuepress/openhab-docs/addons/uis/apps/images", "docs/apps")
puts ">>> Migrating the Administration section"
Dir.glob(".vuepress/openhab-docs/administration/*.md") { |path|
file = File.basename(path)
puts " -> #{file}"
process_file(".vuepress/openhab-docs/administration", file, "docs/administration", "#{$docs_repo_root}/administration/#{file}")
}
puts " -> images"
FileUtils.cp_r(".vuepress/openhab-docs/administration/images", "docs/administration/images")
puts ">>> Migrating the Developer section"
Dir.glob(".vuepress/openhab-docs/developers/*.md") { |path|
file = File.basename(path)
puts " -> #{file}"
process_file(".vuepress/openhab-docs/developers", file, "docs/developer", "#{$docs_repo_root}/developer/#{file}")
}
["audio", "bindings", "ioservices", "legacy", "module-types", "osgi", "persistence", "transformations", "utils", "ide"].each { |subsection|
Dir.glob(".vuepress/openhab-docs/developers/#{subsection}/*.md") { |path|
file = File.basename(path)
puts " -> #{subsection}/#{file}"
process_file(".vuepress/openhab-docs/developers/#{subsection}", file, "docs/developer/#{subsection}", "#{$docs_repo_root}/developer/#{subsection}/#{file}")
}
}
puts " -> images"
FileUtils.cp_r(".vuepress/openhab-docs/developers/bindings/images", "docs/developer/bindings/images")
FileUtils.cp_r(".vuepress/openhab-docs/developers/osgi/images", "docs/developer/osgi/images")
FileUtils.cp_r(".vuepress/openhab-docs/developers/ide/images", "docs/developer/ide/images")
### ADDONS
puts ">>> Migrating add-ons: Automation"
Dir.glob(".vuepress/openhab-docs/_addons_automation/**") { |path|
addon = File.basename(path)
next if $ignore_addons.include?(addon)
puts " -> #{addon}"
FileUtils.mkdir_p("addons/automation/" + addon)
process_file(".vuepress/openhab-docs/_addons_automation", addon + "/readme.md", "addons/automation", nil)
}
puts ">>> Migrating add-ons: Persistence"
Dir.glob(".vuepress/openhab-docs/_addons_persistences/**") { |path|
addon = File.basename(path)
next if $ignore_addons.include?(addon)
puts " -> #{addon}"
FileUtils.mkdir_p("addons/persistence/" + addon)
process_file(".vuepress/openhab-docs/_addons_persistences", addon + "/readme.md", "addons/persistence", nil)
}
puts ">>> Migrating add-ons: Transformations"
Dir.glob(".vuepress/openhab-docs/_addons_transformations/**") { |path|
addon = File.basename(path)
next if $ignore_addons.include?(addon)
puts " -> #{addon}"
FileUtils.mkdir_p("addons/transformations/" + addon)
process_file(".vuepress/openhab-docs/_addons_transformations", addon + "/readme.md", "addons/transformations", nil)
}
puts ">>> Migrating add-ons: Voice"
Dir.glob(".vuepress/openhab-docs/_addons_voices/**") { |path|
addon = File.basename(path)
next if $ignore_addons.include?(addon)
puts " -> #{addon}"
FileUtils.mkdir_p("addons/voice/" + addon)
process_file(".vuepress/openhab-docs/_addons_voices", addon + "/readme.md", "addons/voice", nil)
}
puts ">>> Migrating add-ons: IO"
Dir.glob(".vuepress/openhab-docs/_addons_ios/**") { |path|
# See below for the Alexa & Mycroft special cases
next if path =~ /alexa-skill/
next if path =~ /mycroft-skill/
next if path =~ /google-assistant/
addon = File.basename(path)
next if $ignore_addons.include?(addon)
puts " -> #{addon}"
# Detect and skip 1.x bindings - shouldn't ultimately occur
if addon =~ /1$/ then
puts " (1.x, skipping)"
next
end
FileUtils.mkdir_p("addons/integrations/" + addon)
process_file(".vuepress/openhab-docs/_addons_ios", addon + "/readme.md", "addons/integrations", nil)
if (Dir.exists?(".vuepress/openhab-docs/_addons_ios/#{addon}/doc")) then
puts " \\-> images"
FileUtils.cp_r(".vuepress/openhab-docs/_addons_ios/#{addon}/doc", "addons/integrations/#{addon}")
end
if (Dir.exists?(".vuepress/openhab-docs/_addons_ios/#{addon}/contrib")) then
puts " \\-> images"
FileUtils.cp_r(".vuepress/openhab-docs/_addons_ios/#{addon}/contrib", "addons/integrations/#{addon}")
end
}
# Handle those three separately - copy them in the "ecosystem" section
FileUtils.mkdir_p("docs/ecosystem/alexa")
FileUtils.mkdir_p("docs/ecosystem/mycroft")
FileUtils.mkdir_p("docs/ecosystem/google-assistant")
process_file(".vuepress/openhab-docs/_addons_ios/alexa-skill", "readme.md", "docs/ecosystem/alexa", "https://github.com/openhab/openhab-alexa/blob/master/USAGE.md")
process_file(".vuepress/openhab-docs/_addons_ios/mycroft-skill", "readme.md", "docs/ecosystem/mycroft", "https://github.com/openhab/openhab-mycroft/blob/master/USAGE.md")
process_file(".vuepress/openhab-docs/_addons_ios/google-assistant", "readme.md", "docs/ecosystem/google-assistant", "https://github.com/openhab/openhab-google-assistant/blob/master/docs/USAGE.md")
FileUtils.cp_r(".vuepress/openhab-docs/_addons_ios/google-assistant/images", "docs/ecosystem/google-assistant")
puts ">>> Migrating add-ons: Bindings"
Dir.glob(".vuepress/openhab-docs/_addons_bindings/**") { |path|
addon = File.basename(path)
next if $ignore_addons.include?(addon)
puts " -> #{addon}"
# Detect and skip 1.x bindings - shouldn't ultimately occur
if addon =~ /1$/ then
puts " (1.x, skipping)"
next
end
FileUtils.mkdir_p("addons/bindings/" + addon)
process_file(".vuepress/openhab-docs/_addons_bindings", addon + "/readme.md", "addons/bindings", nil)
if (Dir.exists?(".vuepress/openhab-docs/_addons_bindings/#{addon}/doc") && addon != "zwave") then
puts " \\-> images"
FileUtils.cp_r(".vuepress/openhab-docs/_addons_bindings/#{addon}/doc", "addons/bindings/#{addon}")
elsif (Dir.exists?(".vuepress/openhab-docs/_addons_bindings/#{addon}/contrib") && addon != "zwave") then
puts " \\-> images"
FileUtils.cp_r(".vuepress/openhab-docs/_addons_bindings/#{addon}/contrib", "addons/bindings/#{addon}")
elsif addon == "zwave" then
puts " \\-> things.md"
FileUtils.mkdir_p("addons/bindings/zwave/doc")
process_file(".vuepress/openhab-docs/_addons_bindings", "zwave/doc/things.md", "addons/bindings", nil)
end
}
puts ">>> Creating ZWave thing viewer"
if (File.exists?('.vuepress/openhab-docs/_addons_bindings/zwave/doc/things.md')) then
File.open('addons/bindings/zwave/thing.md', 'w+') { |out|
out.puts '---'
out.puts 'title: ZWave Thing'
out.puts 'prev: ./'
out.puts '---'
out.puts
out.puts '<ThingDocRenderer />'
}
end
# puts ">>> Migrating Z-Wave docs"
# Dir.glob(".vuepress/openhab-docs/_addons_bindings/zwave/doc/*.md") { |path|
# next if path =~ /device\.md/
# file = File.basename(path)
# puts " -> #{file}"
# FileUtils.mkdir_p("addons/bindings/zwave/doc")
# process_file(".vuepress/openhab-docs/_addons_bindings/zwave/doc", file, "addons/bindings/zwave/doc", nil)
# }
# Write arrays of addons by type to include in VuePress config.js
puts ">>> Writing add-ons arrays to files for sidebar navigation"
["bindings", "persistence", "automation", "integrations", "transformations", "voice"].each { |type|
File.open(".vuepress/addons-#{type}.js", "w+") { |file|
file.puts "module.exports = ["
Dir.foreach('addons/' + type) { |dir|
if !dir.include?('.') then
# puts dir
File.readlines('addons/' + type + '/' + dir + '/readme.md').each { |line|
if line =~ /^label:/ then
title = line.gsub("label: ", "").gsub("\n", "")
file.puts "\t['#{type}/#{dir}/', '#{title}']," if !(title =~ /1\.x/)
end
}
end
}
file.puts "]"
}
}
# Regenerate the classic iconset docs
puts ">>> Generating iconset"
system("ruby generate_iconset_doc.rb .vuepress/openhab-docs/_addons_iconsets classic .vuepress/openhab-docs/_data docs/configuration/iconsets")
# Publish latest Javadoc
puts ">>> Downloading and extracting latest Javadoc from Jenkins"
`wget -nv https://ci.openhab.org/job/openHAB-JavaDoc/lastSuccessfulBuild/artifact/target/javadoc-latest.tgz`
`tar xzvf javadoc-latest.tgz --strip 2 && mv apidocs/ .vuepress/public/javadoc/latest`
# Copy the thing-types.json file to the proper location
FileUtils.cp(".vuepress/openhab-docs/.vuepress/thing-types.json", ".vuepress")