Commit 53e971226d

Loris Cro <kappaloris@gmail.com>
2022-08-18 18:02:19
autodoc: minor pr cleanup
1 parent 51a4861
Changed files (3)
lib/docs/main.js
@@ -51,7 +51,7 @@ var zigAnalysis;
   const domHdrName = document.getElementById("hdrName");
   const domHelpModal = document.getElementById("helpModal");
   const domSearchPlaceholder = document.getElementById("searchPlaceholder");
-  const sourceFileUrlTemplate = "src-viewer/{{file}}#L{{line}}"
+  const sourceFileUrlTemplate = "src/{{file}}#L{{line}}"
   const domLangRefLink = document.getElementById("langRefLink");
 
   let lineCounter = 1;
@@ -989,7 +989,7 @@ var zigAnalysis;
           "switch(" +
           cond +
           ") {" +
-          '<a href="/src-viewer/' +
+          '<a href="/src/' +
           file_name +
           "#L" +
           line +
src/Docgen.zig → src/autodoc/render_source.zig
@@ -9,7 +9,7 @@ const print = std.debug.print;
 const mem = std.mem;
 const testing = std.testing;
 const Allocator = std.mem.Allocator;
-const Module = @import("Module.zig");
+const Module = @import("../Module.zig");
 
 pub fn genHtml(
     allocator: Allocator,
@@ -33,7 +33,6 @@ pub fn genHtml(
         \\        line-height: 1.5;
         \\      }
         \\
-        \\      @media screen and (min-width: 1025px) {
         \\      pre > code {
         \\        display: block;
         \\        overflow: auto;
src/Autodoc.zig
@@ -9,7 +9,7 @@ const Package = @import("Package.zig");
 const Zir = @import("Zir.zig");
 const Ref = Zir.Inst.Ref;
 const log = std.log.scoped(.autodoc);
-const Docgen = @import("Docgen.zig");
+const Docgen = @import("autodoc/render_source.zig");
 
 module: *Module,
 doc_location: Compilation.EmitLoc,
@@ -243,6 +243,7 @@ pub fn generateZirData(self: *Autodoc) !void {
         try d.handle.openDir(self.doc_location.basename, .{})
     else
         try self.module.zig_cache_artifact_directory.handle.openDir(self.doc_location.basename, .{});
+
     {
         const data_js_f = try output_dir.createFile("data.js", .{});
         defer data_js_f.close();
@@ -267,25 +268,27 @@ pub fn generateZirData(self: *Autodoc) !void {
         try buffer.flush();
     }
 
-    output_dir.makeDir("src-viewer") catch |e| switch (e) {
-        error.PathAlreadyExists => {},
-        else => |err| return err,
-    };
-    const html_dir = try output_dir.openDir("src-viewer", .{});
+    {
+        output_dir.makeDir("src") catch |e| switch (e) {
+            error.PathAlreadyExists => {},
+            else => |err| return err,
+        };
+        const html_dir = try output_dir.openDir("src", .{});
 
-    var files_iterator = self.files.iterator();
+        var files_iterator = self.files.iterator();
 
-    while (files_iterator.next()) |entry| {
-        const new_html_path = entry.key_ptr.*.sub_file_path;
+        while (files_iterator.next()) |entry| {
+            const new_html_path = entry.key_ptr.*.sub_file_path;
 
-        const html_file = try createFromPath(html_dir, new_html_path);
-        defer html_file.close();
-        var buffer = std.io.bufferedWriter(html_file.writer());
+            const html_file = try createFromPath(html_dir, new_html_path);
+            defer html_file.close();
+            var buffer = std.io.bufferedWriter(html_file.writer());
 
-        const out = buffer.writer();
+            const out = buffer.writer();
 
-        try Docgen.genHtml(self.module.gpa, entry.key_ptr.*, out);
-        try buffer.flush();
+            try Docgen.genHtml(self.module.gpa, entry.key_ptr.*, out);
+            try buffer.flush();
+        }
     }
 
     // copy main.js, index.html