From fc9b5e598735cb22523600dbf9ef30a5e22384b7 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Mon, 10 Apr 2023 12:46:32 -0500 Subject: [PATCH] cleanup: `/news` index.json loading --- src/app.onyx | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/app.onyx b/src/app.onyx index c0e12b0..10812c4 100644 --- a/src/app.onyx +++ b/src/app.onyx @@ -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 -- 2.25.1