Skip to content

Commit b5bf6df

Browse files
paradox460mhanberg
andauthoredNov 8, 2023
feat: automatically generate post ids (#33)
Co-authored-by: Mitchell Hanberg <[email protected]>
1 parent 8e47467 commit b5bf6df

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
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

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ 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)
89
|> Map.put(:body, body)
910
|> Map.put(:file, filename)
1011
|> Map.put(:layout, Module.concat([attrs.layout || page_config.layout]))

‎lib/tableau/extensions/post_extension.ex

+9-2
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`. A leaking implementation detail that should be fixed eventually.
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

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

+1
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]))

0 commit comments

Comments
 (0)
Please sign in to comment.