# This function converts a "source" file to something looking good in VuePress, # adding, replacing and stuff require "fileutils" require "net/http" require "uri" require "rexml/document" def process_file(indir, file, outdir, source) in_frontmatter = false frontmatter_processed = false has_source = false has_logo = 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:/ 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 == "habpanel" then puts " (add-on is habpanel)" source = "https://github.com/openhab/openhab-webui/blob/main/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/main/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/main/README.md" elsif !(file =~ /things/) then puts " (add-on is from openhab-addons)" source = "https://github.com/openhab/openhab-addons/blob/main/addons/#{addon_type}/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 if line =~ /^More details regarding this and other Transformation services can be found in the individual transformation articles linked below./ out.puts "" out.puts ":::tip" out.puts "You can find the available transformation services [here](https://www.openhab.org/addons/#transform)." out.puts ":::" out.puts "" break end 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_bindings.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 # Expand comments with a list of links # (https://github.com/eclipse/smarthome/issues/5571) if line =~ // 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("{{docu}}/", "./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("", '\') line = line.gsub("", '\') line = line.gsub("(?(?!`)", '\') line = line.gsub("", '\') line = line.gsub("", '``') if file =~ /amazonechocontrol/ line = line.gsub("", '<SerialNumber>') if file =~ /airvisualnode/ line = line.gsub("", '<version>') if file =~ /caldav/ line = line.gsub("by ", 'by ``') if file =~ /ipx8001/ line = line.gsub("
", '
') line = line.gsub("':'", '`:`') if file =~ /lametrictime/ line = line.gsub("", '``') if file =~ /milight/ line = line.gsub("", '``') if file =~ /milight/ line = line.gsub("", '``') if file =~ /milight/ line = line.gsub("", '``') if file =~ /milight/ line = line.gsub("", '``') if file =~ /milight/ line = line.gsub("", '``') if file =~ /milight/ line = line.gsub("[](", '[here](') if file =~ /powermax1/ line = line.gsub("", '<n>') if file =~ /rfxcom/ line = line.gsub(" ", ' <value> ') if file =~ /zibase/ line = line.gsub("", '<username>') if file =~ /zoneminder/ line = line.gsub("", '<password>') if file =~ /zoneminder/ line = line.gsub("", '<yourzmip>') if file =~ /zoneminder/ line = line.gsub(" ", ' <chatId> ') if file =~ /telegram/ line = line.gsub(" ", ' <token> ') if file =~ /telegram/ line = line.gsub("", '\') 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 out.puts '' } end