2021-09-19 19:35:36 +01:00
|
|
|
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 + "/"
|
|
|
|
|
2021-09-20 16:50:38 +01:00
|
|
|
protocol = "https://"
|
2021-09-19 19:35:36 +01:00
|
|
|
|
|
|
|
da = ["<a href=\"" + protocol + site_domain + "\">home</a> "]
|
|
|
|
dp = ["<p><a href=\"" + protocol + site_domain + "\">home</a></p>"]
|
|
|
|
dsa = ["<a href=\"" + protocol + site_domain + "\">/</a> "]
|
|
|
|
dsp = ["<p><a href=\"" + protocol + site_domain + "\">/</a></p>"]
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-11-13 13:53:44 +00:00
|
|
|
procfiles = Marshal.load(Marshal.dump(files))
|
|
|
|
|
2021-09-19 19:35:36 +01:00
|
|
|
for file in directory
|
|
|
|
file1 = "/" + file
|
|
|
|
file1["input/"]= ""
|
|
|
|
file2 = file1[1..-1]
|
|
|
|
file2["/"]= ""
|
|
|
|
da.append("<a href=\"" + protocol + site_domain + file1 + "\">" + file2 + "</a> ")
|
|
|
|
dp.append("<p><a href=\"" + protocol + site_domain + file1 + "\">" + file2 + "</a></p>")
|
|
|
|
dsa.append("<a href=\"" + protocol + site_domain + file1 + "\">" + file2 + "/</a> ")
|
|
|
|
dsp.append("<p><a href=\"" + protocol + site_domain + file1 + "\">" + file2 + "/</a></p>")
|
|
|
|
end
|
|
|
|
|
|
|
|
for file in structure
|
|
|
|
handle = file
|
|
|
|
handle["input/"]= ""
|
|
|
|
|
|
|
|
comb = "output/" + handle
|
|
|
|
Dir.mkdir comb unless Dir.exists? comb
|
|
|
|
end
|
|
|
|
|
|
|
|
for file in files
|
2021-11-13 13:53:44 +00:00
|
|
|
if(File.exist?('input/inclusions.conf'))
|
|
|
|
list = IO.readlines("input/inclusions.conf", chomp: true)
|
|
|
|
for ext in list
|
|
|
|
if file.include? ext
|
|
|
|
handle = File.read(file)
|
|
|
|
|
|
|
|
output = file
|
|
|
|
output["input"]= "output"
|
|
|
|
IO.write(output, handle)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
handle = File.read(file)
|
|
|
|
|
|
|
|
output = file
|
|
|
|
output["input"]= "output"
|
|
|
|
IO.write(output, handle)
|
|
|
|
end
|
2021-09-19 19:35:36 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def scope
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
|
2021-11-13 13:53:44 +00:00
|
|
|
if(File.exist?('input/preproc.conf'))
|
|
|
|
list = IO.readlines("input/preproc.conf", chomp: true)
|
|
|
|
for proc in list
|
|
|
|
if(File.exist?('proc/' + proc +'/pre.sh'))
|
|
|
|
for file in procfiles
|
|
|
|
runner = `proc/#{proc}/pre.sh #{file}`
|
|
|
|
puts runner
|
|
|
|
end
|
|
|
|
else
|
|
|
|
puts proc +" does not support being used as a pre-processor."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-19 19:35:36 +01:00
|
|
|
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)
|
|
|
|
|
2021-09-20 17:29:37 +01:00
|
|
|
if product.include? "{SITE_NAME}"
|
2021-09-20 17:25:26 +01:00
|
|
|
while product.include? "{SITE_NAME}"
|
2021-09-19 19:35:36 +01:00
|
|
|
product["{SITE_NAME}"]= site_name
|
2021-09-20 17:29:37 +01:00
|
|
|
end
|
2021-09-19 19:35:36 +01:00
|
|
|
end
|
|
|
|
|
2021-09-20 17:29:37 +01:00
|
|
|
if product.include? "{SITE_DOMAIN}"
|
2021-09-20 17:25:26 +01:00
|
|
|
while product.include? "{SITE_DOMAIN}"
|
2021-09-19 19:35:36 +01:00
|
|
|
product["{SITE_DOMAIN}"]= site_domain
|
|
|
|
end
|
2021-09-20 17:29:37 +01:00
|
|
|
end
|
2021-09-19 19:35:36 +01:00
|
|
|
|
2021-09-20 17:29:37 +01:00
|
|
|
if product.include? "{PAGE_TITLE}"
|
2021-09-20 17:25:26 +01:00
|
|
|
while product.include? "{PAGE_TITLE}"
|
2021-09-19 19:35:36 +01:00
|
|
|
product["{PAGE_TITLE}"]= title
|
2021-09-20 17:29:37 +01:00
|
|
|
end
|
2021-09-19 19:35:36 +01:00
|
|
|
end
|
|
|
|
|
2021-09-20 17:29:37 +01:00
|
|
|
if product.include? "{DIRECTORY_A}"
|
2021-09-20 17:25:26 +01:00
|
|
|
while product.include? "{DIRECTORY_A}"
|
2021-09-19 19:35:36 +01:00
|
|
|
product["{DIRECTORY_A}"]= da.join()
|
2021-09-20 17:29:37 +01:00
|
|
|
end
|
2021-09-19 19:35:36 +01:00
|
|
|
end
|
|
|
|
|
2021-09-20 17:29:37 +01:00
|
|
|
if product.include? "{DIRECTORY_P}"
|
2021-09-20 17:25:26 +01:00
|
|
|
while product.include? "{DIRECTORY_P}"
|
2021-09-19 19:35:36 +01:00
|
|
|
product["{DIRECTORY_P}"]= dp.join()
|
2021-09-20 17:29:37 +01:00
|
|
|
end
|
2021-09-19 19:35:36 +01:00
|
|
|
end
|
|
|
|
|
2021-09-20 17:29:37 +01:00
|
|
|
if product.include? "{DIRECTORY_SLASH_A}"
|
2021-09-20 17:25:26 +01:00
|
|
|
while product.include? "{DIRECTORY_SLASH_A}"
|
2021-09-19 19:35:36 +01:00
|
|
|
product["{DIRECTORY_SLASH_A}"]= dsa.join()
|
2021-09-20 17:29:37 +01:00
|
|
|
end
|
2021-09-19 19:35:36 +01:00
|
|
|
end
|
|
|
|
|
2021-09-20 17:29:37 +01:00
|
|
|
if product.include? "{DIRECTORY_SLASH_P}"
|
2021-09-20 17:25:26 +01:00
|
|
|
while product.include? "{DIRECTORY_SLASH_P}"
|
2021-09-19 19:35:36 +01:00
|
|
|
product["{DIRECTORY_SLASH_P}"]= dsp.join()
|
2021-09-20 17:29:37 +01:00
|
|
|
end
|
2021-09-19 19:35:36 +01:00
|
|
|
end
|
|
|
|
|
2021-09-20 17:29:37 +01:00
|
|
|
if product.include? "{PAGE_CONTENT}"
|
2021-09-20 17:25:26 +01:00
|
|
|
while product.include? "{PAGE_CONTENT}"
|
2021-09-19 19:35:36 +01:00
|
|
|
product["{PAGE_CONTENT}"]= content
|
2021-09-20 17:29:37 +01:00
|
|
|
end
|
2021-09-19 19:35:36 +01:00
|
|
|
end
|
|
|
|
|
2021-09-20 17:29:37 +01:00
|
|
|
if product.include? "$EWFM$"
|
|
|
|
while product.include? "$EWFM$"
|
2021-09-19 19:35:36 +01:00
|
|
|
product["$EWFM$"]= "<p>This page has been generated by ewfm using the " + theme + " theme!</p>"
|
2021-09-20 17:29:37 +01:00
|
|
|
end
|
2021-09-19 19:35:36 +01:00
|
|
|
end
|
|
|
|
|
2021-09-20 17:29:37 +01:00
|
|
|
if product.include? "$THEME$"
|
|
|
|
while product.include? "$THEME$"
|
2021-09-19 19:35:36 +01:00
|
|
|
product["$THEME$"]= theme
|
|
|
|
end
|
2021-09-20 17:29:37 +01:00
|
|
|
end
|
2021-09-19 19:35:36 +01:00
|
|
|
|
2021-09-20 17:29:37 +01:00
|
|
|
if product.include? "$TIME$"
|
|
|
|
while product.include? "$TIME$"
|
2021-09-19 19:35:36 +01:00
|
|
|
time = DateTime.now
|
|
|
|
cdt = time.strftime "%d/%m/%Y %H:%M:%S"
|
|
|
|
product["$TIME$"]= cdt
|
|
|
|
end
|
2021-09-20 17:29:37 +01:00
|
|
|
end
|
2021-09-19 19:35:36 +01:00
|
|
|
|
2021-09-20 17:29:37 +01:00
|
|
|
if product.include? "$RUBY$"
|
|
|
|
while product.include? "$RUBY$"
|
2021-09-19 19:35:36 +01:00
|
|
|
product["$RUBY$"]= RUBY_VERSION
|
|
|
|
end
|
2021-09-20 17:29:37 +01:00
|
|
|
end
|
2021-09-19 19:35:36 +01:00
|
|
|
|
|
|
|
handle = file
|
|
|
|
handle["input"]= "output"
|
|
|
|
handle[".md"]= ".html"
|
|
|
|
IO.write(handle, product)
|
|
|
|
end
|
2021-11-13 13:53:44 +00:00
|
|
|
|
|
|
|
if(File.exist?('input/postproc.conf'))
|
|
|
|
list = IO.readlines("input/postproc.conf", chomp: true)
|
|
|
|
for proc in list
|
|
|
|
if(File.exist?('proc/' + proc +'/post.sh'))
|
|
|
|
for file in procfiles
|
|
|
|
runner = `proc/#{proc}/post.sh #{file}`
|
|
|
|
puts runner
|
|
|
|
end
|
|
|
|
else
|
|
|
|
puts proc +" does not support being used as a post-processor."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|