From: Brendan Hansen Date: Mon, 10 Apr 2023 17:46:32 +0000 (-0500) Subject: cleanup: `/news` index.json loading X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=fc9b5e598735cb22523600dbf9ef30a5e22384b7;p=onyxlang.io.git cleanup: `/news` index.json loading --- 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