defmodule Blogue do @moduledoc """ """ @doc """ """ def build_home(index_path) do posts_meta = posts(Path.join(Path.dirname(index_path), "post")) |> Enum.map(&meta/1) built_html = index_path |> EEx.eval_file(posts: posts_meta) File.write(Path.join(Path.dirname(index_path), "index.html"), built_html) end def posts(posts_path) do File.ls!(posts_path) |> Enum.map(&Path.join(posts_path, &1)) end def meta(post_path) do parsed_page = Path.join(post_path, "index.html") |> File.read!() |> Floki.parse() title = parsed_page |> Floki.find("title") |> Floki.text() date = parsed_page |> Floki.find("meta") |> Enum.map( &[name: hd(Floki.attribute(&1, "name")), content: hd(Floki.attribute(&1, "content"))] ) |> Enum.filter(&(&1[:name] == "date")) |> hd [href: String.slice(post_path, 1..-1), title: title, date: date[:content]] end end 0