Skip to content
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

fix: handle token format correctly in MDExConverter #105

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
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ config :logger, level: :warning

config :tableau, Mix.Tasks.Tableau.FailExtension, enabled: true
config :tableau, Mix.Tasks.Tableau.LogExtension, enabled: true
config :tableau, Tableau.PostExtension, enabled: false
config :tableau, Tableau.PostExtension, enabled: true
config :tableau, Tableau.RSSExtension, enabled: false
config :tableau, Tableau.SitemapExtension, enabled: false
config :tableau, :config, url: "http://localhost:4999"
2 changes: 1 addition & 1 deletion lib/mix/tasks/tableau.build.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ defmodule Mix.Tasks.Tableau.Build do

defp extensions_for(modules, type) do
extensions =
for mod <- modules, {:ok, type} == Tableau.Extension.type(mod) do
for mod <- modules, Code.ensure_loaded?(mod), {:ok, type} == Tableau.Extension.type(mod) do
mod
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tableau/converters/mdex_converter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Tableau.MDExConverter do
@moduledoc """
Converter to parse markdown content with `MDEx`
"""
def convert(_filepath, _front_matter, body, %{config: config}) do
def convert(_filepath, _front_matter, body, %{site: %{config: config}}) do
MDEx.to_html!(body, config.markdown[:mdex])
end
end
2 changes: 1 addition & 1 deletion lib/tableau/extensions/rss_extension.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule Tableau.RSSExtension do
)
end

def run(%{site: %{config: %{url: url}}, posts: posts, rss: rss} = token) do
def run(%{site: %{config: %{url: url}}, posts: posts, extensions: %{rss: %{config: rss}}} = token) do
prelude =
"""
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
Expand Down
43 changes: 35 additions & 8 deletions test/mix/tasks/tableau.build_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ defmodule Mix.Tasks.Tableau.LogExtension do
@moduledoc false
use Tableau.Extension, key: :log, type: :pre_build, priority: 200

defmodule Config do
@moduledoc false
def new(i), do: {:ok, i}
end

def run(token) do
IO.inspect(System.monotonic_time(), label: "second")
IO.write(:stderr, "second: #{System.monotonic_time()}\n")
{:ok, token}
end
end
Expand All @@ -18,7 +13,7 @@ defmodule Mix.Tasks.Tableau.FailExtension do
use Tableau.Extension, key: :fail, type: :pre_build, priority: 100

def run(_site) do
IO.inspect(System.monotonic_time(), label: "first")
IO.write(:stderr, "first: #{System.monotonic_time()}\n")
:error
end
end
Expand Down Expand Up @@ -145,8 +140,38 @@ defmodule Mix.Tasks.Tableau.BuildTest do

@tag :tmp_dir
test "renders all pages", %{tmp_dir: out} do
posts = out |> Path.join("_posts") |> tap(&File.mkdir_p!/1)
pages = out |> Path.join("_pages") |> tap(&File.mkdir_p!/1)
Application.put_env(:tableau, Tableau.PostExtension, enabled: true, dir: posts)
Application.put_env(:tableau, Tableau.PageExtension, enabled: true, dir: pages)

File.write(Path.join(posts, "my-post.md"), """
---
layout: Mix.Tasks.Tableau.BuildTest.RootLayout
title: A Bing Bong Blog Post
date: 2017-02-28
categories: post
permalink: /:title/
---

## Bing

Bong!
""")

page_path = pages |> Path.join("some/deeply/nested/page") |> tap(&File.mkdir_p!/1) |> Path.join("/my-page.md")

File.write(page_path, """
---
layout: Mix.Tasks.Tableau.BuildTest.RootLayout
title: Beginner Tutorial
---

## How to get started
""")

{log, io} =
with_io(fn ->
with_io(:stderr, fn ->
{_, log} =
with_log(fn ->
_documents = Build.run(["--out", out])
Expand All @@ -171,5 +196,7 @@ defmodule Mix.Tasks.Tableau.BuildTest do

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