 
       File.mkdir_p! "#{dest}"
       IO.puts "Created directory `#{dest}`."
+
+      dest |> File.ls!
+           |> Enum.map(&("#{dest}#{&1}"))
+           |> Enum.each(&(File.rm_rf! &1))
 
       {time, _} = :timer.tc(fn ->
         compile_nav

    template = Agent.get Global, &(Map.get &1, "template_page")
    info = Agent.get Global, &(Map.get &1, :pageinfo)

    IO.puts "Cleaning pages..."

    dest
    |> File.ls!
    |> Enum.filter(&(String.ends_with? &1, ".html"))
    |> Enum.each(&(File.rm_rf! "#{dest}#{&1}"))

    case mode do
      :parallel ->
        info

    html = template
           |> render([contents: html])
           |> genpage([page_title: info.title])
    [_|subdir] = info.name |> String.split("/") |> Enum.reverse
    subdir = case subdir do
      [] -> ""
      [x] -> x <> "/"
      [_|_] -> (subdir |> Enum.reverse |> Enum.join("/")) <> "/"
    end
    if subdir != "", do: File.mkdir_p! "#{dest}#{subdir}"
    File.open! "#{dest}#{info.name}.html", [:write, :utf8], fn device ->
      IO.write device, html
    end
