feat: Mostly implemented routing using url-routing package.

This commit is contained in:
2025-01-19 00:06:57 -05:00
parent da41da566b
commit d27a19863a
8 changed files with 626 additions and 225 deletions

View File

@@ -28,4 +28,16 @@ extension Request {
let html = try await html()
return HTMLResponse { html }
}
// Render the html if we're an htmx request, otherwise render the main page.
func render<C: HTML, D: SendableHTMLDocument>(
mainPage: (C) async throws -> D,
@HTMLBuilder html: () async throws -> C
) async rethrows -> HTMLResponse where C: Sendable {
let html = try await html()
guard isHtmxRequest else {
return try await render { try await mainPage(html) }
}
return HTMLResponse { html }
}
}