diff --git a/lib/sloane_sh/build.ex b/lib/sloane_sh/build.ex index 13af566..b5ad1ae 100644 --- a/lib/sloane_sh/build.ex +++ b/lib/sloane_sh/build.ex @@ -45,7 +45,9 @@ defmodule SloaneSH.Build do with {:ok, data} <- File.read(path), {:ok, md} <- Markdown.transform(ctx, data), - :ok <- Write.post(ctx, post, md.html) do + contents = Layouts.post_layout(ctx, md.attrs, md.html), + html = Layouts.root_layout(ctx, md.attrs, contents), + :ok <- Write.post(ctx, post, html) do Logger.info("Built post: #{post}") else err -> Logger.error("Failed to build post #{post}: #{inspect(err)}") diff --git a/lib/sloane_sh/layouts/partials.ex b/lib/sloane_sh/layouts/partials.ex index 1c1f75c..28e7e3a 100644 --- a/lib/sloane_sh/layouts/partials.ex +++ b/lib/sloane_sh/layouts/partials.ex @@ -2,15 +2,30 @@ defmodule SloaneSH.Layouts.Partials do @moduledoc """ HTML partials for use in HTML layouts """ + require EEx - def header(_ctx) do - ~s""" -
- -
- """ + EEx.function_from_string( + :def, + :header, + ~S""" +
+

sloane.sh

+ +
+ """, + [:ctx, :attrs] + ) + + defp cx(classes) do + classes + |> Enum.map(fn + {_, _} = t -> t + c -> {c, true} + end) + |> Enum.filter(fn {_, v} -> !!v end) + |> Enum.map_join(" ", fn {class, _} -> class end) end end diff --git a/lib/sloane_sh/watch.ex b/lib/sloane_sh/watch.ex index 11754de..d96e37c 100644 --- a/lib/sloane_sh/watch.ex +++ b/lib/sloane_sh/watch.ex @@ -20,14 +20,13 @@ defmodule SloaneSH.Watch do def init(%Context{} = ctx) do {:ok, watcher_pid} = FileSystem.start_link( - dirs: - [ - # ctx.config.layouts_dir, - "priv/site/layouts", - ctx.config.pages_dir, - ctx.config.posts_dir - ] - |> dbg() + dirs: [ + # ctx.config.layouts_dir, + "priv/site/layouts", + "lib/sloane_sh/layouts", + ctx.config.pages_dir, + ctx.config.posts_dir + ] ) :ok = FileSystem.subscribe(watcher_pid) @@ -50,8 +49,6 @@ defmodule SloaneSH.Watch do @impl GenServer def handle_info({:file_event, pid, {path, events}}, %{ctx: ctx, watcher_pid: pid} = state) do - dbg(path) - if String.match?(path, ~r/layouts/) do recompile_layouts() Build.run(ctx) @@ -78,8 +75,9 @@ defmodule SloaneSH.Watch do end defp recompile_layouts do + partials_source = Layouts.Partials.module_info(:compile)[:source] |> List.to_string() layouts_source = Layouts.module_info(:compile)[:source] |> List.to_string() - {:ok, _, _} = Kernel.ParallelCompiler.compile([layouts_source]) + {:ok, _, _} = Kernel.ParallelCompiler.compile([partials_source, layouts_source]) :ok end diff --git a/priv/site/layouts/post.html.eex b/priv/site/layouts/post.html.eex index fb81838..9511d75 100644 --- a/priv/site/layouts/post.html.eex +++ b/priv/site/layouts/post.html.eex @@ -1 +1,5 @@ +<%= if attrs[:title] do %> +

<%= attrs[:title] %>

+<% end %> + <%= inner_content %> diff --git a/priv/site/layouts/root.html.eex b/priv/site/layouts/root.html.eex index d337acb..725eda9 100644 --- a/priv/site/layouts/root.html.eex +++ b/priv/site/layouts/root.html.eex @@ -6,8 +6,10 @@ sloane.sh | <%= attrs[:title] %> - - <%= header(ctx) %> - <%= inner_content %> + + <%= header(ctx, attrs) %> +
+ <%= inner_content %> +
diff --git a/priv/site/pages/about.md b/priv/site/pages/about.md index 489193a..8920003 100644 --- a/priv/site/pages/about.md +++ b/priv/site/pages/about.md @@ -1 +1,6 @@ ++++ +permalink = "/about" +title = "about" ++++ + Yes it does!! diff --git a/priv/site/posts/2024-02-16-test-post.md b/priv/site/posts/2024-02-16-test-post.md index be6ab48..c4bc5cc 100644 --- a/priv/site/posts/2024-02-16-test-post.md +++ b/priv/site/posts/2024-02-16-test-post.md @@ -1,3 +1,7 @@ -# Test Post ++++ +title = "Test Post" ++++ this is just a test of the posts functionality + +Does this work ?