Skip to content

Commit 74bf8fb

Browse files
authored
fix(build): capture pre_write page changes (#162)
1 parent 3714a83 commit 74bf8fb

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/mix/tasks/tableau.build.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ defmodule Mix.Tasks.Tableau.Build do
6565

6666
token = mods |> extensions_for(:pre_write) |> run_extensions(:pre_write, token)
6767

68-
for %{body: body, permalink: permalink} <- pages do
68+
for %{body: body, permalink: permalink} <- token.site[:pages] do
6969
file_path = build_file_path(out, permalink)
7070
dir = Path.dirname(file_path)
7171

test/mix/tasks/tableau.build_test.exs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ defmodule Mix.Tasks.Tableau.FooExtension do
2525
def pre_write(token) do
2626
pages =
2727
for page <- token.site.pages do
28-
Map.put(page, :foo, "bar")
28+
page
29+
|> Map.put(:foo, "bar")
30+
|> Map.put(:body, page.body <> "<!-- foo: bar -->\n")
2931
end
3032

3133
{:ok, put_in(token.site.pages, pages)}
@@ -189,10 +191,16 @@ defmodule Mix.Tasks.Tableau.BuildTest do
189191

190192
assert log =~ "FailExtension failed to run"
191193

192-
assert File.exists?(Path.join(out, "/index.html"))
193-
assert File.exists?(Path.join(out, "/about/index.html"))
194-
assert File.exists?(Path.join(out, "/a-bing-bong-blog-post/index.html"))
195-
assert File.exists?(Path.join(out, "/some/deeply/nested/page/my-page/index.html"))
194+
for file <- [
195+
"/index.html",
196+
"/about/index.html",
197+
"/a-bing-bong-blog-post/index.html",
198+
"/some/deeply/nested/page/my-page/index.html"
199+
] do
200+
path = Path.join(out, file)
201+
assert File.exists?(path)
202+
assert path |> File.read!() |> String.ends_with?("<!-- foo: bar -->\n")
203+
end
196204
end
197205

198206
@tag :tmp_dir

0 commit comments

Comments
 (0)