@@ -42,6 +42,8 @@ const Args = struct {
4242 exclude_private : bool = false ,
4343 overview_output_file : ? []const u8 = null ,
4444 languages_output_file : ? []const u8 = null ,
45+ overview_template : ? []const u8 = null ,
46+ languages_template : ? []const u8 = null ,
4547
4648 const Self = @This ();
4749
@@ -68,12 +70,17 @@ const Args = struct {
6870 if (self .excluded_langs ) | s | allocator .free (s );
6971 if (self .overview_output_file ) | s | allocator .free (s );
7072 if (self .languages_output_file ) | s | allocator .free (s );
73+ if (self .overview_template ) | s | allocator .free (s );
74+ if (self .languages_template ) | s | allocator .free (s );
7175 }
7276};
7377
74- fn overview (arena : * std.heap.ArenaAllocator , stats : anytype ) ! []const u8 {
78+ fn overview (
79+ arena : * std.heap.ArenaAllocator ,
80+ stats : anytype ,
81+ template : []const u8 ,
82+ ) ! []const u8 {
7583 const a = arena .allocator ();
76- const template : []const u8 = @embedFile ("templates/overview.svg" );
7784 var out_data = template ;
7885 // Vulnerable to template injection. In practice, this should never happen.
7986 inline for (@typeInfo (@TypeOf (stats )).@"struct" .fields ) | field | {
@@ -103,9 +110,12 @@ fn overview(arena: *std.heap.ArenaAllocator, stats: anytype) ![]const u8 {
103110 return out_data ;
104111}
105112
106- fn languages (arena : * std.heap.ArenaAllocator , stats : anytype ) ! []const u8 {
113+ fn languages (
114+ arena : * std.heap.ArenaAllocator ,
115+ stats : anytype ,
116+ template : []const u8 ,
117+ ) ! []const u8 {
107118 const a = arena .allocator ();
108- const template : []const u8 = @embedFile ("templates/languages.svg" );
109119 const progress = try a .alloc ([]const u8 , stats .languages .count ());
110120 const lang_list = try a .alloc ([]const u8 , stats .languages .count ());
111121 for (
@@ -280,12 +290,26 @@ pub fn main() !void {
280290
281291 try writeFile (
282292 args .overview_output_file orelse "overview.svg" ,
283- try overview (& arena , aggregate_stats ),
293+ try overview (
294+ & arena ,
295+ aggregate_stats ,
296+ if (args .overview_template ) | template |
297+ try readFile (arena .allocator (), template )
298+ else
299+ @embedFile ("templates/overview.svg" ),
300+ ),
284301 );
285302
286303 try writeFile (
287304 args .languages_output_file orelse "languages.svg" ,
288- try languages (& arena , aggregate_stats ),
305+ try languages (
306+ & arena ,
307+ aggregate_stats ,
308+ if (args .languages_template ) | template |
309+ try readFile (arena .allocator (), template )
310+ else
311+ @embedFile ("templates/languages.svg" ),
312+ ),
289313 );
290314 }
291315}
0 commit comments