Extend post format options with .org files

master
Raymon Zutekouw 3 years ago
parent a0eb56e115
commit 2d6e087342
No known key found for this signature in database
GPG Key ID: 1E9BCC39EDD1DD53
  1. 5
      client/.gitignore
  2. 42
      client/gen.exs
  3. 8
      client/posts/ExamplePost
  4. 8
      client/posts_custom/ExamplePostCustomFormat
  5. 4
      client/posts_org/ExamplePostOrgFormat.org

5
client/.gitignore vendored

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

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

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

@ -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
Loading…
Cancel
Save