Makko, the people-oriented static site generator made for blogging. forge.starlightnet.work/Team/Makko
ssg static-site-generator makko starlight-network
at main 4.3 kB view raw
1const std = @import("std"); 2const args = @import("args"); 3 4const live = @import("live.zig").live; 5const helper = @import("helper.zig"); 6 7const Makko = @import("Makko.zig"); 8const Log = @import("Log.zig"); 9 10// TODO: Fix this. 11// depends on: https://github.com/ziglang/zig/issues/22775 12// const Setup = @import("build.zig.zon"); 13// 14const VERSION_STRING = "2.1.0"; 15 16const Arguments = struct { 17 help: bool = false, 18 version: bool = false, 19 20 live: bool = false, 21 public: bool = false, 22 port: u16 = 4040, 23 24 pub const shorthands = .{ 25 .h = "help", 26 .v = "version", 27 .l = "live", 28 .p = "public", 29 }; 30}; 31 32fn version(out: Log) !void { 33 out.raw("Starlight Makko v{s}\n\n", .{VERSION_STRING}); 34} 35 36fn help(out: Log) !void { 37 out.header("STARLIGHT MAKKO"); 38 out.raw( 39 \\ Makko is the simple static site generator that loves you back. 40 \\ 41 , .{}); 42 43 out.header("USAGE"); 44 out.raw( 45 \\ makko [options] <folder> 46 \\ 47 \\ --help, -h: Displays this screen. 48 \\ 49 \\ --version, -v: Displays version information. (v{s}) 50 \\ 51 \\ --live, -l: Enables the live-development environment. 52 \\ 53 \\ --public, -p: Makes the live-environment visible to other 54 \\ devices on the network. 55 \\ 56 \\ --port: Sets the port for the live-environment. 57 \\ (Default is 4040.) 58 \\ 59 \\ <folder>: The folder that contains your Makko project. 60 \\ 61 , .{VERSION_STRING}); 62 63 out.header("ABOUT PROJECTS"); 64 out.raw( 65 \\ If the project folder you specify does not have a 'makko.json' 66 \\ file (which is a sort-of database for Makko), it will generate 67 \\ one in the spot as necessary, you are advised to revise it. 68 \\ 69 \\ If any of the specified paths on the 'makko.json' file do not 70 \\ exist, Makko will create and populate them with examples. 71 \\ 72 \\ If any template is unavailable, Makko will generate an 73 \\ example template in its place. 74 \\ 75 , .{}); 76 77 out.header("LEARN MORE"); 78 out.raw( 79 \\ Documentation: https://makko.starlightnet.work/ 80 \\ GIT Repository: https://forge.starlightnet.work/Team/Makko/ 81 \\ About us: https://starlightnet.work/ 82 \\ 83 \\ 84 , .{}); 85} 86 87pub fn main() !void { 88 var gpa = std.heap.GeneralPurposeAllocator(.{}){}; 89 defer _ = gpa.deinit(); 90 const allocator = gpa.allocator(); 91 92 const options = args.parseForCurrentProcess( 93 Arguments, 94 allocator, 95 .print, 96 ) catch return; 97 defer options.deinit(); 98 99 var log = Log.init(); 100 101 if (options.options.version) 102 return try version(log); 103 104 if (options.options.help) 105 return try help(log); 106 107 const p = options.positionals.len; 108 if (p != 1) { 109 log.err("Expected 1 positional, got {}.", .{p}); 110 if (p == 0) 111 log.info("Hint: Pass a folder to Makko!", .{}); 112 return try help(log); 113 } 114 115 const root = options.positionals[0]; 116 if (!helper.isDir(std.fs.cwd(), root)) 117 log.fatal("Path '{s}' is not a folder!", .{root}); 118 119 var makko = Makko.open(root, allocator) catch |err| 120 log.fatal("Could not open or set up Makko state! ({})\n", .{err}); 121 122 defer makko.deinit(); 123 124 makko.loadTemplates() catch |err| 125 log.err("Could not load templates! ({})", .{err}); 126 127 blk: { 128 var pass = try makko.automaticPass(); 129 defer pass.deinit(); 130 131 makko.generateFeeds() catch |err| 132 log.err("Could not generate feeds! ({})", .{err}); 133 134 // No changes made! :O 135 if (pass.changes.items.len == 0) { 136 log.info("Nothing to do!", .{}); 137 break :blk; 138 } 139 140 log.info("Starlight Makko v{s}", .{VERSION_STRING}); 141 142 // I... don't know how this could fail! other than alloc/os stuff 143 try makko.storeDatabase(); 144 try pass.printChanges(); 145 146 pass.runCallbacks() catch |err| 147 log.err("Could not run callbacks! ({})", .{err}); 148 } 149 150 // Enable live mode if one happens to pass --live (-l) 151 if (options.options.live) 152 try live(options.options.public, options.options.port, &makko); 153}