wip: page layouts, dark mode, header

This commit is contained in:
sloane 2024-02-23 22:41:26 -05:00
parent 0d7b9ce002
commit 38f8208a44
7 changed files with 55 additions and 25 deletions

View file

@ -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)}")

View file

@ -2,15 +2,30 @@ defmodule SloaneSH.Layouts.Partials do
@moduledoc """
HTML partials for use in HTML layouts
"""
require EEx
def header(_ctx) do
~s"""
<header>
EEx.function_from_string(
:def,
: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">
<a href="/">home</a>
<a href="/about">about</a>
<a href="/" class="<%= cx("underline": attrs[:permalink] == "/") %>">home</a>
<a href="/about" class="<%= cx("underline": attrs[:permalink] == "/about") %>">about</a>
</nav>
</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

View file

@ -20,14 +20,13 @@ defmodule SloaneSH.Watch do
def init(%Context{} = ctx) do
{:ok, watcher_pid} =
FileSystem.start_link(
dirs:
[
dirs: [
# ctx.config.layouts_dir,
"priv/site/layouts",
"lib/sloane_sh/layouts",
ctx.config.pages_dir,
ctx.config.posts_dir
]
|> dbg()
)
: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

View file

@ -1 +1,5 @@
<%= if attrs[:title] do %>
<h2 class="font-sans font-bold text-lg"><%= attrs[:title] %></h2>
<% end %>
<%= inner_content %>

View file

@ -6,8 +6,10 @@
<title>sloane.sh | <%= attrs[:title] %></title>
<link rel="stylesheet" href="/assets/app.css" />
</head>
<body class="w-full max-w-3xl">
<%= header(ctx) %>
<body class="w-full max-w-3xl bg-white text-black dark:bg-neutral-800 dark:text-neutral-100">
<%= header(ctx, attrs) %>
<main class="font-serif mt-6">
<%= inner_content %>
</main>
</body>
</html>

View file

@ -1 +1,6 @@
+++
permalink = "/about"
title = "about"
+++
Yes it does!!

View file

@ -1,3 +1,7 @@
# Test Post
+++
title = "Test Post"
+++
this is just a test of the posts functionality
Does this work ?