Skip to content

Commit

Permalink
zig- add user page
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro committed Aug 25, 2021
1 parent e33726e commit 65d2106
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/handler/_.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ const mime = @import("../mime.zig");

const __ = @import("./_internal.zig");
const _index = @import("./index.zig");
const _user = @import("./user.zig");

pub fn getHandler() http.RequestHandler(void) {
return http.router.Router(void, &.{
http.router.get("/", _index.get),
file_route("/theme.css"),
http.router.get("/about", StaticPek("/about.pek").get),
http.router.get("/contact", StaticPek("/contact.pek").get),
http.router.get("/:remote/:user", _user.get),
});
}

Expand Down
22 changes: 22 additions & 0 deletions src/handler/user.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const std = @import("std");
const string = []const u8;
const http = @import("apple_pie");

const db = @import("./../db/_.zig");
const _internal = @import("./_internal.zig");

pub fn get(_: void, response: *http.Response, request: http.Request, args: struct { remote: u64, user: string }) !void {
_ = args;
const alloc = request.arena;
const r = try db.Remote.byID(alloc, args.remote);
const o = try r.?.findUserByName(alloc, args.user);
const p = try o.?.packages(alloc);

try _internal.writePageResponse(alloc, response, request, "/user.pek", .{
.aquila_version = @import("root").version,
.logged_in = false,
.repo = r.?,
.owner = o.?,
.pkgs = p,
});
}
18 changes: 18 additions & 0 deletions www/user.pek
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
h2("@"{owner.name}"'s Packages")
div[class="pkg-grid"](
{#each pkgs}
div[class="terminal-card"](
div(
h3[style="margin-bottom: 0;"](
a[href=("./"{owner.name}"/"{this.name})]({this.name})
{#ifequal repo.type "github"}span(img[src=("https://img.shields.io/github/stars/"{this.remote_name}"?style=flat")])/ifequal/
)
div(i[class="balance scale icon"]" "{#if this.license}{this.license}<else>"No"/if/" License")
div({this.description}"&nbsp;")
)
)
/each/
)
)
)
)

0 comments on commit 65d2106

Please sign in to comment.