Skip to content

Commit

Permalink
Merge pull request #3 from andyleclair/feat/dev_server
Browse files Browse the repository at this point in the history
add dev server + post
  • Loading branch information
andyleclair authored Dec 31, 2024
2 parents 9860aa5 + 5b66f33 commit d54cfc7
Show file tree
Hide file tree
Showing 21 changed files with 859 additions and 499 deletions.
1 change: 1 addition & 0 deletions lib/mix/tasks/build.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule Mix.Tasks.Build do
use Mix.Task

@impl Mix.Task
def run(_args) do
{micro, :ok} =
Expand Down
4 changes: 2 additions & 2 deletions lib/personal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ defmodule Personal do
<body class="bg-nor-easter text-smurf-blood">
<div class="flex h-60 min-h-screen flex-col items-center">
<header class="bg-bludacris p-10 my-4 lg:mt-10 lg:mb-14">
<h1>[email protected]$><span class="blink">_</span></h1>
<h1><a href={url()}>[email protected]</a>$><span class="blink">_</span></h1>
</header>
<main class="relative grow min-h-96 flex-1 p-4">
<%= render_slot(@inner_block) %>
</main>
<footer class="mt-10 bg-bludacris p-4 text-center">
<footer class="mt-24 bg-bludacris p-4 text-center">
© Andy LeClair 2024 | <a href="/atom.xml">Atom</a> | <a href="/feed.xml">RSS</a>
</footer>
</div>
Expand Down
4 changes: 2 additions & 2 deletions lib/personal/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ defmodule Personal.Application do
@impl true
def start(_type, _args) do
children = [
# Starts a worker by calling: Personal.Worker.start_link(arg)
# {Personal.Worker, arg}
{Bandit, plug: Personal.DevServer},
{Personal.Watcher, dirs: ["./lib", "./posts"]}
]

# See https://hexdocs.pm/elixir/Supervisor.html
Expand Down
25 changes: 25 additions & 0 deletions lib/personal/dev_server.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
defmodule Personal.Router do
use Plug.Router
plug :match
plug :dispatch

get "/drafts" do
send_resp(conn, 200, "drafts")
end

match _ do
send_resp(conn, 404, "oops")
end
end

defmodule Personal.DevServer do
use Plug.Builder

plug Plug.Static.IndexHtml, at: "/"

plug Plug.Static,
at: "/",
from: "./output"

plug Personal.Router
end
35 changes: 35 additions & 0 deletions lib/personal/watcher.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
defmodule Personal.Watcher do
require Logger
use GenServer

def start_link(args) do
GenServer.start_link(__MODULE__, args)
end

def init(args) do
{:ok, watcher_pid} = FileSystem.start_link(args)
FileSystem.subscribe(watcher_pid)
{:ok, %{watcher_pid: watcher_pid}}
end

# These emit a LOT of events, [:modified] is fine
def handle_info(
{:file_event, watcher_pid, {path, [:modified]}},
%{watcher_pid: watcher_pid} = state
) do
Mix.shell().info(["File modified: #{path}"])
Mix.shell().info(["Site Rebuilding"])
# Currently, we're just recompiling the entire site
# TODO: make this fancier based on the path
System.cmd("mix", ["site.build"])
Mix.shell().info([:green, "Site rebuilt"])
{:noreply, state}
end

def handle_info(
{:file_event, watcher_pid, {_path, _events}},
%{watcher_pid: watcher_pid} = state
) do
{:noreply, state}
end
end
5 changes: 4 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ defmodule Personal.MixProject do
{:makeup_erlang, ">= 0.0.0"},
{:nimble_publisher, "~> 1.1.0"},
{:phoenix, "~> 1.7"},
{:bandit, "~> 1.0"},
{:phoenix_live_view, "~> 1.0"},
{:tailwind, "~> 0.2"},
{:tzdata, "~> 1.1"}
{:tzdata, "~> 1.1"},
{:plug_static_index_html, "~> 1.0"},
{:file_system, "~> 1.0", only: :dev}
]
end

Expand Down
5 changes: 5 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
%{
"bandit": {:hex, :bandit, "1.6.1", "9e01b93d72ddc21d8c576a704949e86ee6cde7d11270a1d3073787876527a48f", [:mix], [{:hpax, "~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.0", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "5a904bf010ea24b67979835e0507688e31ac873d4ffc8ed0e5413e8d77455031"},
"castore": {:hex, :castore, "1.0.10", "43bbeeac820f16c89f79721af1b3e092399b3a1ecc8df1a472738fd853574911", [:mix], [], "hexpm", "1b0b7ea14d889d9ea21202c43a4fa015eb913021cb535e8ed91946f4b77a8848"},
"certifi": {:hex, :certifi, "2.12.0", "2d1cca2ec95f59643862af91f001478c9863c2ac9cb6e2f89780bfd8de987329", [:rebar3], [], "hexpm", "ee68d85df22e554040cdb4be100f33873ac6051387baf6a8f6ce82272340ff1c"},
"earmark": {:hex, :earmark, "1.4.47", "7e7596b84fe4ebeb8751e14cbaeaf4d7a0237708f2ce43630cfd9065551f94ca", [:mix], [], "hexpm", "3e96bebea2c2d95f3b346a7ff22285bc68a99fbabdad9b655aa9c6be06c698f8"},
"esbuild": {:hex, :esbuild, "0.8.2", "5f379dfa383ef482b738e7771daf238b2d1cfb0222bef9d3b20d4c8f06c7a7ac", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "558a8a08ed78eb820efbfda1de196569d8bfa9b51e8371a1934fbb31345feda7"},
"file_system": {:hex, :file_system, "1.0.1", "79e8ceaddb0416f8b8cd02a0127bdbababe7bf4a23d2a395b983c1f8b3f73edd", [:mix], [], "hexpm", "4414d1f38863ddf9120720cd976fce5bdde8e91d8283353f0e31850fa89feb9e"},
"hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"},
"hpax": {:hex, :hpax, "1.0.2", "762df951b0c399ff67cc57c3995ec3cf46d696e41f0bba17da0518d94acd4aac", [:mix], [], "hexpm", "2f09b4c1074e0abd846747329eaa26d535be0eb3d189fa69d812bfb8bfefd32f"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
"makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"},
Expand All @@ -22,9 +25,11 @@
"phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"},
"plug": {:hex, :plug, "1.16.1", "40c74619c12f82736d2214557dedec2e9762029b2438d6d175c5074c933edc9d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a13ff6b9006b03d7e33874945b2755253841b238c34071ed85b0e86057f8cddc"},
"plug_crypto": {:hex, :plug_crypto, "2.1.0", "f44309c2b06d249c27c8d3f65cfe08158ade08418cf540fd4f72d4d6863abb7b", [:mix], [], "hexpm", "131216a4b030b8f8ce0f26038bc4421ae60e4bb95c5cf5395e1421437824c4fa"},
"plug_static_index_html": {:hex, :plug_static_index_html, "1.0.0", "840123d4d3975585133485ea86af73cb2600afd7f2a976f9f5fd8b3808e636a0", [:mix], [{:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "79fd4fcf34d110605c26560cbae8f23c603ec4158c08298bd4360fdea90bb5cf"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"},
"tailwind": {:hex, :tailwind, "0.2.4", "5706ec47182d4e7045901302bf3a333e80f3d1af65c442ba9a9eed152fb26c2e", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "c6e4a82b8727bab593700c998a4d98cf3d8025678bfde059aed71d0000c3e463"},
"telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"},
"thousand_island": {:hex, :thousand_island, "1.3.7", "1da7598c0f4f5f50562c097a3f8af308ded48cd35139f0e6f17d9443e4d0c9c5", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "0139335079953de41d381a6134d8b618d53d084f558c734f2662d1a72818dd12"},
"tzdata": {:hex, :tzdata, "1.1.2", "45e5f1fcf8729525ec27c65e163be5b3d247ab1702581a94674e008413eef50b", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "cec7b286e608371602318c414f344941d5eb0375e14cfdab605cca2fe66cba8b"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
"websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"},
Expand Down
2 changes: 1 addition & 1 deletion output/assets/app.css

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion output/atom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
<title>andyleclair.dev</title>
<link href="https://andyleclair.dev/" />
<link href="https://andyleclair.dev/atom.xml" rel="self" />
<updated>2024-12-30T00:00:00-05:00</updated>
<updated>2024-12-31T00:00:00-05:00</updated>
<author>
<name>Andy LeClair</name>
</author>
<id>https://andyleclair.dev/</id>

<entry>
<title>Dev Server</title>
<link href="https://andyleclair.dev/posts/2024/12-31-dev-server.html" />
<id>https://andyleclair.dev/posts/2024/12-31-dev-server.html</id>
<updated>2024-12-31T00:00:00-05:00</updated>
<summary>Adding a development server</summary>
</entry>
<entry>
<title>Adding RSS to a static site</title>
<link href="https://andyleclair.dev/posts/2024/12-30-adding-rss-to-a-static-site.html" />
<id>https://andyleclair.dev/posts/2024/12-30-adding-rss-to-a-static-site.html</id>
Expand Down
7 changes: 7 additions & 0 deletions output/feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
<link>https://andyleclair.dev/</link>
<atom:link href="https://andyleclair.dev/feed.xml" rel="self" type="application/rss+xml" />
<item>
<title>Dev Server</title>
<description>Adding a development server</description>
<pubDate>Tue, 31 Dec 2024 00:00:00 EST</pubDate>
<link>https://andyleclair.dev/posts/2024/12-31-dev-server.html</link>
<guid isPermaLink="true">https://andyleclair.dev/posts/2024/12-31-dev-server.html</guid>
</item>
<item>
<title>Adding RSS to a static site</title>
<description>Adding RSS and Atom feeds to this site</description>
<pubDate>Mon, 30 Dec 2024 00:00:00 EST</pubDate>
Expand Down
6 changes: 4 additions & 2 deletions output/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
<body class="bg-nor-easter text-smurf-blood">
<div class="flex h-60 min-h-screen flex-col items-center">
<header class="bg-bludacris p-10 my-4 lg:mt-10 lg:mb-14">
<h1>[email protected]$><span class="blink">_</span></h1>
<h1><a href="https://andyleclair.dev/">[email protected]</a>$><span class="blink">_</span></h1>
</header>
<main class="relative grow min-h-96 flex-1 p-4">

<h2 class="text-xl">Blog!</h2>
<ul>
<li>
2024-12-31 - <a href="posts/2024/12-31-dev-server.html">Dev Server</a>
</li><li>
2024-12-30 - <a href="posts/2024/12-30-adding-rss-to-a-static-site.html">Adding RSS to a static site</a>
</li><li>
2024-11-15 - <a href="posts/2024/11-15-how-to-do-a-preload-good.html">How To Do A Preload Good</a>
Expand All @@ -40,7 +42,7 @@ <h2 class="text-xl">Blog!</h2>
</ul>

</main>
<footer class="bg-bludacris p-4 text-center">
<footer class="mt-24 bg-bludacris p-4 text-center">
© Andy LeClair 2024 | <a href="/atom.xml">Atom</a> | <a href="/feed.xml">RSS</a>
</footer>
</div>
Expand Down
4 changes: 2 additions & 2 deletions output/posts/2024/08-27-hello-world.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<body class="bg-nor-easter text-smurf-blood">
<div class="flex h-60 min-h-screen flex-col items-center">
<header class="bg-bludacris p-10 my-4 lg:mt-10 lg:mb-14">
<h1>[email protected]$><span class="blink">_</span></h1>
<h1><a href="https://andyleclair.dev/">[email protected]</a>$><span class="blink">_</span></h1>
</header>
<main class="relative grow min-h-96 flex-1 p-4">

Expand All @@ -36,7 +36,7 @@ <h3><a href="https://www.youtube.com/watch?v=wVrSXeRXSWE">Related Listening</a><
</article>

</main>
<footer class="bg-bludacris p-4 text-center">
<footer class="mt-24 bg-bludacris p-4 text-center">
© Andy LeClair 2024 | <a href="/atom.xml">Atom</a> | <a href="/feed.xml">RSS</a>
</footer>
</div>
Expand Down
4 changes: 2 additions & 2 deletions output/posts/2024/08-28-readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<body class="bg-nor-easter text-smurf-blood">
<div class="flex h-60 min-h-screen flex-col items-center">
<header class="bg-bludacris p-10 my-4 lg:mt-10 lg:mb-14">
<h1>[email protected]$><span class="blink">_</span></h1>
<h1><a href="https://andyleclair.dev/">[email protected]</a>$><span class="blink">_</span></h1>
</header>
<main class="relative grow min-h-96 flex-1 p-4">

Expand Down Expand Up @@ -45,7 +45,7 @@ <h3><a href="https://www.youtube.com/watch?v=9q4mVEcedSo">Related Listening</a><
</article>

</main>
<footer class="bg-bludacris p-4 text-center">
<footer class="mt-24 bg-bludacris p-4 text-center">
© Andy LeClair 2024 | <a href="/atom.xml">Atom</a> | <a href="/feed.xml">RSS</a>
</footer>
</div>
Expand Down
Loading

0 comments on commit d54cfc7

Please sign in to comment.