wip: page layouts, dark mode, header
This commit is contained in:
parent
0d7b9ce002
commit
38f8208a44
7 changed files with 55 additions and 25 deletions
|
@ -45,7 +45,9 @@ defmodule SloaneSH.Build do
|
||||||
|
|
||||||
with {:ok, data} <- File.read(path),
|
with {:ok, data} <- File.read(path),
|
||||||
{:ok, md} <- Markdown.transform(ctx, data),
|
{: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}")
|
Logger.info("Built post: #{post}")
|
||||||
else
|
else
|
||||||
err -> Logger.error("Failed to build post #{post}: #{inspect(err)}")
|
err -> Logger.error("Failed to build post #{post}: #{inspect(err)}")
|
||||||
|
|
|
@ -2,15 +2,30 @@ defmodule SloaneSH.Layouts.Partials do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
HTML partials for use in HTML layouts
|
HTML partials for use in HTML layouts
|
||||||
"""
|
"""
|
||||||
|
require EEx
|
||||||
|
|
||||||
def header(_ctx) do
|
EEx.function_from_string(
|
||||||
~s"""
|
:def,
|
||||||
<header>
|
:header,
|
||||||
|
~S"""
|
||||||
|
<header class="flex flex-col gap-2">
|
||||||
|
<a href="/"><h1 class="text-xl">sloane.sh</h1></a>
|
||||||
<nav class="flex flex-row gap-2">
|
<nav class="flex flex-row gap-2">
|
||||||
<a href="/">home</a>
|
<a href="/" class="<%= cx("underline": attrs[:permalink] == "/") %>">home</a>
|
||||||
<a href="/about">about</a>
|
<a href="/about" class="<%= cx("underline": attrs[:permalink] == "/about") %>">about</a>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
"""
|
""",
|
||||||
|
[: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
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,14 +20,13 @@ defmodule SloaneSH.Watch do
|
||||||
def init(%Context{} = ctx) do
|
def init(%Context{} = ctx) do
|
||||||
{:ok, watcher_pid} =
|
{:ok, watcher_pid} =
|
||||||
FileSystem.start_link(
|
FileSystem.start_link(
|
||||||
dirs:
|
dirs: [
|
||||||
[
|
|
||||||
# ctx.config.layouts_dir,
|
# ctx.config.layouts_dir,
|
||||||
"priv/site/layouts",
|
"priv/site/layouts",
|
||||||
|
"lib/sloane_sh/layouts",
|
||||||
ctx.config.pages_dir,
|
ctx.config.pages_dir,
|
||||||
ctx.config.posts_dir
|
ctx.config.posts_dir
|
||||||
]
|
]
|
||||||
|> dbg()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
:ok = FileSystem.subscribe(watcher_pid)
|
:ok = FileSystem.subscribe(watcher_pid)
|
||||||
|
@ -50,8 +49,6 @@ defmodule SloaneSH.Watch do
|
||||||
|
|
||||||
@impl GenServer
|
@impl GenServer
|
||||||
def handle_info({:file_event, pid, {path, events}}, %{ctx: ctx, watcher_pid: pid} = state) do
|
def handle_info({:file_event, pid, {path, events}}, %{ctx: ctx, watcher_pid: pid} = state) do
|
||||||
dbg(path)
|
|
||||||
|
|
||||||
if String.match?(path, ~r/layouts/) do
|
if String.match?(path, ~r/layouts/) do
|
||||||
recompile_layouts()
|
recompile_layouts()
|
||||||
Build.run(ctx)
|
Build.run(ctx)
|
||||||
|
@ -78,8 +75,9 @@ defmodule SloaneSH.Watch do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp recompile_layouts do
|
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()
|
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
|
:ok
|
||||||
end
|
end
|
||||||
|
|
|
@ -1 +1,5 @@
|
||||||
|
<%= if attrs[:title] do %>
|
||||||
|
<h2 class="font-sans font-bold text-lg"><%= attrs[:title] %></h2>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<%= inner_content %>
|
<%= inner_content %>
|
||||||
|
|
|
@ -6,8 +6,10 @@
|
||||||
<title>sloane.sh | <%= attrs[:title] %></title>
|
<title>sloane.sh | <%= attrs[:title] %></title>
|
||||||
<link rel="stylesheet" href="/assets/app.css" />
|
<link rel="stylesheet" href="/assets/app.css" />
|
||||||
</head>
|
</head>
|
||||||
<body class="w-full max-w-3xl">
|
<body class="w-full max-w-3xl bg-white text-black dark:bg-neutral-800 dark:text-neutral-100">
|
||||||
<%= header(ctx) %>
|
<%= header(ctx, attrs) %>
|
||||||
|
<main class="font-serif mt-6">
|
||||||
<%= inner_content %>
|
<%= inner_content %>
|
||||||
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1 +1,6 @@
|
||||||
|
+++
|
||||||
|
permalink = "/about"
|
||||||
|
title = "about"
|
||||||
|
+++
|
||||||
|
|
||||||
Yes it does!!
|
Yes it does!!
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
# Test Post
|
+++
|
||||||
|
title = "Test Post"
|
||||||
|
+++
|
||||||
|
|
||||||
this is just a test of the posts functionality
|
this is just a test of the posts functionality
|
||||||
|
|
||||||
|
Does this work ?
|
||||||
|
|
Loading…
Reference in a new issue