require "markd" require "dir" require "file" require "path" begin Dir.mkdir_p Path["dist/static"] rescue if !Dir.exists? Path["dist/static"] puts "Could not create required folders. Exiting." exit 1 end end Base = begin if File.file? "base.html" File.read "base.html" elsif File.file? Path[ENV["HOME"]+"/.config/blogtool/base.html"] File.read Path[ENV["HOME"]+"/.config/blogtool/base.html"] elsif File.file? Path["/etc/blogtool/base.html"] File.read Path["/etc/blogtool/base.html"] else puts "Can't find base.html" exit 1 end end BaseCSS = begin if File.file? Path[ENV["HOME"]+"/.config/blogtool/styles.css"] File.read Path[ENV["HOME"]+"/.config/blogtool/styles.css"] elsif File.file? Path["/etc/blogtool/styles.css"] File.read Path["/etc/blogtool/styles.css"] else "" end end def render_file(filename : String | Path) Base.sub("## CONTENT", Markd.to_html(File.read(filename), Markd::Options.new(smart: true, safe: false))) end index = Base content = "" Dir.entries("articles").select{ |i| i != "." && i != ".." }.each do |article| if article[article.size-3, article.size] == ".md" File.write Path.new("dist", article[0,article.size-3]+".html"), render_file("articles/"+article) content += "