From e9d50f1392e294f7421772e39c03dee04d42e126 Mon Sep 17 00:00:00 2001
From: Raymonzut <40148684+Raymonzut@users.noreply.github.com>
Date: Fri, 9 Oct 2020 23:31:54 +0200
Subject: [PATCH 1/7] Extract template filling: pair usage consistant
---
client/public/gen.ex | 45 ++++++++++++++++++++++----------------------
1 file changed, 23 insertions(+), 22 deletions(-)
diff --git a/client/public/gen.ex b/client/public/gen.ex
index d4124bc..da18165 100644
--- a/client/public/gen.ex
+++ b/client/public/gen.ex
@@ -5,6 +5,22 @@ post_template = File.read!("./templates/post_single_page.html")
post_feed_item_template = File.read!("./templates/post_item.xml")
post_feed_template = File.read!("./templates/posts.xml")
+# Converting handlebars in template to values
+fill_template = fn template, pairs ->
+ Regex.compile!("{{(.*)}}") |>
+ Regex.replace(template, fn _, key -> if key != "content" do Map.get(pairs, String.to_atom(key)) else
+ Map.get(pairs, String.to_atom(key))
+ # Converting \n to paragraphs
+ |> String.split("\\n")
+ |> Enum.reject(fn(x) -> x == "" end)
+ |> Enum.map(fn paragraph -> ("
" <> paragraph <> "
\n") end)
+ |> Enum.join("")
+ end
+ end)
+end
+
+fill_template_pretemplated = fn template -> &fill_template.(template, &1) end
+
post_contents = File.ls!("./posts")
|> Enum.reject(fn(x) -> String.starts_with?(x, ".") end)
|> Enum.map(fn f -> File.read!("./posts/" <> f) end)
@@ -26,43 +42,28 @@ index_file = post_contents
Enum.map(fn post -> ""
end) |> Enum.join("\n")) end)
- |> (fn template -> Regex.replace(Regex.compile!("{{index}}"), index_template, fn _, __ -> template end) end).()
+ |> Enum.join("\n")
+ |> (fn v -> %{index: v} end).()
+ |> fill_template_pretemplated.(index_template).()
File.open!("./gen/index.html", [:write])
|> IO.binwrite(index_file)
|> File.close()
-
post_contents
|> Enum.each(fn post ->
File.open!("./gen/" <> Map.get(post, :id) <> ".html", [:write])
- |> IO.binwrite(
- # Converting handlebars to values
- Regex.compile!("{{(.*)}}") |>
- Regex.replace(post_template, fn _, key -> if key != "content" do Map.get(post, String.to_atom(key)) else
- Map.get(post, String.to_atom(key))
- # Converting \n to paragraphs
- |> String.split("\\n")
- |> Enum.reject(fn(x) -> x == "" end)
- |> Enum.map(fn paragraph -> ("" <> paragraph <> "
\n") end)
- |> Enum.join("")
- end
- end))
+ |> IO.binwrite(fill_template.(post_template, post))
|> File.close()
end)
post_feed = post_contents
|> Enum.sort_by(fn m -> Map.get(m, :date) end)
|> Enum.reverse()
- |> Enum.map(fn post ->
- Regex.compile!("{{(.*)}}") |>
- Regex.replace(post_feed_item_template, fn _, key -> Map.get(post, String.to_atom(key))
- end)
- end)
+ |> Enum.map(fill_template_pretemplated.(post_feed_item_template))
|> Enum.join("\n")
- |> (fn items -> (Regex.compile!("{{items}}") |>
- Regex.replace(post_feed_template, fn _, __ -> items end))
- end).()
+ |> (fn v -> %{items: v} end).()
+ |> fill_template_pretemplated.(post_feed_template).()
File.open!("./gen/rss.xml", [:write])
|> IO.binwrite(post_feed)
From 67b8a4f5817349c83e761cc2a7733df58032470d Mon Sep 17 00:00:00 2001
From: Raymonzut <40148684+Raymonzut@users.noreply.github.com>
Date: Fri, 6 Nov 2020 22:18:27 +0100
Subject: [PATCH 2/7] Update index gen for new date format
---
client/public/gen.ex | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/client/public/gen.ex b/client/public/gen.ex
index da18165..f124480 100644
--- a/client/public/gen.ex
+++ b/client/public/gen.ex
@@ -32,14 +32,15 @@ post_contents = File.ls!("./posts")
|> Enum.reduce(%{}, fn(x, acc) -> Map.merge(x, acc) end)
end)
+months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
index_file = post_contents
- |> Enum.sort_by(fn m -> Map.get(m, :date) end)
- |> Enum.reverse()
+ |> Enum.sort_by(fn m -> Map.get(m, :date) |> (fn d -> Enum.find_index(months, &(&1 == String.slice(d, 8..10))) end).() end)
# Group by month
- |> Enum.group_by(fn m -> Map.get(m, :date) |> String.slice(0..6) end)
+ |> Enum.group_by(fn m -> Map.get(m, :date) |> String.slice(8..15) end)
+ |> Enum.sort_by(fn {d, _c} -> Enum.find_index(months, &(&1 == String.slice(d, 0..2))) end)
|> Enum.reverse()
|> Enum.map(fn {month, posts} -> "\n" <> month <> "
\n" <> (posts |>
- Enum.map(fn post -> "" <> (Map.get(post, :date) |> String.slice(0..9)) <>
+ Enum.map(fn post -> ""
end) |> Enum.join("\n")) end)
|> Enum.join("\n")
From 403fc9d5cbd516ea4e93e0e10292ee2c652b129d Mon Sep 17 00:00:00 2001
From: Raymonzut <40148684+Raymonzut@users.noreply.github.com>
Date: Fri, 6 Nov 2020 22:38:10 +0100
Subject: [PATCH 3/7] Account for multiple years for sorting posts
- Prepare for 2021
---
client/public/gen.ex | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/client/public/gen.ex b/client/public/gen.ex
index f124480..5d72c1b 100644
--- a/client/public/gen.ex
+++ b/client/public/gen.ex
@@ -37,7 +37,8 @@ index_file = post_contents
|> Enum.sort_by(fn m -> Map.get(m, :date) |> (fn d -> Enum.find_index(months, &(&1 == String.slice(d, 8..10))) end).() end)
# Group by month
|> Enum.group_by(fn m -> Map.get(m, :date) |> String.slice(8..15) end)
- |> Enum.sort_by(fn {d, _c} -> Enum.find_index(months, &(&1 == String.slice(d, 0..2))) end)
+ |> Enum.sort_by(fn {d, _c} -> (length months) * elem(Integer.parse(String.slice(d, 4..7)), 0)
+ + Enum.find_index(months, &(&1 == String.slice(d, 0..2))) end)
|> Enum.reverse()
|> Enum.map(fn {month, posts} -> "\n" <> month <> "
\n" <> (posts |>
Enum.map(fn post -> "" <> (Map.get(post, :date) |> String.slice(0..6)) <>
From eff86a1f3ebf60cb9bd216e08d8d150a00f3b4a7 Mon Sep 17 00:00:00 2001
From: Raymonzut <40148684+Raymonzut@users.noreply.github.com>
Date: Sat, 7 Nov 2020 11:31:10 +0100
Subject: [PATCH 4/7] Fix #12
- move pre-gen files out of public/
---
client/.gitignore | 1 +
client/{public => }/gen.ex | 6 +++---
client/{public => }/posts/.gitkeep | 0
client/public/.gitignore | 1 -
client/{public => }/templates/post_index_page.html | 0
client/{public => }/templates/post_item.xml | 0
client/{public => }/templates/post_single_page.html | 0
client/{public => }/templates/posts.xml | 0
8 files changed, 4 insertions(+), 4 deletions(-)
create mode 100644 client/.gitignore
rename client/{public => }/gen.ex (94%)
rename client/{public => }/posts/.gitkeep (100%)
rename client/{public => }/templates/post_index_page.html (100%)
rename client/{public => }/templates/post_item.xml (100%)
rename client/{public => }/templates/post_single_page.html (100%)
rename client/{public => }/templates/posts.xml (100%)
diff --git a/client/.gitignore b/client/.gitignore
new file mode 100644
index 0000000..03ddbf1
--- /dev/null
+++ b/client/.gitignore
@@ -0,0 +1 @@
+posts/*
diff --git a/client/public/gen.ex b/client/gen.ex
similarity index 94%
rename from client/public/gen.ex
rename to client/gen.ex
index 5d72c1b..0a853f6 100644
--- a/client/public/gen.ex
+++ b/client/gen.ex
@@ -48,13 +48,13 @@ index_file = post_contents
|> (fn v -> %{index: v} end).()
|> fill_template_pretemplated.(index_template).()
-File.open!("./gen/index.html", [:write])
+File.open!("./public/gen/index.html", [:write])
|> IO.binwrite(index_file)
|> File.close()
post_contents
|> Enum.each(fn post ->
- File.open!("./gen/" <> Map.get(post, :id) <> ".html", [:write])
+ File.open!("./public/gen/" <> Map.get(post, :id) <> ".html", [:write])
|> IO.binwrite(fill_template.(post_template, post))
|> File.close()
end)
@@ -67,6 +67,6 @@ post_feed = post_contents
|> (fn v -> %{items: v} end).()
|> fill_template_pretemplated.(post_feed_template).()
-File.open!("./gen/rss.xml", [:write])
+File.open!("./public/gen/rss.xml", [:write])
|> IO.binwrite(post_feed)
|> File.close()
diff --git a/client/public/posts/.gitkeep b/client/posts/.gitkeep
similarity index 100%
rename from client/public/posts/.gitkeep
rename to client/posts/.gitkeep
diff --git a/client/public/.gitignore b/client/public/.gitignore
index 690991b..7b86b0c 100644
--- a/client/public/.gitignore
+++ b/client/public/.gitignore
@@ -1,2 +1 @@
-posts/*
gen/*
diff --git a/client/public/templates/post_index_page.html b/client/templates/post_index_page.html
similarity index 100%
rename from client/public/templates/post_index_page.html
rename to client/templates/post_index_page.html
diff --git a/client/public/templates/post_item.xml b/client/templates/post_item.xml
similarity index 100%
rename from client/public/templates/post_item.xml
rename to client/templates/post_item.xml
diff --git a/client/public/templates/post_single_page.html b/client/templates/post_single_page.html
similarity index 100%
rename from client/public/templates/post_single_page.html
rename to client/templates/post_single_page.html
diff --git a/client/public/templates/posts.xml b/client/templates/posts.xml
similarity index 100%
rename from client/public/templates/posts.xml
rename to client/templates/posts.xml
From 6271fbb3b00c1d2fdbb4870d70a4dd91f3d0b386 Mon Sep 17 00:00:00 2001
From: Raymonzut <40148684+Raymonzut@users.noreply.github.com>
Date: Sat, 7 Nov 2020 11:45:20 +0100
Subject: [PATCH 5/7] Rename gen.ex to gen.exs, as it is a script
---
client/{gen.ex => gen.exs} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename client/{gen.ex => gen.exs} (100%)
diff --git a/client/gen.ex b/client/gen.exs
similarity index 100%
rename from client/gen.ex
rename to client/gen.exs
From bf0b5448b6aadd2a6a9f65da1fcb45f75883bb3c Mon Sep 17 00:00:00 2001
From: Raymonzut <40148684+Raymonzut@users.noreply.github.com>
Date: Thu, 12 Nov 2020 17:36:40 +0100
Subject: [PATCH 6/7] Fix #13
---
client/gen.exs | 1 +
1 file changed, 1 insertion(+)
diff --git a/client/gen.exs b/client/gen.exs
index 0a853f6..c1ab456 100644
--- a/client/gen.exs
+++ b/client/gen.exs
@@ -35,6 +35,7 @@ post_contents = File.ls!("./posts")
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
index_file = post_contents
|> Enum.sort_by(fn m -> Map.get(m, :date) |> (fn d -> Enum.find_index(months, &(&1 == String.slice(d, 8..10))) end).() end)
+ |> Enum.reverse()
# Group by month
|> Enum.group_by(fn m -> Map.get(m, :date) |> String.slice(8..15) end)
|> Enum.sort_by(fn {d, _c} -> (length months) * elem(Integer.parse(String.slice(d, 4..7)), 0)
From f82b6ba8f6e1e54e4ed02ac77a8b8ed7a359f582 Mon Sep 17 00:00:00 2001
From: Raymonzut <40148684+Raymonzut@users.noreply.github.com>
Date: Thu, 12 Nov 2020 18:14:56 +0100
Subject: [PATCH 7/7] Add docker-compose.yaml for client
---
client/Dockerfile | 1 -
docker-compose.yaml | 8 ++++++++
2 files changed, 8 insertions(+), 1 deletion(-)
create mode 100644 docker-compose.yaml
diff --git a/client/Dockerfile b/client/Dockerfile
index 9bda8c3..5da8154 100644
--- a/client/Dockerfile
+++ b/client/Dockerfile
@@ -1,4 +1,3 @@
FROM nginx as production-stage
RUN mkdir /app
-COPY /public /app
COPY nginx.conf /etc/nginx/nginx.conf
diff --git a/docker-compose.yaml b/docker-compose.yaml
new file mode 100644
index 0000000..2201185
--- /dev/null
+++ b/docker-compose.yaml
@@ -0,0 +1,8 @@
+version: "3.3"
+services:
+ client:
+ build: client/
+ ports:
+ - "5010:80"
+ volumes:
+ - "./client/public:/app:rw"