[HN Gopher] Serving Astro with Rust
___________________________________________________________________
Serving Astro with Rust
Author : skwee357
Score : 39 points
Date : 2024-03-10 15:29 UTC (7 hours ago)
(HTM) web link (www.yieldcode.blog)
(TXT) w3m dump (www.yieldcode.blog)
| jitl wrote:
| Reading this, I can't help but feel like the "reject modernity,
| embrace tradition" UI development trend of returning to untyped
| templating languages is throwing the baby out with the bathwater.
| Using jinja/htmx/go-templates helps you avoid a big Javascript
| bundle, but it lands you right back in this 90s/00s toil of
| screwing around binding your "real" programming language to some
| half-baked untyped meta-language that spits out something XML-
| like. If you're picking Rust or any other language where you like
| the typechecker, why throw that all away?
|
| Defining your UI as more-or-less normal functions in your main
| programming language that take normal arguments and return return
| composable UI-typed values is a massive, massive productivity
| win. Lots of teams pick Typescript/React over other
| languages/frameworks they prefer or that have better performance
| for only that reason!
|
| I'm very happy that many production UI systems are moving towards
| a React/Elm-inspired API. On Android, Jetpack Compose means I
| don't need to screw around copy pasting method names between XML
| files and Java classes. On iOS, SwiftUI means I never need to
| plumb delegates around Interface Builder again. In Typescript
| land, there's a zillion React-inspired frameworks, like Astro,
| that carry this learning forward.
|
| If I was in OP's position, I'd be looking for some macros / sugar
| (https://docs.rs/typed-html/latest/typed_html/ came up in a quick
| google search) that make it really easy to write composable UI
| snippets in my regular Rust files. Why introduce a new language,
| a new typechecker, and muck around iteroperating between Rust and
| Typescript, if you can do it all in Rust? You can even add a
| little bit of glue to make HTMX directives that eg do form things
| type-check against the form action they'll POST to. You should be
| able to rely on the Rust compiler to make function calls that
| return strings not error at runtime.
| 0atman wrote:
| This is the right answer. How can you go back to a non-typed
| world after Rust I don't know.
|
| I use html-node which has a typed submodule for even greater
| strictness. I just build some valid html, make a string and
| write that to the output directory and get on with my life. Eg:
| https://github.com/0atman/noboilerplate/
|
| Templates... Rust functions
|
| Flow control... Rust match expression
|
| Abstraction... Rust modules
|
| Html validation... Rust compiler
|
| I like to think that in writing the html-node crate, Vidhan
| taught the compiler to speak html! https://lib.rs/crates/html-
| node
| Thaxll wrote:
| Did OP read Caddy doc before throwing Rust into the mix? I'm
| pretty sure his use case is doable with simple Caddy config.
| dcre wrote:
| It took me a while to understand how little is ultimately going
| on here. If you're using Astro to generate a static site, then
| the question of how to serve it has nothing to do with Rust --
| it's a question you can ask (and which should be relatively easy
| to answer) for any web server.
___________________________________________________________________
(page generated 2024-03-10 23:00 UTC)