Skip to content

Commit 7cca6ba

Browse files
paradox460mhanberg
authored andcommitted
Automatically generate post IDs
1 parent 8e47467 commit 7cca6ba

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/tableau/extensions/post_extension.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ 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.
11+
* `:id` - An Elixir module to be used when compiling the backing `Tableau.Page`. Optional.
1212
* `:title` - The title of the post. Falls back to the first `<h1>` tag if present in the body.
1313
* `:permalink` - The permalink of the post. `:title` will be replaced with the posts title and non alphanumeric characters removed. Optional.
1414
* `:date` - A string representation of an Elixir `NaiveDateTime`, often presented as a `sigil_N`. This will be converted to your configured timezone.
@@ -90,9 +90,13 @@ defmodule Tableau.PostExtension do
9090

9191
posts =
9292
for post <- apply(Tableau.PostExtension.Posts, :posts, []) do
93+
post_id =
94+
post.id ||
95+
post.title |> String.replace(~r/[^[:alnum:]]+/u, "_") |> Macro.camelize() |> then(&("Post." <> &1))
96+
9397
{:module, _module, _binary, _term} =
9498
Module.create(
95-
Module.concat([post.id]),
99+
Module.concat([post_id]),
96100
quote do
97101
use Tableau.Page, unquote(Macro.escape(Keyword.new(post)))
98102

0 commit comments

Comments
 (0)