@@ -22,22 +22,22 @@ defmodule ExDoc.Formatter.HTML do
2222 Formatter . copy_assets ( config . assets , config . output ) ++
2323 Formatter . copy_assets ( additional_assets ( config ) , config . output )
2424
25- search_data = generate_search_data ( project_nodes , extras , config )
25+ search_data = generate_search_data ( config , project_nodes , extras )
2626
2727 { modules , tasks } = Enum . split_with ( project_nodes , & ( & 1 . type != :task ) )
2828
2929 all_files =
3030 search_data ++
3131 static_files ++
32- generate_sidebar_items ( modules , tasks , extras , config ) ++
33- generate_api_reference ( modules , tasks , config ) ++
34- generate_extras ( extras , config ) ++
32+ generate_sidebar_items ( config , modules , tasks , extras ) ++
33+ generate_api_reference ( config , modules , tasks ) ++
34+ generate_extras ( config , extras ) ++
3535 Formatter . copy_favicon ( config , Path . join ( @ assets_dir , "favicon" ) ) ++
3636 Formatter . copy_logo ( config , Path . join ( @ assets_dir , "logo" ) ) ++
3737 generate_search ( config ) ++
3838 generate_not_found ( config ) ++
39- generate_list ( modules , config ) ++
40- generate_list ( tasks , config ) ++
39+ generate_list ( config , modules ) ++
40+ generate_list ( config , tasks ) ++
4141 generate_redirects ( config , ".html" )
4242
4343 entrypoint = config . output |> Path . join ( "index.html" ) |> Path . relative_to_cwd ( )
@@ -48,30 +48,29 @@ defmodule ExDoc.Formatter.HTML do
4848 filename = "404.html"
4949 config = set_canonical_url ( config , filename )
5050 content = Templates . not_found_template ( config )
51- File . write! ( " #{ config . output } / #{ filename } " , content )
51+ write! ( config , filename , content )
5252 [ filename ]
5353 end
5454
5555 defp generate_search ( config ) do
5656 filename = "search.html"
5757 config = set_canonical_url ( config , filename )
5858 content = Templates . search_template ( config )
59- File . write! ( " #{ config . output } / #{ filename } " , content )
59+ write! ( config , filename , content )
6060 [ filename ]
6161 end
6262
63- defp generate_sidebar_items ( modules , tasks , extras , config ) do
63+ defp generate_sidebar_items ( config , modules , tasks , extras ) do
6464 content = Templates . create_sidebar_items ( config , modules , tasks , extras )
65-
6665 path = "dist/sidebar_items-#{ digest ( content ) } .js"
67- File . write! ( Path . join ( config . output , path ) , content )
66+ write! ( config , path , content )
6867 [ path ]
6968 end
7069
71- defp generate_search_data ( linked , extras , config ) do
70+ defp generate_search_data ( config , linked , extras ) do
7271 content = SearchData . create ( linked , extras , config . proglang )
7372 path = "dist/search_data-#{ digest ( content ) } .js"
74- File . write! ( Path . join ( config . output , path ) , content )
73+ write! ( config , path , content )
7574 [ path ]
7675 end
7776
@@ -82,14 +81,14 @@ defmodule ExDoc.Formatter.HTML do
8281 |> binary_part ( 0 , 8 )
8382 end
8483
85- defp generate_extras ( extras , config ) do
84+ defp generate_extras ( config , extras ) do
8685 generated_extras =
8786 extras
8887 |> Enum . reject ( & is_map_key ( & 1 , :url ) )
8988 |> with_prev_next ( )
9089 |> Enum . map ( fn { node , prev , next } ->
9190 filename = "#{ node . id } .html"
92- output = " #{ config . output } / #{ filename } "
91+ output = Path . join ( config . output , filename )
9392 config = set_canonical_url ( config , filename )
9493
9594 refs = % {
@@ -114,7 +113,7 @@ defmodule ExDoc.Formatter.HTML do
114113 for % { source_path: source_path , id: id } when source_path != nil <- extras ,
115114 ext = extension_name ( source_path ) ,
116115 ext == ".livemd" do
117- output = " #{ config . output } / #{ id } #{ ext } "
116+ output = Path . join ( config . output , " #{ id } #{ ext } ")
118117
119118 File . copy! ( source_path , output )
120119
@@ -135,13 +134,13 @@ defmodule ExDoc.Formatter.HTML do
135134 ]
136135 end
137136
138- defp generate_api_reference ( _modules , _tasks , % { api_reference: false } ) do
137+ defp generate_api_reference ( % { api_reference: false } , _modules , _tasks ) do
139138 [ ]
140139 end
141140
142- defp generate_api_reference ( modules , tasks , config ) do
141+ defp generate_api_reference ( config , modules , tasks ) do
143142 filename = "api-reference.html"
144- output = " #{ config . output } / #{ filename } "
143+ output = Path . join ( config . output , filename )
145144 config = set_canonical_url ( config , filename )
146145
147146 html = Templates . api_reference_template ( config , modules , tasks )
@@ -154,7 +153,7 @@ defmodule ExDoc.Formatter.HTML do
154153 [ filename ]
155154 end
156155
157- def generate_redirects ( config , ext ) do
156+ defp generate_redirects ( config , ext ) do
158157 config . redirects
159158 |> Map . new ( )
160159 |> Map . put_new ( "index" , config . main )
@@ -173,7 +172,7 @@ defmodule ExDoc.Formatter.HTML do
173172 _ -> to <> ext
174173 end
175174
176- generate_redirect ( source , config , destination )
175+ generate_redirect ( config , source , destination )
177176
178177 source
179178 end )
@@ -185,15 +184,15 @@ defmodule ExDoc.Formatter.HTML do
185184 |> String . downcase ( )
186185 end
187186
188- defp generate_redirect ( filename , config , redirect_to ) do
189- without_anchor = String . split ( redirect_to , "#" ) |> hd ( )
187+ defp generate_redirect ( config , filename , redirect_to ) do
188+ without_anchor = redirect_to |> String . split ( "#" ) |> hd ( )
190189
191- unless case_sensitive_file_regular? ( " #{ config . output } / #{ without_anchor } " ) do
190+ unless config . output |> Path . join ( without_anchor ) |> case_sensitive_file_regular? ( ) do
192191 ExDoc . warn ( "#{ filename } redirects to #{ redirect_to } , which does not exist" , [ ] )
193192 end
194193
195194 content = Templates . redirect_template ( config , redirect_to )
196- File . write! ( " #{ config . output } / #{ filename } " , content )
195+ write! ( config , filename , content )
197196 end
198197
199198 defp case_sensitive_file_regular? ( path ) do
@@ -205,17 +204,17 @@ defmodule ExDoc.Formatter.HTML do
205204 end
206205 end
207206
208- defp generate_list ( nodes , config ) do
207+ defp generate_list ( config , nodes ) do
209208 nodes
210- |> Task . async_stream ( & generate_module_page ( & 1 , config ) , timeout: :infinity )
209+ |> Task . async_stream ( & generate_module_page ( config , & 1 ) , timeout: :infinity )
211210 |> Enum . map ( & elem ( & 1 , 1 ) )
212211 end
213212
214- defp generate_module_page ( module_node , config ) do
213+ defp generate_module_page ( config , module_node ) do
215214 filename = "#{ module_node . id } .html"
216215 config = set_canonical_url ( config , filename )
217216 content = Templates . module_template ( config , module_node )
218- File . write! ( " #{ config . output } / #{ filename } " , content )
217+ write! ( config , filename , content )
219218 filename
220219 end
221220
@@ -231,4 +230,10 @@ defmodule ExDoc.Formatter.HTML do
231230 config
232231 end
233232 end
233+
234+ defp write! ( config , filename , content ) do
235+ config . output
236+ |> Path . join ( filename )
237+ |> File . write! ( content )
238+ end
234239end
0 commit comments