cleanup: `/news` index.json loading
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 10 Apr 2023 17:46:32 +0000 (12:46 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 10 Apr 2023 17:46:32 +0000 (12:46 -0500)
src/app.onyx

index c0e12b0a0e30c689a90b1d1507508e6a76e479e2..10812c4353e1fc6b8b84f8cb824ea7bf25a61ac7 100644 (file)
@@ -3,7 +3,7 @@ use runtime
 use otmp
 use http
 use http.server {Req :: Request, Res :: Response, route}
-use json
+use core.encoding.json
 
 #inject runtime.vars {
     Enable_Heap_Debug :: true
@@ -61,7 +61,7 @@ reg: otmp.TemplateRegistry;
 @route.{.GET, "/news"}
 (req: &Req, res: &Res) {
     Article :: struct { name, description, path, date: str }
-    articles := make([..] Article);
+    articles: [] Article;
 
     article_file := os.get_contents("www/news-articles/index.json");
     article_index, json_err := json.decode_with_error(article_file);
@@ -70,13 +70,7 @@ reg: otmp.TemplateRegistry;
         return;
     }
 
-    for article_index.root->as_array() {
-        name := it["name"]->as_str();
-        desc := it["description"]->as_str();
-        path := it["path"]->as_str();
-        date := it["date"]->as_str();
-        articles << .{ name, desc, path, date };
-    }
+    json.as_any(article_index.root, &articles);
 
     res->render("pages/news", &.{
         articles = articles