Created
September 20, 2023 15:12
-
-
Save marler8997/690d2f5b1d21b0974b1421c82ae3c544 to your computer and use it in GitHub Desktop.
Zig Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const stdout = std.io.getStdOut().writer(); | |
fn raw(s: []const u8) void { | |
stdout.writeAll(s) catch |err| @panic(@errorName(err)); | |
} | |
fn fmt(comptime spec: []const u8, args: anytype) void { | |
stdout.print(spec, args) catch |err| @panic(@errorName(err)); | |
} | |
fn load(comptime T: type) T { | |
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
// hardcoded mock data | |
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
return T{ | |
.releases = &[_]In.Release{ | |
.{ | |
.name = "master", | |
.date = "2023-09-19", | |
.notes = null, | |
}, | |
.{ | |
.name = "0.11.0", | |
.date = "2023-08-04", | |
.notes = "example notes", | |
}, | |
}, | |
.i18n = .{ | |
.downloads_heading = "Releases", | |
.downloads_install_from_pkg_manager = "You can also <a href=\"https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager\"> install Zig from a package manager</a>.", | |
.downloads_json = "There is a <a href=\"https://ziglang.org/download/index.json\">JSON version of this page</a>.", | |
.downloads_minisig = "Files are signed with <a href=\"https://jedisct1.github.io/minisign/\">minisign</a> using this public key:", | |
}, | |
}; | |
} | |
const In = struct { | |
releases: []const Release, | |
i18n: struct { | |
downloads_heading: []const u8, | |
downloads_install_from_pkg_manager: []const u8, | |
downloads_json: []const u8, | |
downloads_minisig: []const u8, | |
}, | |
const Release = struct { | |
name: []const u8, | |
date: []const u8, | |
notes: ?[]const u8, | |
}; | |
}; | |
pub fn main() void { | |
const in = load(In); | |
raw( | |
\\<div class="container"> | |
\\ | |
); | |
raw("<h1>"); | |
raw(in.i18n.downloads_heading); | |
raw("</h1>\n"); | |
raw("<p>"); | |
raw(in.i18n.downloads_install_from_pkg_manager); | |
raw("</p>\n"); | |
raw("<p>"); | |
raw(in.i18n.downloads_json); | |
raw("</p>\n"); | |
raw("<p>"); | |
raw(in.i18n.downloads_minisig); | |
raw("</p>\n"); | |
raw("<pre><code>RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U</code></pre>\n"); | |
raw("<div>\n"); | |
for (in.releases) |release| { | |
genRelease(in, release); | |
} | |
raw("</div>\n"); | |
raw("</div>\n"); | |
} | |
fn genRelease(in: In, release: In.Release) void { | |
_ = in; | |
fmt( | |
\\<h2 id="release-{[name]s}">{[name]s}</h2> | |
\\ | |
, | |
.{ .name = release.name }, | |
); | |
raw("<ul>\n"); | |
fmt("<li>{s}</li>", .{release.date}); | |
if (release.notes) |notes| { | |
fmt("<li>{s}</li>", .{notes}); | |
} | |
// <li>{{ i18n "download-documentation" (index $release "docs") | safeHTML }}</li> | |
// {{ if isset $release "stdDocs"}} | |
// <li>{{ i18n "download-stdlib-docs" (index $release "stdDocs") | safeHTML }}</li> | |
// {{ end }} | |
raw("</ul>\n"); | |
// </ul> | |
// | |
// <table> | |
// <colgroup> | |
// <col width="10%"> | |
// <col width="10%"> | |
// <col width="40%"> | |
// <col width="10%"> | |
// </colgroup> | |
// <thead> | |
// <tr> | |
// <th>{{ i18n "download-os" }}</th> | |
// <th>{{ i18n "download-arch" }}</th> | |
// <th>{{ i18n "download-filename" }}</th> | |
// <th>{{ i18n "download-sig" }}</th> | |
// <th>{{ i18n "download-size" }}</th> | |
// </tr> | |
// </thead> | |
// <tbody> | |
// {{ range $section_name := $.Site.Params.download_section_order }} | |
// {{ $section := index $.Site.Params.download_section $section_name }} | |
// {{ $rows := slice }} | |
// {{ range $row_index, $row_name := $section.rows }} | |
// {{ $target_name := printf "%s%s" $row_name $section.release_suffix }} | |
// {{ with index $release $target_name }} | |
// {{ $rows = $rows | append $row_name }} | |
// {{ end }} | |
// {{ end }} | |
// | |
// {{ range $row_index, $row_name := $rows }} | |
// <tr> | |
// {{ if eq $row_index 0 }} | |
// {{ $title := $section.title }} | |
// {{ if eq $section_name "src" }} | |
// {{ $title = i18n $title }} | |
// {{ end }} | |
// <th rowspan="{{ len $rows }}">{{ $title }}</th> | |
// {{ end }} | |
// {{ $td_class := "" }} | |
// {{ if eq $row_index (sub (len $rows) 1) }} | |
// {{ $td_class = "last-row-in-section" }} | |
// {{ end }} | |
// {{ $arch := $row_name }} | |
// {{ if eq $section_name "src" }} | |
// {{ $arch = "" }} | |
// {{ end }} | |
// | |
// {{ $target_name := printf "%s%s" $row_name $section.release_suffix }} | |
// {{ with index $release $target_name}} | |
// <td class="{{$td_class}}">{{ $arch }}</td> | |
// <td class="{{$td_class}}"><a href="{{ index . "tarball"}}">{{ path.Base (index . "tarball")}}</a></td> | |
// <td class="{{$td_class}}"><a href="{{ index . "tarball"}}.minisig">minisig</a></td> | |
// <td class="{{$td_class}}">{{ lang.NumFmt 1 (div (int (index . "size")) 1048576.0)}}MiB</td> | |
// {{ end }} | |
// </tr> | |
// {{ end }} | |
// <tr> | |
// {{ end }} | |
// </tbody> | |
// </table> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment