Skip to content

Commit 9585d16

Browse files
authored
fix: handle token format correctly in MDExConverter (#105)
fix: handle token format correctly in RSSExtension fix: ensure extensions are loading
1 parent d1a5480 commit 9585d16

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
lines changed

config/test.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ config :logger, level: :warning
44

55
config :tableau, Mix.Tasks.Tableau.FailExtension, enabled: true
66
config :tableau, Mix.Tasks.Tableau.LogExtension, enabled: true
7-
config :tableau, Tableau.PostExtension, enabled: false
7+
config :tableau, Tableau.PostExtension, enabled: true
88
config :tableau, Tableau.RSSExtension, enabled: false
99
config :tableau, Tableau.SitemapExtension, enabled: false
1010
config :tableau, :config, url: "http://localhost:4999"

lib/mix/tasks/tableau.build.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ defmodule Mix.Tasks.Tableau.Build do
7474

7575
defp extensions_for(modules, type) do
7676
extensions =
77-
for mod <- modules, {:ok, type} == Tableau.Extension.type(mod) do
77+
for mod <- modules, Code.ensure_loaded?(mod), {:ok, type} == Tableau.Extension.type(mod) do
7878
mod
7979
end
8080

lib/tableau/converters/mdex_converter.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule Tableau.MDExConverter do
22
@moduledoc """
33
Converter to parse markdown content with `MDEx`
44
"""
5-
def convert(_filepath, _front_matter, body, %{config: config}) do
5+
def convert(_filepath, _front_matter, body, %{site: %{config: config}}) do
66
MDEx.to_html!(body, config.markdown[:mdex])
77
end
88
end

lib/tableau/extensions/rss_extension.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ defmodule Tableau.RSSExtension do
3535
)
3636
end
3737

38-
def run(%{site: %{config: %{url: url}}, posts: posts, rss: rss} = token) do
38+
def run(%{site: %{config: %{url: url}}, posts: posts, extensions: %{rss: %{config: rss}}} = token) do
3939
prelude =
4040
"""
4141
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">

test/mix/tasks/tableau.build_test.exs

+35-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@ defmodule Mix.Tasks.Tableau.LogExtension do
22
@moduledoc false
33
use Tableau.Extension, key: :log, type: :pre_build, priority: 200
44

5-
defmodule Config do
6-
@moduledoc false
7-
def new(i), do: {:ok, i}
8-
end
9-
105
def run(token) do
11-
IO.inspect(System.monotonic_time(), label: "second")
6+
IO.write(:stderr, "second: #{System.monotonic_time()}\n")
127
{:ok, token}
138
end
149
end
@@ -18,7 +13,7 @@ defmodule Mix.Tasks.Tableau.FailExtension do
1813
use Tableau.Extension, key: :fail, type: :pre_build, priority: 100
1914

2015
def run(_site) do
21-
IO.inspect(System.monotonic_time(), label: "first")
16+
IO.write(:stderr, "first: #{System.monotonic_time()}\n")
2217
:error
2318
end
2419
end
@@ -145,8 +140,38 @@ defmodule Mix.Tasks.Tableau.BuildTest do
145140

146141
@tag :tmp_dir
147142
test "renders all pages", %{tmp_dir: out} do
143+
posts = out |> Path.join("_posts") |> tap(&File.mkdir_p!/1)
144+
pages = out |> Path.join("_pages") |> tap(&File.mkdir_p!/1)
145+
Application.put_env(:tableau, Tableau.PostExtension, enabled: true, dir: posts)
146+
Application.put_env(:tableau, Tableau.PageExtension, enabled: true, dir: pages)
147+
148+
File.write(Path.join(posts, "my-post.md"), """
149+
---
150+
layout: Mix.Tasks.Tableau.BuildTest.RootLayout
151+
title: A Bing Bong Blog Post
152+
date: 2017-02-28
153+
categories: post
154+
permalink: /:title/
155+
---
156+
157+
## Bing
158+
159+
Bong!
160+
""")
161+
162+
page_path = pages |> Path.join("some/deeply/nested/page") |> tap(&File.mkdir_p!/1) |> Path.join("/my-page.md")
163+
164+
File.write(page_path, """
165+
---
166+
layout: Mix.Tasks.Tableau.BuildTest.RootLayout
167+
title: Beginner Tutorial
168+
---
169+
170+
## How to get started
171+
""")
172+
148173
{log, io} =
149-
with_io(fn ->
174+
with_io(:stderr, fn ->
150175
{_, log} =
151176
with_log(fn ->
152177
_documents = Build.run(["--out", out])
@@ -171,5 +196,7 @@ defmodule Mix.Tasks.Tableau.BuildTest do
171196

172197
assert File.exists?(Path.join(out, "/index.html"))
173198
assert File.exists?(Path.join(out, "/about/index.html"))
199+
assert File.exists?(Path.join(out, "/a-bing-bong-blog-post/index.html"))
200+
assert File.exists?(Path.join(out, "/some/deeply/nested/page/my-page/index.html"))
174201
end
175202
end

0 commit comments

Comments
 (0)