~mika/www.m1kadev.nl

ref: 864f33dd4b323f6832ebe0e31c519e98a0287257 www.m1kadev.nl/kethel/lib/blog.ex -rw-r--r-- 741 bytes
864f33dd — m1ka fix greets on mobile (i think) a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
defmodule Blog do
  def collect(project_root, bricks) do
    files =
      Path.wildcard(project_root <> "/blog/*.fxg")
      |> Map.new(fn x -> {FileX.trimmed_filename(x), File.read!(x)} end)

    # no blog posts yet so we return nothing

    %{
      output_dir: "#{project_root}/build/blog",
      main_template: File.read!(project_root <> "/templates/base.thtml"),
      bricks: bricks
    }
  end

  def compile(blog) do
    File.mkdir_p!("#{blog.output_dir}")

    index = "<h1>my blog ^w^</h1> <p>comig son :3</p>"

    File.write!(
      "#{blog.output_dir}/index.html",
      Mustache.render(blog.main_template, Map.merge(%{fxg_content: index}, blog.bricks))
    )

    IO.puts("[GENERATE] #{blog.output_dir}/index.html")
  end
end