@@ -9,6 +9,7 @@ const Package = @import("Package.zig");
99const Zir = @import ("Zir.zig" );
1010const Ref = Zir .Inst .Ref ;
1111const log = std .log .scoped (.autodoc );
12+ const Docgen = @import ("autodoc/render_source.zig" );
1213
1314module : * Module ,
1415doc_location : Compilation.EmitLoc ,
@@ -242,6 +243,7 @@ pub fn generateZirData(self: *Autodoc) !void {
242243 try d .handle .openDir (self .doc_location .basename , .{})
243244 else
244245 try self .module .zig_cache_artifact_directory .handle .openDir (self .doc_location .basename , .{});
246+
245247 {
246248 const data_js_f = try output_dir .createFile ("data.js" , .{});
247249 defer data_js_f .close ();
@@ -266,13 +268,56 @@ pub fn generateZirData(self: *Autodoc) !void {
266268 try buffer .flush ();
267269 }
268270
271+ {
272+ output_dir .makeDir ("src" ) catch | e | switch (e ) {
273+ error .PathAlreadyExists = > {},
274+ else = > | err | return err ,
275+ };
276+ const html_dir = try output_dir .openDir ("src" , .{});
277+
278+ var files_iterator = self .files .iterator ();
279+
280+ while (files_iterator .next ()) | entry | {
281+ const new_html_path = entry .key_ptr .* .sub_file_path ;
282+
283+ const html_file = try createFromPath (html_dir , new_html_path );
284+ defer html_file .close ();
285+ var buffer = std .io .bufferedWriter (html_file .writer ());
286+
287+ const out = buffer .writer ();
288+
289+ try Docgen .genHtml (self .module .gpa , entry .key_ptr .* , out );
290+ try buffer .flush ();
291+ }
292+ }
293+
269294 // copy main.js, index.html
270295 var docs_dir = try self .module .comp .zig_lib_directory .handle .openDir ("docs" , .{});
271296 defer docs_dir .close ();
272297 try docs_dir .copyFile ("main.js" , output_dir , "main.js" , .{});
273298 try docs_dir .copyFile ("index.html" , output_dir , "index.html" , .{});
274299}
275300
301+ fn createFromPath (base_dir : std.fs.Dir , path : []const u8 ) ! std.fs.File {
302+ var path_tokens = std .mem .tokenize (u8 , path , std .fs .path .sep_str );
303+ var dir = base_dir ;
304+ while (path_tokens .next ()) | toc | {
305+ if (path_tokens .peek () != null ) {
306+ dir .makeDir (toc ) catch | e | switch (e ) {
307+ error .PathAlreadyExists = > {},
308+ else = > | err | return err ,
309+ };
310+ dir = try dir .openDir (toc , .{});
311+ } else {
312+ return dir .createFile (toc , .{}) catch | e | switch (e ) {
313+ error .PathAlreadyExists = > try dir .openFile (toc , .{}),
314+ else = > | err | return err ,
315+ };
316+ }
317+ }
318+ return error .EmptyPath ;
319+ }
320+
276321/// Represents a chain of scopes, used to resolve decl references to the
277322/// corresponding entry in `self.decls`.
278323const Scope = struct {
0 commit comments