From 3020fb369cb40b7ea2971099dbce6ac6b9eca69a Mon Sep 17 00:00:00 2001 From: m1kadev Date: Tue, 27 Jan 2026 22:33:50 +0100 Subject: [PATCH] kethel: final touches --- kethel/lib/scriprs | 0 kethel/lib/thoughts.ex | 25 ++++++++++++++++++++----- kethel/main.exs | 19 +++++++++++++++++++ pages/colophon.fxg | 3 +++ styles/thoughts.css | 6 +++++- templates/inline_thought.thtml | 8 ++++++++ 6 files changed, 55 insertions(+), 6 deletions(-) delete mode 100644 kethel/lib/scriprs create mode 100644 templates/inline_thought.thtml diff --git a/kethel/lib/scriprs b/kethel/lib/scriprs deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/kethel/lib/thoughts.ex b/kethel/lib/thoughts.ex index 4ad401ff7d75498b8964418dd725f7db325dd347..eaa19aab6ada279dd695bcbbe67a45d7489f6930 100644 --- a/kethel/lib/thoughts.ex +++ b/kethel/lib/thoughts.ex @@ -1,5 +1,5 @@ defmodule Thoughts do - defstruct [:thoughts, :template, :bricks, :project_root] + defstruct [:thoughts, :template, :bricks, :project_root, :index_template, :inline_template ] @spec urlify(binary()) :: binary() defp urlify(name) do @@ -21,7 +21,9 @@ defmodule Thoughts do Path.wildcard("#{project_root}/thoughts/*") |> Enum.map(fn path -> {path, get_file_commit_date(path), File.read!(path)} end) |> Enum.sort_by(fn {_, date, _ } -> date end, :desc), + inline_template: File.read!("#{project_root}/templates/inline_thought.thtml"), template: File.read!("#{project_root}/templates/thought.thtml"), + index_template: File.read!("#{project_root}/templates/thoughts.thtml"), bricks: bricks, project_root: project_root } @@ -42,11 +44,25 @@ defmodule Thoughts do compile_file(thought, thoughts.template, thoughts.bricks, thoughts.project_root) end) |> Enum.to_list() - t_end = System.monotonic_time(:millisecond) + # generate index + index_content = thoughts.thoughts + |> Enum.map(fn thought -> inline_thought(thought, thoughts) end) + |> Enum.join() + index = Mustache.render(thoughts.index_template, Map.merge(thoughts.bricks, %{fxg_content: index_content})) + File.write!("#{thoughts.project_root}/build/thoughts/index.html", index) + IO.puts("[COMPILED] #{thoughts.project_root}/build/thoughts/index.html") + t_end = System.monotonic_time(:millisecond) t_end - t_begin end + defp inline_thought({path, date, thought}, context) do + stripped_name = String.replace_prefix(path, "#{context.project_root}/thoughts/", "") + location = "https://m1kadev.nl/thoughts/#{urlify(stripped_name)}.html" + title = "#{stripped_name}" + Mustache.render(context.inline_template, %{name: title, date: date, thought: thought}) + end + defp compile_file({path, date, thought}, template, bricks, project_root) do name = trim_abs_path(path, project_root) output_path = "#{project_root}/build/thoughts/#{urlify(name)}.html" @@ -58,7 +74,6 @@ defmodule Thoughts do def get_file_commit_date(path) do {ts_string, 0} = System.cmd("git", ["log", "--format=%ct", path]) - String.trim_trailing(ts_string) |> String.to_integer() end @@ -67,8 +82,8 @@ defmodule Thoughts do location = String.replace_prefix(path, project_root <> "/thoughts/", "") link = "https://m1kadev.nl/thoughts/" <> urlify(location) <> ".html" rfc_date = date - |> DateTime.from_unix!() - |> Calendar.strftime("%a, %d %b %Y %H:%M:%S %Z") + |> DateTime.from_unix!() + |> Calendar.strftime("%a, %d %b %Y %H:%M:%S %Z") Mustache.render(template, %{title: location, date: rfc_date, description: thought, category: "thoughts", link: link } ) end end diff --git a/kethel/main.exs b/kethel/main.exs index a66d3cd8c38aa3a6afbd20439ac4a5e0c34f24ab..85d67f08c7ed48e5a82f777a9720136cd92f6ed7 100644 --- a/kethel/main.exs +++ b/kethel/main.exs @@ -57,6 +57,25 @@ if folder != nil do File.write!("#{project_root}/build/rss.xml", rss_header <> rss_thoughts <> rss_footer) IO.puts("[COMPILED] #{project_root}/build/rss.xml") + + { lcss_version, 0 }= System.cmd("npx", [ "lightningcss", "-V" ]) + { hmn_version, 0 } = System.cmd("npx", [ "html-minifier-next", "-V" ]) + { ujs_version, 0 } = System.cmd("npx", [ "uglifyjs", "-V" ]) + { git_commit, 0 } = System.cmd("git", [ "rev-parse", "HEAD" ]) + + { build_date, 0 } = System.cmd("date", ["+%H:%M %d/%m/%y"]) + + info_txt = """ + commit=#{git_commit} + lightningcss=#{lcss_version} + html_minifier_next=#{hmn_version} + uglifyjs=#{ujs_version} + build_time=#{build_date} + """ + + File.write!("#{project_root}/build/info.txt", info_txt) + + IO.puts("[COMPILED] #{project_root}/build/info.txt") IO.puts("Finalising..."); diff --git a/pages/colophon.fxg b/pages/colophon.fxg index ba621a21bc87aea439600c768c027e4660a29e48..4402fdf79aa7ef3b7b87daa17017b55a911b3a18 100644 --- a/pages/colophon.fxg +++ b/pages/colophon.fxg @@ -3,6 +3,9 @@ == about == you're looking at a <#https://en.wiktionary.org/wiki/beautiful#English beautiful> site, with <#https://caddyserver.com/ caddy> as its backend. + the site generator is a home-grown non-gmo <#https://github.com/m1kadev/www.m1kadev.nl/tree/main/kethel/ elixir app>. the internal markup language is <#https://github.com/m1kadev/fxg fxg>, made to be more legible than markdown. + templating the final html is handled by <#https://mustache.github.io mustache>, a stateless templating library. + css, js, and html parsing are handled by lightningcss, uglifyjs, and html-minifier-next, respectively. diff --git a/styles/thoughts.css b/styles/thoughts.css index d30ac624f82a47c4a309eb28ee82fb2759baae00..2a1dc0c42fa03730ba96fd13aca02aaf8e0bc7b7 100644 --- a/styles/thoughts.css +++ b/styles/thoughts.css @@ -18,4 +18,8 @@ .thought>small { text-align: right; display: block; -} \ No newline at end of file +} + +main hr:first-of-type { + display: none; +} diff --git a/templates/inline_thought.thtml b/templates/inline_thought.thtml new file mode 100644 index 0000000000000000000000000000000000000000..47baf56959c29e8a1d19cc664412ababff65211f --- /dev/null +++ b/templates/inline_thought.thtml @@ -0,0 +1,8 @@ +
+
+

{{ &name }}

+ + {{ thought }} + + -mika, {{ date }} +