Skip to content

feat: automatically generate post ids #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/tableau/extensions/page_extension.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ defmodule Tableau.PageExtension do

Frontmatter is compiled with `yaml_elixir` and all keys are converted to atoms.

* `:id` - An Elixir module to be used when compiling the backing `Tableau.Page`. A leaking implementation detail that should be fixed eventually.
* `:title` - The title of the page
* `:permalink` - The permalink of the page.
* `:layout` - A string representation of a Tableau layout module.
Expand Down Expand Up @@ -74,11 +73,19 @@ defmodule Tableau.PageExtension do
Macro.Env.location(__ENV__)
)

for {mod, _, _} <- :code.all_available(),
mod = Module.concat([to_string(mod)]),
Tableau.Graph.Node.type(mod) == :page,
mod.__tableau_opts__()[:__tableau_page_extension__] do
:code.purge(mod)
:code.delete(mod)
end

pages =
for page <- apply(Tableau.PageExtension.Pages, :pages, []) do
{:module, _module, _binary, _term} =
Module.create(
Module.concat([page.id]),
:"#{System.unique_integer()}",
quote do
use Tableau.Page, unquote(Macro.escape(Keyword.new(page)))

Expand Down
1 change: 1 addition & 0 deletions lib/tableau/extensions/page_extension/pages/page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Tableau.PageExtension.Pages.Page do
Tableau.PageExtension.Config.new(Map.new(Application.get_env(:tableau, Tableau.PageExtension, %{})))

attrs
|> Map.put(:__tableau_page_extension__, true)
|> Map.put(:body, body)
|> Map.put(:file, filename)
|> Map.put(:layout, Module.concat([attrs.layout || page_config.layout]))
Expand Down
11 changes: 9 additions & 2 deletions lib/tableau/extensions/post_extension.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ defmodule Tableau.PostExtension do

Frontmatter is compiled with `yaml_elixir` and all keys are converted to atoms.

* `:id` - An Elixir module to be used when compiling the backing `Tableau.Page`. A leaking implementation detail that should be fixed eventually.
* `:title` - The title of the post. Falls back to the first `<h1>` tag if present in the body.
* `:permalink` - The permalink of the post. `:title` will be replaced with the posts title and non alphanumeric characters removed. Optional.
* `:date` - A string representation of an Elixir `NaiveDateTime`, often presented as a `sigil_N`. This will be converted to your configured timezone.
Expand Down Expand Up @@ -88,11 +87,19 @@ defmodule Tableau.PostExtension do
Macro.Env.location(__ENV__)
)

for {mod, _, _} <- :code.all_available(),
mod = Module.concat([to_string(mod)]),
Tableau.Graph.Node.type(mod) == :page,
mod.__tableau_opts__()[:__tableau_post_extension__] do
:code.purge(mod)
:code.delete(mod)
end

posts =
for post <- apply(Tableau.PostExtension.Posts, :posts, []) do
{:module, _module, _binary, _term} =
Module.create(
Module.concat([post.id]),
:"#{System.unique_integer()}",
quote do
use Tableau.Page, unquote(Macro.escape(Keyword.new(post)))

Expand Down
1 change: 1 addition & 0 deletions lib/tableau/extensions/post_extension/posts/post.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Tableau.PostExtension.Posts.Post do
Tableau.PostExtension.Config.new(Map.new(Application.get_env(:tableau, Tableau.PostExtension, %{})))

attrs
|> Map.put(:__tableau_post_extension__, true)
|> Map.put(:body, body)
|> Map.put(:file, filename)
|> Map.put(:layout, Module.concat([attrs[:layout] || post_config.layout]))
Expand Down