~michalr/blog2gmi

5aa810f94cb728667f6d1a8e378ff2c765b82927 — Michał Rudowicz 2 years ago 423d86c
Initial generation of gmi output
2 files changed, 34 insertions(+), 4 deletions(-)

M src/main.cr
M src/templates.cr
M src/main.cr => src/main.cr +20 -4
@@ 67,7 67,23 @@ model = {
  "entries" => entries_list,
}

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

if output_dir.is_a?(String)
  output_dir_s = output_dir.as(String)
else
  STDERR.puts("Output directory not specified! Use -o")
  exit(1)
end

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

entry_template = Crustache.parse(entry_tpl())
model["entries"].map_parallel do |entry|
  File.open(Path.new(output_dir_s, entry["url"].as(String)), "w") do |file|
    file.puts(Crustache.render(entry_template, entry))
  end
end

M src/templates.cr => src/templates.cr +14 -0
@@ 13,3 13,17 @@ This is basically a Gemini version of my blog:
{{/entries}}
FRONT_MATTER_TPL
end

def entry_tpl
  tpl = <<-ENTRY_TPL
# {{title}} - fleg gemlog

=> index.gmi - Back to main page

## Gemlog entries

{{rendered}}

=> index.gmi - Back to main page
ENTRY_TPL
end