Merge branch 'beta'

master c3.3.0
Raymon Zutekouw 2 years ago
commit 4b9f9b301c
No known key found for this signature in database
GPG Key ID: 1E9BCC39EDD1DD53
  1. 5
      client/.gitignore
  2. 89
      client/gen.exs
  3. 8
      client/posts/ExamplePost
  4. 6
      client/posts_custom/ExamplePostCustomFormat
  5. 3
      client/posts_org/ExamplePostOrgFormat.org
  6. 2
      client/public/index.html
  7. 15
      client/templates/post_item.xml
  8. 2
      client/templates/post_single_page.html
  9. 7
      client/templates/posts.xml

5
client/.gitignore vendored

@ -1 +1,4 @@
posts/*
posts_custom/*
!posts_custom/ExamplePostCustomFormat
posts_org/*
!posts_org/ExamplePostOrgFormat.org

@ -8,22 +8,20 @@ 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 -> ("<p>" <> paragraph <> "</p>\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
post_contents = File.ls!("./posts")
wrapInParagraphs = fn content -> content
|> String.split("\\n")
|> Enum.reject(fn(x) -> x == "" end)
|> Enum.map(fn paragraph -> if String.starts_with?(paragraph, "<") do paragraph else "<p>" <> paragraph <> "</p>" end 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/" <> 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)
@ -31,8 +29,58 @@ post_contents = File.ls!("./posts")
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 ->
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))
)
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)
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()
@ -42,7 +90,7 @@ index_file = post_contents
|> Enum.reverse()
|> Enum.map(fn {month, posts} -> "\n<h1>" <> month <> "</h1>\n" <> (posts |>
Enum.map(fn post -> "<h2>" <> (Map.get(post, :date) |> String.slice(0..6)) <>
" - <a href=\"" <> Map.get(post, :id) <> ".html\">" <> Map.get(post, :title) <> "</a></h2>"
" - <a href=\"" <> Map.get(post, :localpath) <> ".html\">" <> Map.get(post, :title) <> "</a></h2>"
end) |> Enum.join("\n")) end)
|> Enum.join("\n")
|> (fn v -> %{index: v} end).()
@ -52,14 +100,27 @@ 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)
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))

@ -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

@ -0,0 +1,6 @@
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.

@ -0,0 +1,3 @@
#+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

@ -30,7 +30,7 @@
<div>
<p>
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.
</p>
<p>

@ -1,14 +1,9 @@
<item>
<title>{{title}}</title>
<link>https://raymon.dev/posts/{{id}}.html</link>
<guid>https://raymon.dev/posts/{{id}}.html</guid>
<description>
<![CDATA[
{{content}}
]]>
</description>
<content type="html">
{{content}}
</content>
<link>https://raymon.dev/posts/{{localpath}}.html</link>
<guid>https://raymon.dev/posts/{{localpath}}.html</guid>
<pubDate>{{date}}</pubDate>
<description><![CDATA[
{{content}}
]]></description>
</item>

@ -26,7 +26,7 @@
<article>
<header>
<h1>{{title}}</h1>
<h3>For those using a RSS reader, subscribe here: <a href="/posts/rss.xml">rss.xml</a></h3>
<p><strong>For those using a RSS reader, subscribe here: <a href="/posts/rss.xml">rss.xml</a></strong></p>
</header>
<time datetime="{{date}}"></time>
{{content}}

@ -1,12 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="https://raymon.dev/api/posts/rss.xml" rel="self" type="application/rss+xml" />
<title>Posts</title>
<link>https://raymon.dev</link>
<title>Raymon Zutekouw</title>
<description>Personal blog</description>
<language>en-us</language>
<link>https://raymon.dev</link>
<atom:link href="https://raymon.dev/posts/rss.xml" rel="self" type="application/rss+xml" />
{{items}}
</channel>
</rss>

Loading…
Cancel
Save