parent
e9a6a6bf2e
commit
1faa875989
@ -1 +1,4 @@ |
||||
blogtool |
||||
blogtool |
||||
lib |
||||
shard.lock |
||||
testsite/dist |
@ -1,13 +1,56 @@ |
||||
require "markd" |
||||
require "dir" |
||||
require "file" |
||||
require "path" |
||||
|
||||
begin |
||||
Dir.mkdir "dist" |
||||
Dir.mkdir_p Path["dist/static"] |
||||
rescue |
||||
if !Dir.exists? Path["dist/static"] |
||||
puts "Could not create required folders. Exiting." |
||||
exit 1 |
||||
end |
||||
end |
||||
|
||||
articles = Dir.entries "articles" |
||||
articles = articles.select { |i| i != "." && i != ".." } |
||||
puts articles |
||||
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+Markd.to_html(File.read(filename), Markd::Options.new(smart: true, safe: false))+"</body></html>" |
||||
end |
||||
|
||||
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) |
||||
else |
||||
File.write Path.new("dist", article+".html"), render_file("articles/"+article) |
||||
end |
||||
end |
||||
|
||||
Dir.entries("assets").select{ |i| i != "." && i != ".." }.each do |asset| |
||||
File.copy Path.new("assets", asset), Path.new("dist", "static", asset) |
||||
end |
||||
|
||||
#print Markd.to_html(text, Markd::Options.new(smart: true, safe: false)); |
||||
File.write Path.new("dist", "static", "styles.css"), BaseCSS+File.read("styles.css") |
||||
File.write Path.new("dist", "about.html"), render_file("about.md") |
||||
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
Loading…
Reference in new issue