Skip to content

Commit 1d25364

Browse files
committed
fixups
1 parent 16a69f8 commit 1d25364

File tree

4 files changed

+21
-35
lines changed

4 files changed

+21
-35
lines changed

lib/tableau/extensions/page_extension.ex

+9-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ defmodule Tableau.PageExtension do
88
99
Frontmatter is compiled with `yaml_elixir` and all keys are converted to atoms.
1010
11-
* `:id` - An Elixir module to be used when compiling the backing `Tableau.Page`. A leaking implementation detail that should be fixed eventually.
1211
* `:title` - The title of the page
1312
* `:permalink` - The permalink of the page.
1413
* `:layout` - A string representation of a Tableau layout module.
@@ -74,11 +73,19 @@ defmodule Tableau.PageExtension do
7473
Macro.Env.location(__ENV__)
7574
)
7675

76+
for {mod, _, _} <- :code.all_available(),
77+
mod = Module.concat([to_string(mod)]),
78+
Tableau.Graph.Node.type(mod) == :page,
79+
mod.__tableau_opts__()[:__tableau_page_extension__] do
80+
:code.purge(mod)
81+
:code.delete(mod)
82+
end
83+
7784
pages =
7885
for page <- apply(Tableau.PageExtension.Pages, :pages, []) do
7986
{:module, _module, _binary, _term} =
8087
Module.create(
81-
Module.concat([page.id]),
88+
:"#{System.unique_integer()}",
8289
quote do
8390
use Tableau.Page, unquote(Macro.escape(Keyword.new(page)))
8491

lib/tableau/extensions/page_extension/pages/page.ex

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ defmodule Tableau.PageExtension.Pages.Page do
55
Tableau.PageExtension.Config.new(Map.new(Application.get_env(:tableau, Tableau.PageExtension, %{})))
66

77
attrs
8+
|> Map.put(:__tableau_page_extension__, true)
9+
|> Map.put(:module, :"#{System.unique_integer()}")
810
|> Map.put(:body, body)
911
|> Map.put(:file, filename)
1012
|> Map.put(:layout, Module.concat([attrs.layout || page_config.layout]))

lib/tableau/extensions/post_extension.ex

+9-21
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ defmodule Tableau.PostExtension do
88
99
Frontmatter is compiled with `yaml_elixir` and all keys are converted to atoms.
1010
11-
* `:id` - An Elixir module to be used when compiling the backing `Tableau.Page`. Optional.
1211
* `:title` - The title of the post. Falls back to the first `<h1>` tag if present in the body.
1312
* `:permalink` - The permalink of the post. `:title` will be replaced with the posts title and non alphanumeric characters removed. Optional.
1413
* `:date` - A string representation of an Elixir `NaiveDateTime`, often presented as a `sigil_N`. This will be converted to your configured timezone.
@@ -88,11 +87,19 @@ defmodule Tableau.PostExtension do
8887
Macro.Env.location(__ENV__)
8988
)
9089

90+
for {mod, _, _} <- :code.all_available(),
91+
mod = Module.concat([to_string(mod)]),
92+
Tableau.Graph.Node.type(mod) == :page,
93+
mod.__tableau_opts__()[:__tableau_post_extension__] do
94+
:code.purge(mod)
95+
:code.delete(mod)
96+
end
97+
9198
posts =
9299
for post <- apply(Tableau.PostExtension.Posts, :posts, []) do
93100
{:module, _module, _binary, _term} =
94101
Module.create(
95-
Module.concat([post.id]),
102+
:"#{System.unique_integer()}",
96103
quote do
97104
use Tableau.Page, unquote(Macro.escape(Keyword.new(post)))
98105

@@ -107,25 +114,6 @@ defmodule Tableau.PostExtension do
107114
post
108115
end
109116

110-
generated_posts = Enum.map(posts, & &1.id)
111-
112-
loaded_posts =
113-
Enum.reduce(:code.all_loaded(), [], fn {mod, _}, acc ->
114-
mod
115-
|> to_string()
116-
|> String.split(".")
117-
|> then(fn
118-
[_, "AutogenPostID" | _] -> mod |> Macro.to_string() |> then(&[&1 | acc])
119-
_ -> acc
120-
end)
121-
end)
122-
123-
for post <- loaded_posts, post not in generated_posts do
124-
post = Module.concat([post])
125-
:code.purge(post)
126-
:code.delete(post)
127-
end
128-
129117
{:ok, Map.put(token, :posts, posts)}
130118
end,
131119
[Node.self()],

lib/tableau/extensions/post_extension/posts/post.ex

+1-12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ defmodule Tableau.PostExtension.Posts.Post do
77
Tableau.PostExtension.Config.new(Map.new(Application.get_env(:tableau, Tableau.PostExtension, %{})))
88

99
attrs
10+
|> Map.put(:__tableau_post_extension__, true)
1011
|> Map.put(:body, body)
1112
|> Map.put(:file, filename)
1213
|> Map.put(:layout, Module.concat([attrs[:layout] || post_config.layout]))
@@ -18,7 +19,6 @@ defmodule Tableau.PostExtension.Posts.Post do
1819
_ -> nil
1920
end
2021
end)
21-
|> maybe_calculate_id()
2222
|> Map.put(
2323
:date,
2424
DateTime.from_naive!(
@@ -68,15 +68,4 @@ defmodule Tableau.PostExtension.Posts.Post do
6868
|> String.replace(~r/[^[:alnum:]\/\-]/, "")
6969
|> String.downcase()
7070
end
71-
72-
defp maybe_calculate_id(%{id: _} = attrs), do: attrs
73-
74-
defp maybe_calculate_id(attrs) do
75-
attrs.title
76-
|> String.downcase()
77-
|> String.replace(~r/[^[:alnum:]]+/u, "_")
78-
|> Macro.camelize()
79-
|> then(&"AutogenPostID.#{&1}")
80-
|> then(&Map.put(attrs, :id, &1))
81-
end
8271
end

0 commit comments

Comments
 (0)