@@ -24,6 +24,7 @@ const log = @import("log.zig");
2424const App = @import ("app.zig" ).App ;
2525const Server = @import ("server.zig" ).Server ;
2626const Browser = @import ("browser/browser.zig" ).Browser ;
27+ const DumpStripMode = @import ("browser/dump.zig" ).Opts .StripMode ;
2728
2829const build_config = @import ("build_config" );
2930
@@ -184,7 +185,7 @@ fn run(alloc: Allocator) !void {
184185 try page .dump (.{
185186 .page = page ,
186187 .with_base = opts .withbase ,
187- .exclude_scripts = opts .noscript ,
188+ .strip_mode = opts .strip_mode ,
188189 }, & writer .interface );
189190 try writer .interface .flush ();
190191 }
@@ -292,8 +293,8 @@ const Command = struct {
292293 url : []const u8 ,
293294 dump : bool = false ,
294295 common : Common ,
295- noscript : bool = false ,
296296 withbase : bool = false ,
297+ strip_mode : DumpStripMode = .{},
297298 };
298299
299300 const Common = struct {
@@ -372,7 +373,14 @@ const Command = struct {
372373 \\Options:
373374 \\--dump Dumps document to stdout.
374375 \\ Defaults to false.
375- \\--noscript Exclude <script> tags in dump. Defaults to false.
376+ \\
377+ \\--strip_mode Comma separated list of tag groups to remove from dump
378+ \\ the dump. e.g. --strip_mode js,css
379+ \\ - "js" script and link[as=script, rel=preload]
380+ \\ - "ui" includes img, picture, video, css and svg
381+ \\ - "css" includes style and link[rel=stylesheet]
382+ \\ - "full" includes js, ui and css
383+ \\
376384 \\--with_base Add a <base> tag in dump. Defaults to false.
377385 \\
378386 ++ common_options ++
@@ -460,6 +468,10 @@ fn inferMode(opt: []const u8) ?App.RunMode {
460468 return .fetch ;
461469 }
462470
471+ if (std .mem .eql (u8 , opt , "--strip_mode" )) {
472+ return .fetch ;
473+ }
474+
463475 if (std .mem .eql (u8 , opt , "--with_base" )) {
464476 return .fetch ;
465477 }
@@ -545,10 +557,10 @@ fn parseFetchArgs(
545557 args : * std.process.ArgIterator ,
546558) ! Command.Fetch {
547559 var dump : bool = false ;
548- var noscript : bool = false ;
549560 var withbase : bool = false ;
550561 var url : ? []const u8 = null ;
551562 var common : Command.Common = .{};
563+ var strip_mode : DumpStripMode = .{};
552564
553565 while (args .next ()) | opt | {
554566 if (std .mem .eql (u8 , "--dump" , opt )) {
@@ -557,7 +569,11 @@ fn parseFetchArgs(
557569 }
558570
559571 if (std .mem .eql (u8 , "--noscript" , opt )) {
560- noscript = true ;
572+ log .warn (.app , "deprecation warning" , .{
573+ .feature = "--noscript argument" ,
574+ .hint = "use '--strip_mode js' instead" ,
575+ });
576+ strip_mode .js = true ;
561577 continue ;
562578 }
563579
@@ -566,6 +582,32 @@ fn parseFetchArgs(
566582 continue ;
567583 }
568584
585+ if (std .mem .eql (u8 , "--strip_mode" , opt )) {
586+ const str = args .next () orelse {
587+ log .fatal (.app , "missing argument value" , .{ .arg = "--strip_mode" });
588+ return error .InvalidArgument ;
589+ };
590+
591+ var it = std .mem .splitScalar (u8 , str , ',' );
592+ while (it .next ()) | part | {
593+ const trimmed = std .mem .trim (u8 , part , & std .ascii .whitespace );
594+ if (std .mem .eql (u8 , trimmed , "js" )) {
595+ strip_mode .js = true ;
596+ } else if (std .mem .eql (u8 , trimmed , "ui" )) {
597+ strip_mode .ui = true ;
598+ } else if (std .mem .eql (u8 , trimmed , "css" )) {
599+ strip_mode .css = true ;
600+ } else if (std .mem .eql (u8 , trimmed , "full" )) {
601+ strip_mode .js = true ;
602+ strip_mode .ui = true ;
603+ strip_mode .css = true ;
604+ } else {
605+ log .fatal (.app , "invalid option choice" , .{ .arg = "--strip_mode" , .value = trimmed });
606+ }
607+ }
608+ continue ;
609+ }
610+
569611 if (try parseCommonArg (allocator , opt , args , & common )) {
570612 continue ;
571613 }
@@ -591,8 +633,8 @@ fn parseFetchArgs(
591633 .url = url .? ,
592634 .dump = dump ,
593635 .common = common ,
594- .noscript = noscript ,
595636 .withbase = withbase ,
637+ .strip_mode = strip_mode ,
596638 };
597639}
598640
0 commit comments