~michalr/blog2gmi

423d86c2ccbb5ec1e343c20194bfbfb43648b773 — MichaƂ Rudowicz 3 years ago d17ca5a
Preparations for actual gmi file output
1 files changed, 10 insertions(+), 2 deletions(-)

M src/main.cr
M src/main.cr => src/main.cr +10 -2
@@ 7,10 7,12 @@ require "option_parser"
require "crustache"

posts_dir = "."
output_dir = nil

OptionParser.parse do |parser|
  parser.banner = "Usage: blog2gmi [arguments]"
  parser.on("-p PATH", "--posts-dir=PATH", "Path to directory with Jekyll posts") { |dir| posts_dir = dir }
  parser.on("-o PATH", "--out=PATH", "Path to directory where the output will be generated") { |dir| output_dir = dir }
  parser.on("-h", "--help", "Show this help") do
    puts parser
    exit


@@ 47,6 49,10 @@ entries_list = Dir.new(posts_dir).entries
  end
  .sort { |a, b| b[2] <=> a[2] } # newest to oldest
  .map do |fname, front_matter, article_date, rendered|
    out_filename = fname.rpartition(".")[0] + ".gmi"
    {out_filename, front_matter, article_date, rendered}
  end
  .map do |fname, front_matter, article_date, rendered|
    {
      "url"      => fname,
      "title"    => front_matter["title"],


@@ 60,6 66,8 @@ entries_list = Dir.new(posts_dir).entries
model = {
  "entries" => entries_list,
}
template = Crustache.parse front_matter_tpl()

puts Crustache.render template, model
# File.open(Path.new(output_dir, "index.gmi"), "w") do |file|
template = Crustache.parse front_matter_tpl()
puts(Crustache.render(template, model))
# end