14 Commits
Author SHA1 Message Date
Raymon Zutekouw 4b9f9b301c Merge branch 'beta' 2021-11-24 20:29:12 +01:00
Raymon Zutekouw 61b3cb1500 Exclude already wrapped paragraphs from <p> wrapping
- Allows `paragraph \n header \n paragraph`
- Allows `paragraph \n  list  \n paragraph`
2021-11-23 12:31:58 +01:00
Raymon Zutekouw b3fe972d0e Move \n -> paragraphs out of fill_template
- As it should only be done for the custom format
2021-11-23 12:07:02 +01:00
Raymon Zutekouw 266b6e0733 Improve formatting in RSS feed, to make it valid 2021-11-23 12:06:02 +01:00
Raymon Zutekouw 6ed757b81b Keep : between hours, minutes, seconds 2021-11-23 11:09:58 +01:00
Raymon Zutekouw 12741a20c5 Remove old link remains
- id's in posts
- /api route
2021-11-23 11:00:11 +01:00
Raymon Zutekouw 4cebaf550b Folder by year/month instead of id under one folder 2021-11-18 20:41:20 +01:00
Raymon Zutekouw 04b41fa182 Fix spelling mistake 2021-11-15 18:27:07 +01:00
Raymon Zutekouw 9e0d3954d2 Swap h3 for p,strong for RSS subscribe header 2021-10-25 11:38:43 +02:00
Raymon Zutekouw 2d6e087342 Extend post format options with .org files 2021-04-28 12:34:36 +02:00
Raymonzut 8d5e9c02ad Merge branch 'beta' into master 2021-01-19 17:48:53 +01:00
Raymonzut a0eb56e115 Remove dynamic age feature 2021-01-19 17:40:48 +01:00
Raymonzut 6c31c8752d Join date sort order function to one line
- Fixes not using year in order calculation
2021-01-08 21:33:28 +01:00
Raymonzut 8e15354c2a Add ExamplePost 2020-11-26 23:08:08 +01:00
12 changed files with 99 additions and 64 deletions
+4 -1
View File
@@ -1 +1,4 @@
posts/* posts_custom/*
!posts_custom/ExamplePostCustomFormat
posts_org/*
!posts_org/ExamplePostOrgFormat.org
+76 -16
View File
@@ -8,22 +8,20 @@ post_feed_template = File.read!("./templates/posts.xml")
# Converting handlebars in template to values # Converting handlebars in template to values
fill_template = fn template, pairs -> fill_template = fn template, pairs ->
Regex.compile!("{{(.*)}}") |> Regex.compile!("{{(.*)}}") |>
Regex.replace(template, fn _, key -> if key != "content" do Map.get(pairs, String.to_atom(key)) else Regex.replace(template, fn _, key -> Map.get(pairs, String.to_atom(key)) end)
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)
end end
fill_template_pretemplated = fn template -> &fill_template.(template, &1) 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.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 -> String.split(c, "\n") end)
|> Enum.map(fn c -> Enum.reject(c, fn(x) -> x == "" end) end) |> Enum.map(fn c -> Enum.reject(c, fn(x) -> x == "" end) end)
|> Enum.map(fn c -> Enum.chunk_every(c, 2) end) |> Enum.map(fn c -> Enum.chunk_every(c, 2) end)
@@ -31,19 +29,68 @@ post_contents = File.ls!("./posts")
Enum.map(c, fn [k, v] -> %{String.to_atom(k) => v} end) Enum.map(c, fn [k, v] -> %{String.to_atom(k) => v} end)
|> Enum.reduce(%{}, fn(x, acc) -> Map.merge(x, acc) end) |> Enum.reduce(%{}, fn(x, acc) -> Map.merge(x, acc) end)
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"] 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 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.sort_by(fn m -> Map.get(m, :date) |> (fn d -> Enum.find_index(months, &(&1 == String.slice(d, 8..10))) end).() end)
|> Enum.reverse() |> Enum.reverse()
# Group by month # Group by month
|> Enum.group_by(fn m -> Map.get(m, :date) |> String.slice(8..15) end) |> 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) |> 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.find_index(months, &(&1 == String.slice(d, 0..2))) end)
|> Enum.reverse() |> Enum.reverse()
|> Enum.map(fn {month, posts} -> "\n<h1>" <> month <> "</h1>\n" <> (posts |> |> Enum.map(fn {month, posts} -> "\n<h1>" <> month <> "</h1>\n" <> (posts |>
Enum.map(fn post -> "<h2>" <> (Map.get(post, :date) |> String.slice(0..6)) <> 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) end) |> Enum.join("\n")) end)
|> Enum.join("\n") |> Enum.join("\n")
|> (fn v -> %{index: v} end).() |> (fn v -> %{index: v} end).()
@@ -53,14 +100,27 @@ File.open!("./public/gen/index.html", [:write])
|> IO.binwrite(index_file) |> IO.binwrite(index_file)
|> File.close() |> File.close()
prepare_path = fn path ->
File.mkdir_p!(Path.dirname(path))
path
end
post_contents post_contents
|> Enum.each(fn post -> |> Enum.each(fn post -> post
File.open!("./public/gen/" <> Map.get(post, :id) <> ".html", [:write]) |> (fn p -> "./public/gen/" <> Map.get(p, :localpath) <> ".html" end).()
|> prepare_path.()
|> File.open!([:write])
|> IO.binwrite(fill_template.(post_template, post)) |> IO.binwrite(fill_template.(post_template, post))
|> File.close() |> File.close()
end) end)
stripForRSS = fn content -> content
|> String.replace("\n", "")
end
post_feed = post_contents 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.sort_by(fn m -> Map.get(m, :date) end)
|> Enum.reverse() |> Enum.reverse()
|> Enum.map(fill_template_pretemplated.(post_feed_item_template)) |> Enum.map(fill_template_pretemplated.(post_feed_item_template))
-7
View File
@@ -7,9 +7,6 @@ events {
} }
http { http {
include /etc/nginx/mime.types; include /etc/nginx/mime.types;
types {
application/javascript mjs;
}
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" ' '$status $body_bytes_sent "$http_referer" '
@@ -29,10 +26,6 @@ http {
alias /app/assets/styling; alias /app/assets/styling;
} }
location /js {
alias /app/lib;
}
location /posts { location /posts {
alias /app/gen/; alias /app/gen/;
} }
View File
@@ -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
+1 -4
View File
@@ -8,8 +8,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Raymon Zutekouw</title> <title>Raymon Zutekouw</title>
<link rel="preload" href="./lib/me.mjs" as="script" crossorigin="anonymous" type="application/javascript">
<link rel="preload" href="index.mjs" as="script" crossorigin="anonymous" type="application/javascript">
<link rel="dns-prefetch" href="https://cdn.statically.io"> <link rel="dns-prefetch" href="https://cdn.statically.io">
<link defer <link defer
@@ -32,7 +30,7 @@
<div> <div>
<p> <p>
Hi there, good to see you on my website. Hi there, good to see you on my website.
My name is Raymon Zutekouw (<span id="age">born on 29-08-2002</span>) My name is Raymon Zutekouw; Self-taught programmer by heart.
</p> </p>
<p> <p>
@@ -48,6 +46,5 @@
</p> </p>
</div> </div>
</div> </div>
<script async type="module" src="index.mjs"></script>
</body> </body>
</html> </html>
-4
View File
@@ -1,4 +0,0 @@
import { age } from "./lib/me.mjs"
const age_span = document.getElementById("age")
age_span.textContent = age().toString()
-17
View File
@@ -1,17 +0,0 @@
export function age() {
let birthdate = new Date("29 August 2002")
let now = new Date()
let age = now.getFullYear() - birthdate.getFullYear()
if (now.getMonth() < birthdate.getMonth())
age--
if (
birthdate.getMonth() === now.getMonth() &&
now.getDate() < birthdate.getDate()
)
age--
return age
}
+5 -10
View File
@@ -1,14 +1,9 @@
<item> <item>
<title>{{title}}</title> <title>{{title}}</title>
<link>https://raymon.dev/posts/{{id}}.html</link> <link>https://raymon.dev/posts/{{localpath}}.html</link>
<guid>https://raymon.dev/posts/{{id}}.html</guid> <guid>https://raymon.dev/posts/{{localpath}}.html</guid>
<description>
<![CDATA[
{{content}}
]]>
</description>
<content type="html">
{{content}}
</content>
<pubDate>{{date}}</pubDate> <pubDate>{{date}}</pubDate>
<description><![CDATA[
{{content}}
]]></description>
</item> </item>
+1 -1
View File
@@ -26,7 +26,7 @@
<article> <article>
<header> <header>
<h1>{{title}}</h1> <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> </header>
<time datetime="{{date}}"></time> <time datetime="{{date}}"></time>
{{content}} {{content}}
+3 -4
View File
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel> <channel>
<atom:link href="https://raymon.dev/api/posts/rss.xml" rel="self" type="application/rss+xml" /> <title>Raymon Zutekouw</title>
<title>Posts</title>
<link>https://raymon.dev</link>
<description>Personal blog</description> <description>Personal blog</description>
<language>en-us</language> <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}} {{items}}
</channel> </channel>
</rss> </rss>