Skip to content

fix: allow atom layout module names #108

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 1 commit into from
Oct 11, 2024
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
4 changes: 2 additions & 2 deletions lib/tableau/extensions/page_extension.ex
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ defmodule Tableau.PageExtension do
optional(:enabled, true) => bool(),
optional(:dir, "_pages") => str(),
optional(:permalink) => str(),
optional(:layout) => str()
optional(:layout) => oneof([str(), atom()])
}),
input
)
Expand Down Expand Up @@ -113,7 +113,7 @@ defmodule Tableau.PageExtension do
|> Map.put(:__tableau_page_extension__, true)
|> Map.put(:body, body)
|> Map.put(:file, filename)
|> Map.put(:layout, Module.concat([front_matter.layout || pages_config.layout]))
|> Map.put(:layout, Module.concat([front_matter[:layout] || pages_config.layout]))
|> Common.build_permalink(pages_config)
end
end
2 changes: 1 addition & 1 deletion lib/tableau/extensions/post_extension.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ defmodule Tableau.PostExtension do
optional(:dir, "_posts") => str(),
optional(:future, false) => bool(),
optional(:permalink) => str(),
optional(:layout) => str()
optional(:layout) => oneof([atom(), str()])
}),
config
)
Expand Down
30 changes: 29 additions & 1 deletion test/tableau/extensions/page_extension_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Tableau.PageExtensionTest do

describe "run" do
setup %{tmp_dir: dir} do
assert {:ok, config} = PageExtension.config(%{dir: dir, enabled: true})
assert {:ok, config} = PageExtension.config(%{dir: dir, enabled: true, layout: Blog.DefaultPageLayout})

token = %{
site: %{config: %{converters: [md: Tableau.MDExConverter]}},
Expand Down Expand Up @@ -200,5 +200,33 @@ defmodule Tableau.PageExtensionTest do
]
} = token
end

test "inherits layout from page extension config", %{tmp_dir: dir, token: token} do
File.write(Path.join(dir, "a-page.md"), """
---
title: missing layout key
type: articles
permalink: /:type/:title
---
A great page
""")

assert {:ok, token} = PageExtension.run(token)

assert %{
pages: [
%{
__tableau_page_extension__: true,
body: "\nA great page\n",
file: ^dir <> "/a-page.md",
layout: Blog.DefaultPageLayout,
permalink: "/articles/missing-layout-key",
title: "missing layout key",
type: "articles"
}
]
} = token
end
end
end
30 changes: 29 additions & 1 deletion test/tableau/extensions/post_extension_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Tableau.PostExtensionTest do

describe "run" do
setup %{tmp_dir: dir} do
assert {:ok, config} = PostExtension.config(%{dir: dir, enabled: true})
assert {:ok, config} = PostExtension.config(%{dir: dir, enabled: true, layout: Blog.DefaultPostLayout})

token = %{
site: %{config: %{converters: [md: Tableau.MDExConverter]}},
Expand Down Expand Up @@ -233,6 +233,34 @@ defmodule Tableau.PostExtensionTest do
} = token
end

test "inherits layout from post extension config", %{tmp_dir: dir, token: token} do
File.write(Path.join(dir, "a-post.md"), """
---
title: Missing layout key
date: 2018-02-28
permalink: /:title
---

A great post
""")

assert {:ok, token} = PostExtension.run(token)

assert %{
posts: [
%{
__tableau_post_extension__: true,
body: "\nA great post\n",
date: ~U[2018-02-28 00:00:00Z],
file: ^dir <> "/a-post.md",
layout: Blog.DefaultPostLayout,
permalink: "/missing-layout-key",
title: "Missing layout key"
}
]
} = token
end

test "handles frontmatter data in the permalink", %{tmp_dir: dir, token: token} do
File.write(Path.join(dir, "a-post.md"), """
---
Expand Down