diff --git a/assets/css/app.css b/assets/css/app.css index 732322d..de7531d 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -14,8 +14,7 @@ /* daisyUI Tailwind Plugin. You can update this file by fetching the latest version with: curl -sLO https://github.com/saadeghi/daisyui/releases/latest/download/daisyui.js Make sure to look at the daisyUI changelog: https://daisyui.com/docs/changelog/ */ -@plugin "../vendor/daisyui" { -} +@plugin "../vendor/daisyui" {} @source inline("mr-1"); @source inline("mb-2"); @@ -80,7 +79,6 @@ a { overflow-wrap: anywhere; } -/* This file is for your main application CSS */ code.hljs { color: #cdd6f4; background: transparent; diff --git a/lib/alchemy_pub/engine.ex b/lib/alchemy_pub/engine.ex index 816e3f6..387ba3d 100644 --- a/lib/alchemy_pub/engine.ex +++ b/lib/alchemy_pub/engine.ex @@ -32,7 +32,7 @@ defmodule AlchemyPub.Engine do nil end - defp compile(md) do + defp compile(md, is_deck) do link_headers = fn {h, attrs, content, meta} -> id = urlify(content) @@ -51,6 +51,10 @@ defmodule AlchemyPub.Engine do ], meta}} end + page_split = fn {hr, _attrs, content, meta} -> + {:replace, {hr, [{"class", "split"}], content, meta}} + end + ast = Earmark.as_ast!(md, pure_links: false, @@ -60,17 +64,31 @@ defmodule AlchemyPub.Engine do title = find_h1(ast) + processors = + if is_deck do + [{"hr", page_split}] + else + [{"h2", link_headers}, {"h3", link_headers}] + end + postprocessor = Earmark.Transform.make_postprocessor( - Earmark.Options.make_options!( - registered_processors: [{"h2", link_headers}, {"h3", link_headers}] - ) + Earmark.Options.make_options!(registered_processors: processors) ) - {title, - ast - |> Earmark.Transform.map_ast(postprocessor) - |> Earmark.transform()} + content = + ast + |> Earmark.Transform.map_ast(postprocessor) + |> Earmark.transform() + + content = + if is_deck do + content |> String.split("
") + else + content + end + + {title, content} end def title(filename, h1, frontmatter) do @@ -132,7 +150,7 @@ defmodule AlchemyPub.Engine do Date.new!(y, m, d) end - {h1, content} = compile(md) + {h1, content} = compile(md, is_deck) filename = path |> Path.basename() |> Path.rootname() title = title(filename, h1, frontmatter) diff --git a/lib/alchemy_pub_web/page_live.ex b/lib/alchemy_pub_web/page_live.ex index 64a9d2b..bab4f8e 100644 --- a/lib/alchemy_pub_web/page_live.ex +++ b/lib/alchemy_pub_web/page_live.ex @@ -94,6 +94,17 @@ defmodule AlchemyPubWeb.PageLive do socket = case page do + {title, :deck, _date, meta, content} -> + socket + |> assign( + page_title: meta |> Map.get("title"), + meta: meta, + content: paginate(content, params["p"]), + title: title, + tag: nil, + track_valid: true + ) + {title, _rank, _date, meta, content} -> socket |> assign( @@ -167,6 +178,11 @@ defmodule AlchemyPubWeb.PageLive do end) end + defp paginate(content, page) do + {page, _} = Integer.parse(page || 0) + content |> Enum.at(page) + end + defp build_content(tag, title, all) do (tag && "

Tag: #{title}