diff --git a/docs/images/favicon.ico b/docs/images/favicon.ico deleted file mode 100644 index 7f372bf..0000000 Binary files a/docs/images/favicon.ico and /dev/null differ diff --git a/lib/mix/tasks/build_static.ex b/lib/mix/tasks/build_static.ex index 9537873..f035c5d 100644 --- a/lib/mix/tasks/build_static.ex +++ b/lib/mix/tasks/build_static.ex @@ -4,50 +4,43 @@ defmodule Mix.Tasks.BuildStatic do @shortdoc "Builds the static content" def run(_args) do + IO.puts("Booting app") Mix.Task.run("app.start") - IO.puts("Building static site...") + IO.puts("Start building /docs static") + + IO.puts("Create directory") build_dir = "build" File.rm_rf!(build_dir) File.mkdir_p!(build_dir) + IO.puts("Create static pages") generate_page("/", "index.html", build_dir) generate_page("/resume_technical", "resume_technical.html", build_dir) - generate_posts(build_dir) - copy_assets(build_dir) - - IO.puts("Static site generated in #{build_dir}/") - end - - defp generate_page(path, filename, build_dir) do - conn = build_conn(path) - content = conn.resp_body - File.write!(Path.join(build_dir, filename), content) - IO.puts("Generated #{filename}") - end - - defp generate_posts(build_dir) do - posts = PgBlog.Blog.all_posts() - Enum.each(posts, fn post -> + IO.puts("Create posts - add them in priv/posts/") + PgBlog.Blog.all_posts() + |> Enum.each(fn post -> path = "/posts/#{post.id}" filename = "#{post.id}.html" generate_page(path, filename, build_dir) end) + + IO.puts("Copy assets") + File.cp_r!("priv/static/.", build_dir) + + IO.puts("Finished building /docs") end - defp build_conn(path) do + defp generate_page(path, filename, build_dir) do conn = Plug.Test.conn(:get, path) - PgBlogWeb.Endpoint.call(conn, []) - end + %{resp_body: body} = PgBlogWeb.Endpoint.call(conn, []) - defp copy_assets(build_dir) do - # Instead of all assets, maybe just copy what we need, which isn't a lot. - # TODO: HERE - File.cp_r!("priv/static/.", build_dir) + build_dir + |> Path.join(filename) + |> File.write!(body) - File.cp("priv/static/favicon.ico", Path.join([build_dir, "images", "favicon.ico"])) - |> IO.inspect(label: "cp") + IO.puts("Created #{filename}") end end