From 2d6e087342a79a465eed160603643088a4e00473 Mon Sep 17 00:00:00 2001 From: Raymon Zutekouw <40148684+Raymonzut@users.noreply.github.com> Date: Wed, 28 Apr 2021 12:34:36 +0200 Subject: [PATCH 1/9] Extend post format options with .org files --- client/.gitignore | 5 ++- client/gen.exs | 42 ++++++++++++++++++++- client/posts/ExamplePost | 8 ---- client/posts_custom/ExamplePostCustomFormat | 8 ++++ client/posts_org/ExamplePostOrgFormat.org | 4 ++ 5 files changed, 56 insertions(+), 11 deletions(-) delete mode 100644 client/posts/ExamplePost create mode 100644 client/posts_custom/ExamplePostCustomFormat create mode 100644 client/posts_org/ExamplePostOrgFormat.org diff --git a/client/.gitignore b/client/.gitignore index 03ddbf1..30947c0 100644 --- a/client/.gitignore +++ b/client/.gitignore @@ -1 +1,4 @@ -posts/* +posts_custom/* +!posts_custom/ExamplePostCustomFormat +posts_org/* +!posts_org/ExamplePostOrgFormat.org diff --git a/client/gen.exs b/client/gen.exs index 82bfd5c..9337a62 100644 --- a/client/gen.exs +++ b/client/gen.exs @@ -21,9 +21,9 @@ end fill_template_pretemplated = fn template -> &fill_template.(template, &1) end -post_contents = File.ls!("./posts") +post_contents_custom = File.ls!("./posts_custom") |> Enum.reject(fn(x) -> String.starts_with?(x, ".") end) - |> Enum.map(fn f -> File.read!("./posts/" <> f) end) + |> Enum.map(fn f -> File.read!("./posts_custom/" <> f) end) |> Enum.map(fn c -> String.split(c, "\n") end) |> Enum.map(fn c -> Enum.reject(c, fn(x) -> x == "" end) end) |> Enum.map(fn c -> Enum.chunk_every(c, 2) end) @@ -32,6 +32,44 @@ post_contents = File.ls!("./posts") |> Enum.reduce(%{}, fn(x, acc) -> Map.merge(x, acc) end) end) +filterCutFileExtension = fn files -> + fn ext -> + Enum.filter(files, &String.ends_with?(&1, "." <> ext)) + |> Enum.map(&String.replace_suffix(&1, "." <> ext, "")) + |> (fn x -> %{String.to_atom(ext) => x} end).() + end +end + +isMeta = &String.starts_with?(&1, "#+") + +posts_org = + File.ls!("./posts_org") + |> Enum.reject(fn x -> String.starts_with?(x, ".") end) + |> (fn files -> Enum.map(["org", "html"], filterCutFileExtension.(files)) end).() + |> Enum.reduce(%{}, fn x, acc -> Map.merge(x, acc) end) + +post_contents_org = + Enum.filter(Map.get(posts_org, :org), fn el -> Enum.member?(Map.get(posts_org, :html), el) end) + |> Enum.map( + &(File.read!("./posts_org/" <> &1 <> ".org") + |> (fn fileContent -> String.split(fileContent, "\n") end).() + |> Enum.take_while(isMeta) + |> Enum.map(fn metaOrg -> + [head | tail] = String.split(metaOrg, ":") + + %{ + (String.slice(head, 2..-1) |> String.downcase() |> String.to_atom()) => + String.slice(Enum.join(tail, ""), 1..-1) + } + end) + |> Enum.reduce(%{:content => File.read!("./posts_org/" <> &1 <> ".html")}, fn x, acc -> + Map.merge(x, acc) + end)) + ) + + +post_contents = Enum.concat(post_contents_custom, post_contents_org) + 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) diff --git a/client/posts/ExamplePost b/client/posts/ExamplePost deleted file mode 100644 index 12e9d21..0000000 --- a/client/posts/ExamplePost +++ /dev/null @@ -1,8 +0,0 @@ -id -4739537f3d29e1047a45c254 -title -Example post for my new post page! -date -Mon, 11 May 2020 13:25:00 GMT -content -My new posts page is live diff --git a/client/posts_custom/ExamplePostCustomFormat b/client/posts_custom/ExamplePostCustomFormat new file mode 100644 index 0000000..c9d9488 --- /dev/null +++ b/client/posts_custom/ExamplePostCustomFormat @@ -0,0 +1,8 @@ +id +4739537f3d29e1047a45c254 +title +Example post for my new custom-gen post page! +date +Mon, 11 May 2020 13:25:00 GMT +content +My new posts page is live, this post has been generated from a custom format. diff --git a/client/posts_org/ExamplePostOrgFormat.org b/client/posts_org/ExamplePostOrgFormat.org new file mode 100644 index 0000000..e612af3 --- /dev/null +++ b/client/posts_org/ExamplePostOrgFormat.org @@ -0,0 +1,4 @@ +#+ID: 4739537f3d29e1047a45c261 +#+TITLE: Example post for my new org-gen post page! +#+DATE: Wed, 28 Apr 2021 11:25:00 GMT +My new posts page is live, this post has been generated from an org file From 9e0d3954d2afbd5509bc27a20e3b7cf0f9343ed7 Mon Sep 17 00:00:00 2001 From: Raymon Zutekouw <40148684+Raymonzut@users.noreply.github.com> Date: Mon, 25 Oct 2021 11:38:43 +0200 Subject: [PATCH 2/9] Swap h3 for p,strong for RSS subscribe header --- client/templates/post_single_page.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/templates/post_single_page.html b/client/templates/post_single_page.html index 28a49ef..dceaa5e 100644 --- a/client/templates/post_single_page.html +++ b/client/templates/post_single_page.html @@ -26,7 +26,7 @@

{{title}}

-

For those using a RSS reader, subscribe here: rss.xml

+

For those using a RSS reader, subscribe here: rss.xml

{{content}} From 04b41fa182f81a2a4b22d21554f936fae107f900 Mon Sep 17 00:00:00 2001 From: Raymon Zutekouw <40148684+Raymonzut@users.noreply.github.com> Date: Mon, 15 Nov 2021 18:27:07 +0100 Subject: [PATCH 3/9] Fix spelling mistake --- client/public/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/public/index.html b/client/public/index.html index 06b9db5..1d35a69 100644 --- a/client/public/index.html +++ b/client/public/index.html @@ -30,7 +30,7 @@

Hi there, good to see you on my website. - My name is Raymon Zutekouw; Self-thaught programmer by heart. + My name is Raymon Zutekouw; Self-taught programmer by heart.

From 4cebaf550bc1316cba5d0971240029ee6d536a2a Mon Sep 17 00:00:00 2001 From: Raymon Zutekouw <40148684+Raymonzut@users.noreply.github.com> Date: Thu, 18 Nov 2021 20:33:17 +0100 Subject: [PATCH 4/9] Folder by year/month instead of id under one folder --- client/gen.exs | 27 +++++++++++++++++++++++---- client/templates/post_item.xml | 4 ++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/client/gen.exs b/client/gen.exs index 9337a62..f5f50a5 100644 --- a/client/gen.exs +++ b/client/gen.exs @@ -67,10 +67,21 @@ post_contents_org = end)) ) +months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] + +dateFolder = fn p -> + Map.get(p, :date) + |> String.slice(8..15) + |> String.split(" ") + |> (fn ([month, year]) -> year <> "/" <> Integer.to_string(Enum.find_index(months, &(&1 == month)) + 1) <> "/" end).() +end +normalize_title = fn title -> String.replace(String.downcase(title), " ", "-") end + +constructLocalPath = fn p -> dateFolder.(p) <> normalize_title.(Map.get(p, :title)) end post_contents = Enum.concat(post_contents_custom, post_contents_org) + |> Enum.map(fn postMap -> Map.merge(postMap, %{localpath: (constructLocalPath.(postMap))}) 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) |> (fn d -> Enum.find_index(months, &(&1 == String.slice(d, 8..10))) end).() end) |> Enum.reverse() @@ -80,7 +91,7 @@ index_file = post_contents |> Enum.reverse() |> Enum.map(fn {month, posts} -> "\n

" <> month <> "

\n" <> (posts |> Enum.map(fn post -> "

" <> (Map.get(post, :date) |> String.slice(0..6)) <> - " - Map.get(post, :id) <> ".html\">" <> Map.get(post, :title) <> "

" + " - Map.get(post, :localpath) <> ".html\">" <> Map.get(post, :title) <> "" end) |> Enum.join("\n")) end) |> Enum.join("\n") |> (fn v -> %{index: v} end).() @@ -90,9 +101,17 @@ File.open!("./public/gen/index.html", [:write]) |> IO.binwrite(index_file) |> File.close() + +prepare_path = fn path -> + File.mkdir_p!(Path.dirname(path)) + path +end + post_contents - |> Enum.each(fn post -> - File.open!("./public/gen/" <> Map.get(post, :id) <> ".html", [:write]) + |> Enum.each(fn post -> post + |> (fn p -> "./public/gen/" <> Map.get(p, :localpath) <> ".html" end).() + |> prepare_path.() + |> File.open!([:write]) |> IO.binwrite(fill_template.(post_template, post)) |> File.close() end) diff --git a/client/templates/post_item.xml b/client/templates/post_item.xml index fca9f40..9a65398 100644 --- a/client/templates/post_item.xml +++ b/client/templates/post_item.xml @@ -1,7 +1,7 @@ {{title}} - https://raymon.dev/posts/{{id}}.html - https://raymon.dev/posts/{{id}}.html + https://raymon.dev/posts/{{localpath}}.html + https://raymon.dev/posts/{{localpath}}.html Date: Tue, 23 Nov 2021 11:00:11 +0100 Subject: [PATCH 5/9] Remove old link remains - id's in posts - /api route --- client/posts_custom/ExamplePostCustomFormat | 2 -- client/posts_org/ExamplePostOrgFormat.org | 1 - client/templates/posts.xml | 2 +- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/client/posts_custom/ExamplePostCustomFormat b/client/posts_custom/ExamplePostCustomFormat index c9d9488..54a3b9f 100644 --- a/client/posts_custom/ExamplePostCustomFormat +++ b/client/posts_custom/ExamplePostCustomFormat @@ -1,5 +1,3 @@ -id -4739537f3d29e1047a45c254 title Example post for my new custom-gen post page! date diff --git a/client/posts_org/ExamplePostOrgFormat.org b/client/posts_org/ExamplePostOrgFormat.org index e612af3..3235dff 100644 --- a/client/posts_org/ExamplePostOrgFormat.org +++ b/client/posts_org/ExamplePostOrgFormat.org @@ -1,4 +1,3 @@ -#+ID: 4739537f3d29e1047a45c261 #+TITLE: Example post for my new org-gen post page! #+DATE: Wed, 28 Apr 2021 11:25:00 GMT My new posts page is live, this post has been generated from an org file diff --git a/client/templates/posts.xml b/client/templates/posts.xml index fe8b854..e7bf2ba 100644 --- a/client/templates/posts.xml +++ b/client/templates/posts.xml @@ -1,7 +1,7 @@ - + Posts https://raymon.dev Personal blog From 6ed757b81bdb92ba9923bfe77236eb5be69c28d8 Mon Sep 17 00:00:00 2001 From: Raymon Zutekouw <40148684+Raymonzut@users.noreply.github.com> Date: Tue, 23 Nov 2021 11:09:58 +0100 Subject: [PATCH 6/9] Keep `:` between hours, minutes, seconds --- client/gen.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/gen.exs b/client/gen.exs index f5f50a5..700dcc0 100644 --- a/client/gen.exs +++ b/client/gen.exs @@ -59,7 +59,7 @@ post_contents_org = %{ (String.slice(head, 2..-1) |> String.downcase() |> String.to_atom()) => - String.slice(Enum.join(tail, ""), 1..-1) + String.slice(Enum.join(tail, ":"), 1..-1) } end) |> Enum.reduce(%{:content => File.read!("./posts_org/" <> &1 <> ".html")}, fn x, acc -> From 266b6e0733e3c5749c29335a769b6e8186fe41d1 Mon Sep 17 00:00:00 2001 From: Raymon Zutekouw <40148684+Raymonzut@users.noreply.github.com> Date: Tue, 23 Nov 2021 11:41:47 +0100 Subject: [PATCH 7/9] Improve formatting in RSS feed, to make it valid --- client/gen.exs | 5 +++++ client/templates/post_item.xml | 11 +++-------- client/templates/posts.xml | 7 +++---- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/client/gen.exs b/client/gen.exs index 700dcc0..116224e 100644 --- a/client/gen.exs +++ b/client/gen.exs @@ -116,7 +116,12 @@ post_contents |> File.close() end) +stripForRSS = fn content -> content + |> String.replace("\n", "") +end + post_feed = post_contents + |> Enum.map(fn m -> Map.update!(m, :content, stripForRSS) end) |> Enum.sort_by(fn m -> Map.get(m, :date) end) |> Enum.reverse() |> Enum.map(fill_template_pretemplated.(post_feed_item_template)) diff --git a/client/templates/post_item.xml b/client/templates/post_item.xml index 9a65398..3d9c42e 100644 --- a/client/templates/post_item.xml +++ b/client/templates/post_item.xml @@ -2,13 +2,8 @@ {{title}} https://raymon.dev/posts/{{localpath}}.html https://raymon.dev/posts/{{localpath}}.html - - - - - {{content}} - {{date}} + diff --git a/client/templates/posts.xml b/client/templates/posts.xml index e7bf2ba..057f7de 100644 --- a/client/templates/posts.xml +++ b/client/templates/posts.xml @@ -1,12 +1,11 @@ - - Posts - https://raymon.dev + Raymon Zutekouw Personal blog en-us - + https://raymon.dev + {{items}} From b3fe972d0e0ac0a9e1a64d93e6edd5ba40544e2b Mon Sep 17 00:00:00 2001 From: Raymon Zutekouw <40148684+Raymonzut@users.noreply.github.com> Date: Tue, 23 Nov 2021 12:07:02 +0100 Subject: [PATCH 8/9] Move `\n` -> paragraphs out of fill_template - As it should only be done for the custom format --- client/gen.exs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/client/gen.exs b/client/gen.exs index 116224e..c9d7c31 100644 --- a/client/gen.exs +++ b/client/gen.exs @@ -8,19 +8,17 @@ 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) + Regex.replace(template, fn _, key -> Map.get(pairs, String.to_atom(key)) end) end fill_template_pretemplated = fn template -> &fill_template.(template, &1) end +wrapInParagraphs = fn content -> content + |> String.split("\\n") + |> Enum.reject(fn(x) -> x == "" end) + |> Enum.map(fn paragraph -> "

" <> paragraph <> "

" end) + |> Enum.join("") +end post_contents_custom = File.ls!("./posts_custom") |> Enum.reject(fn(x) -> String.starts_with?(x, ".") end) |> Enum.map(fn f -> File.read!("./posts_custom/" <> f) end) @@ -31,6 +29,7 @@ post_contents_custom = File.ls!("./posts_custom") Enum.map(c, fn [k, v] -> %{String.to_atom(k) => v} end) |> Enum.reduce(%{}, fn(x, acc) -> Map.merge(x, acc) end) end) + |> Enum.map(fn m -> Map.update!(m, :content, wrapInParagraphs) end) filterCutFileExtension = fn files -> fn ext -> From 61b3cb1500b261ce5488af2347a4dded783283dd Mon Sep 17 00:00:00 2001 From: Raymon Zutekouw <40148684+Raymonzut@users.noreply.github.com> Date: Tue, 23 Nov 2021 12:31:58 +0100 Subject: [PATCH 9/9] Exclude already wrapped paragraphs from

wrapping - Allows `paragraph \n header \n paragraph` - Allows `paragraph \n list \n paragraph` --- client/gen.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/gen.exs b/client/gen.exs index c9d7c31..f9a5baf 100644 --- a/client/gen.exs +++ b/client/gen.exs @@ -16,7 +16,7 @@ fill_template_pretemplated = fn template -> &fill_template.(template, &1) end wrapInParagraphs = fn content -> content |> String.split("\\n") |> Enum.reject(fn(x) -> x == "" end) - |> Enum.map(fn paragraph -> "

" <> paragraph <> "

" end) + |> Enum.map(fn paragraph -> if String.starts_with?(paragraph, "<") do paragraph else "

" <> paragraph <> "

" end end) |> Enum.join("") end post_contents_custom = File.ls!("./posts_custom")