require 'redcarpet' require 'date' site = IO.readlines("input/site.conf", chomp: true) site_domain = site[0] site_name = site[1] theme = site[2] directory = Dir["input/*/"] everything = Dir["input/**/*.md"] workspace = Dir["input/*.md"] prelim = Dir["input/**/*.*"] base = Dir["input/**/"] files = [] structure = [] workspace.push(*everything) themes_fold = "themes/" theme_dir = themes_fold + theme + "/" protocol = "https://" da = ["home "] dp = ["
"] dsa = ["/ "] dsp = [""] Dir.mkdir "output/ewfm_theme" dist_files = Dir[theme_dir + "dist/*"] puts dist_files for file in dist_files string = File.read(file) handle = file prefix = theme_dir + "dist/" handle[prefix]= "output/ewfm_theme/" IO.write(handle, string) end for string in base if string != "input/" structure.append(string) end end for string in prelim if not string.include? ".md" files.append(string) end end for file in directory file1 = "/" + file file1["input/"]= "" file2 = file1[1..-1] file2["/"]= "" da.append("" + file2 + " ") dp.append("") dsa.append("" + file2 + "/ ") dsp.append("") end for file in structure handle = file handle["input/"]= "" comb = "output/" + handle Dir.mkdir comb unless Dir.exists? comb end for file in files handle = File.read(file) output = file output["input"]= "output" IO.write(output, handle) end def scope yield end for file in workspace text = File.read(file) template = File.read(theme_dir + "template.html") product = template puts file renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, fenced_code_blocks: true, strikethrough: true, underline: true, space_after_headers: true) lines = text.lines rest_of_content = lines[1..-1] raw_content = rest_of_content.join() title = lines[0] content = renderer.render(raw_content) while product.include? "{SITE_NAME}" product["{SITE_NAME}"]= site_name end while product.include? "{SITE_DOMAIN}" product["{SITE_DOMAIN}"]= site_domain end while product.include? "{PAGE_TITLE}" product["{PAGE_TITLE}"]= title end while product.include? "{DIRECTORY_A}" product["{DIRECTORY_A}"]= da.join() end while product.include? "{DIRECTORY_P}" product["{DIRECTORY_P}"]= dp.join() end while product.include? "{DIRECTORY_SLASH_A}" product["{DIRECTORY_SLASH_A}"]= dsa.join() end while product.include? "{DIRECTORY_SLASH_P}" product["{DIRECTORY_SLASH_P}"]= dsp.join() end while product.include? "{PAGE_CONTENT}" product["{PAGE_CONTENT}"]= content end while raw_content.include? "$EWFM$" product["$EWFM$"]= "This page has been generated by ewfm using the " + theme + " theme!
" end while raw_content.include? "$THEME$" product["$THEME$"]= theme end while raw_content.include? "$TIME$" time = DateTime.now cdt = time.strftime "%d/%m/%Y %H:%M:%S" product["$TIME$"]= cdt end while raw_content.include? "$RUBY$" product["$RUBY$"]= RUBY_VERSION end handle = file handle["input"]= "output" handle[".md"]= ".html" IO.write(handle, product) end