motyl

Opinionated blog-aware static site generator written in Ruby
Log | Files | Refs | README | LICENSE

commit bd4d9c6c062138e6260e0dc9847dd59b88e77707
parent e3e2e735f8b5707e5d2b6e0de26d206ffb3530d8
Author: Frederic Cambus <fred@statdns.com>
Date:   Tue, 13 Mar 2018 11:51:11 +0100

Use two spaces per indentation level instead of tabs

Diffstat:
Msrc/motyl.rb | 104++++++++++++++++++++++++++++++++++++++++----------------------------------------
1 file changed, 52 insertions(+), 52 deletions(-)

diff --git a/src/motyl.rb b/src/motyl.rb @@ -19,12 +19,12 @@ require 'yaml' # Load and process Markdown file def loadMD(path) - return Kramdown::Document.new(File.read(path)).to_html + return Kramdown::Document.new(File.read(path)).to_html end # Display status message def status(message) - puts("[" + Time.now.strftime("%X") + "] " + message) + puts("[" + Time.now.strftime("%X") + "] " + message) end # Loading configuration @@ -38,54 +38,54 @@ data["site"]["categories"] = {} # Loading templates templates = { - "categories" => File.read("themes/templates/categories.mustache"), - "atom" => File.read("themes/templates/atom.mustache"), - "pages" => File.read("themes/templates/page.mustache"), - "posts" => File.read("themes/templates/post.mustache") + "categories" => File.read("themes/templates/categories.mustache"), + "atom" => File.read("themes/templates/atom.mustache"), + "pages" => File.read("themes/templates/page.mustache"), + "posts" => File.read("themes/templates/post.mustache") } class Mustache - self.template_path = "themes/templates/" + self.template_path = "themes/templates/" end def render(directory, templates, data) - Dir.foreach(directory) do |file| - next if file == '.' or file == '..' - extension = File.extname(file) - - if extension == ".md" - basename = File.basename(file, extension) - data["page"] = YAML.load_file(directory + "/" + basename + ".yaml") - data["page"]["content"] = Mustache.render(loadMD(directory + "/" + file), data) - if data["page"]["url"].nil? - data["page"]["url"] = basename + "/" - end - - status("Rendering " + data["page"]["url"]) - - if directory == "posts" then - data["page"]["datetime"] = DateTime.parse(data["page"]["date"]) - - data["site"]["posts"].push(data["page"]) - - data["page"]["categoryDisplay"] = [] - - # Populate category table - data["page"]["categories"].each do |category| - if data["site"]["categories"][category].nil? - data["site"]["categories"][category] = [] - end - data["site"]["categories"][category].push(data["page"]) - data["page"]["categoryDisplay"].push({ "category" => category, "url" => data["site"]["categoryMap"][category]}) - end - end - - Dir.mkdir("public/" + data["page"]["url"]) unless Dir.exist?("public/" + data["page"]["url"]) - File.write("public/" + data["page"]["url"] + "index.html", Mustache.render(templates[directory], data)) - - data["page"] = {} - end - end + Dir.foreach(directory) do |file| + next if file == '.' or file == '..' + extension = File.extname(file) + + if extension == ".md" + basename = File.basename(file, extension) + data["page"] = YAML.load_file(directory + "/" + basename + ".yaml") + data["page"]["content"] = Mustache.render(loadMD(directory + "/" + file), data) + if data["page"]["url"].nil? + data["page"]["url"] = basename + "/" + end + + status("Rendering " + data["page"]["url"]) + + if directory == "posts" then + data["page"]["datetime"] = DateTime.parse(data["page"]["date"]) + + data["site"]["posts"].push(data["page"]) + + data["page"]["categoryDisplay"] = [] + + # Populate category table + data["page"]["categories"].each do |category| + if data["site"]["categories"][category].nil? + data["site"]["categories"][category] = [] + end + data["site"]["categories"][category].push(data["page"]) + data["page"]["categoryDisplay"].push({ "category" => category, "url" => data["site"]["categoryMap"][category]}) + end + end + + Dir.mkdir("public/" + data["page"]["url"]) unless Dir.exist?("public/" + data["page"]["url"]) + File.write("public/" + data["page"]["url"] + "index.html", Mustache.render(templates[directory], data)) + + data["page"] = {} + end + end end # Render posts @@ -109,14 +109,14 @@ data["page"] = {} Dir.mkdir("public/categories") unless Dir.exist?("public/categories") data["site"]["categories"].keys.each do |category| - categoryURL = data["site"]["categoryMap"][category] + "/" + categoryURL = data["site"]["categoryMap"][category] + "/" - data["site"]["categories"][category] = data["site"]["categories"][category].sort { |a,b| b["date"] <=> a["date"] } - data["page"]["title"] = category - data["page"]["url"] = "categories/" + categoryURL - data["site"]["posts"] = data["site"]["categories"][category] + data["site"]["categories"][category] = data["site"]["categories"][category].sort { |a,b| b["date"] <=> a["date"] } + data["page"]["title"] = category + data["page"]["url"] = "categories/" + categoryURL + data["site"]["posts"] = data["site"]["categories"][category] - Dir.mkdir("public/categories/" + categoryURL) unless Dir.exist?("public/categories/" + categoryURL) - File.write("public/categories/" + categoryURL + "index.html", Mustache.render(templates["categories"], data)) - status("Rendering " + categoryURL) + Dir.mkdir("public/categories/" + categoryURL) unless Dir.exist?("public/categories/" + categoryURL) + File.write("public/categories/" + categoryURL + "index.html", Mustache.render(templates["categories"], data)) + status("Rendering " + categoryURL) end