Skip to content

Commit ad4281b

Browse files
committedJun 14, 2023
feat: copy static assets
1 parent 06ef33e commit ad4281b

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed
 

‎README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,23 @@ config :tableau, :assets,
168168

169169
config :tableau, :assets, tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]}
170170

171-
172171
import_config "#{config_env()}.exs"
173172
```
174173

175174
This will start a long running process that will independently build your CSS as it see's files change.
176175

177176
These are started automatically when you run `mix tableau.server`.
178177

178+
### Static Assets
179+
180+
Other static assets can be copied into the "out" directory by placing them in an `extra` directory in the root of your project.
181+
182+
This directory can be configured.
183+
184+
```elixir
185+
config :tableau, :include, "static"
186+
```
187+
179188
### Development
180189

181190
The dev server can be started with `mix tableau.server`. On file change, a browser reload will be triggered and the page your requesting will be re-built during the request.

‎example/extra/foo.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hi

‎lib/mix/tasks/tableau.build.ex

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ defmodule Mix.Tasks.Tableau.Build do
66
@moduledoc "Task to build the tableau site"
77
@shortdoc "Builds the site"
88

9+
@include_dir Application.compile_env(:tableau, :include, "extra")
10+
911
@impl Mix.Task
1012
def run(argv) do
1113
Mix.Task.run("app.start", ["--preload-modules"])
@@ -26,5 +28,9 @@ defmodule Mix.Tasks.Tableau.Build do
2628

2729
File.write!(Path.join(dir, "index.html"), content)
2830
end
31+
32+
if File.exists?(@include_dir) do
33+
File.cp_r!(@include_dir, out)
34+
end
2935
end
3036
end

‎lib/tableau/router.ex

+1-14
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,7 @@ defmodule Tableau.Router do
3030
end
3131

3232
defp rerender(conn, _) do
33-
out = "_site"
34-
mods = :code.all_available()
35-
graph = Tableau.Graph.new(mods)
36-
File.mkdir_p!(out)
37-
38-
for mod <- Graph.vertices(graph), {:ok, :page} == Tableau.Graph.Node.type(mod) do
39-
content = Tableau.Document.render(graph, mod, %{site: %{}})
40-
permalink = mod.__tableau_permalink__()
41-
dir = Path.join(out, permalink)
42-
43-
File.mkdir_p!(dir)
44-
45-
File.write!(Path.join(dir, "index.html"), content, [:sync])
46-
end
33+
Mix.Task.rerun("tableau.build", ["--out", "_site"])
4734

4835
conn
4936
end

‎test/mix/tasks/tableau.build_test.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ defmodule Mix.Tasks.Tableau.BuildTest do
8989

9090
@tag :tmp_dir
9191
test "renders all pages", %{tmp_dir: out} do
92-
documents = Build.run(["--out", out])
92+
_documents = Build.run(["--out", out])
9393

9494
# # FIXME: this is due to the way the page modules are compiled in the tests
9595
# assert 8 == length(documents)

0 commit comments

Comments
 (0)
Please sign in to comment.