From: Brendan Hansen Date: Sun, 5 Feb 2023 04:22:52 +0000 (-0600) Subject: updated page contents X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=1fbed142540ea00e3ff0a9eb07ec33868db1c987;p=onyxlang.io.git updated page contents --- diff --git a/src/app.onyx b/src/app.onyx index 848f06e..494c1f2 100644 --- a/src/app.onyx +++ b/src/app.onyx @@ -11,6 +11,7 @@ reg: otmp.TemplateRegistry; render :: (r: ^http.Response, template: str, vars: any) { s := reg->render_template(template, ^r.writer, .{ vars.data, vars.type }); r->status(200 if s == .None else 400); + r->end(); } } @@ -19,6 +20,40 @@ reg: otmp.TemplateRegistry; res->render("homepage", null); } +@http.route.{.GET, "/docs"} +(req: ^Req, res: ^Res) { + res->render("docs", null); +} + +@http.route.{.GET, "/news"} +(req: ^Req, res: ^Res) { + if a := req.query->get_opt("a"); a { + filename := tprintf("www/news-articles/{}.html", a.value); + if os.file_exists(filename) { + article := os.get_contents(filename); + defer delete(^article); + + res->render("news_article", ^.{ + article = article + }); + } + + } else { + articles := make([..] str); + + for os.list_directory("www/news-articles") { + name := it->name(); + if string.ends_with(name, ".html") { + articles << string.temp_copy(name[0 .. name.length-5]); + } + } + + res->render("news", ^.{ + articles = articles + }); + } +} + main :: () { reg = otmp.registry(); reg->load_directory("./www/templates", ".html"); @@ -40,6 +75,12 @@ main :: () { router->collect_routes(); app->pipe(^router); + app->pipe((req, res) => { + if !res.completed { + res->render("404", null); + } + }); + logger := http.logger(); app->pipe(^logger); diff --git a/www/news-articles/test-article.html b/www/news-articles/test-article.html new file mode 100644 index 0000000..aa53365 --- /dev/null +++ b/www/news-articles/test-article.html @@ -0,0 +1,7 @@ +

+ Hello, from the first test article! +

+ +

+ These articles are working as desired! +

diff --git a/www/static/css/new_style.css b/www/static/css/new_style.css index 1095d83..3bf5e8c 100644 --- a/www/static/css/new_style.css +++ b/www/static/css/new_style.css @@ -50,7 +50,7 @@ a:visited { } .container { - padding: 56px 0; + padding: 56px 12px; } .container > .container.merge { @@ -108,7 +108,7 @@ code { navbar { background: var(--background-color); color: var(--foreground-color); - padding: 0px; + padding: 0 12px; display: flex; flex-direction: row; @@ -152,3 +152,9 @@ navbar a { .footer-container > * { flex-basis: 0; } + +.footer-container a { + display: block; + padding: 2px 0; + text-decoration: none; +} diff --git a/www/templates/pages/404.html b/www/templates/pages/404.html new file mode 100644 index 0000000..d5ed672 --- /dev/null +++ b/www/templates/pages/404.html @@ -0,0 +1,15 @@ +{{block "content"}} + +{% partial "navbar" %} + +
+
+

404 - Page not found

+
+ + {% partial "footer" %} +
+ +{{endblock}} + +{{extends "base"}} \ No newline at end of file diff --git a/www/templates/pages/docs.html b/www/templates/pages/docs.html new file mode 100644 index 0000000..9addbe8 --- /dev/null +++ b/www/templates/pages/docs.html @@ -0,0 +1,11 @@ +{{block "content"}} + +{% partial "navbar" %} + +
+ {% partial "footer" %} +
+ +{{endblock}} + +{{extends "base"}} \ No newline at end of file diff --git a/www/templates/pages/homepage.html b/www/templates/pages/homepage.html index 6436b6d..2861ffa 100644 --- a/www/templates/pages/homepage.html +++ b/www/templates/pages/homepage.html @@ -43,6 +43,7 @@ factorial :: (n: i32) -> i32 { +

All Others

@@ -79,6 +79,7 @@ $ ./build.sh

Currently, Onyx is not supported on MacOS.

+--> {% partial "footer" %} diff --git a/www/templates/pages/news.html b/www/templates/pages/news.html new file mode 100644 index 0000000..f16282a --- /dev/null +++ b/www/templates/pages/news.html @@ -0,0 +1,23 @@ +{{block "content"}} + +{% partial "navbar" %} + +
+
+

News

+ +
    + {{ foreach $article in $articles }} +
  • + {% $article %} +
  • + {{ endforeach }} +
+
+ + {% partial "footer" %} +
+ +{{endblock}} + +{{extends "base"}} \ No newline at end of file diff --git a/www/templates/pages/news_article.html b/www/templates/pages/news_article.html new file mode 100644 index 0000000..ac5d491 --- /dev/null +++ b/www/templates/pages/news_article.html @@ -0,0 +1,15 @@ +{{block "content"}} + +{% partial "navbar" %} + +
+
+ {% $article %} +
+ + {% partial "footer" %} +
+ +{{endblock}} + +{{extends "base"}} \ No newline at end of file diff --git a/www/templates/partials/footer.html b/www/templates/partials/footer.html index 33b61a6..9db8838 100644 --- a/www/templates/partials/footer.html +++ b/www/templates/partials/footer.html @@ -13,8 +13,8 @@

Resources

-

Docs

-

News

+ Docs + News
diff --git a/www/templates/partials/navbar.html b/www/templates/partials/navbar.html index 44cb691..7e49764 100644 --- a/www/templates/partials/navbar.html +++ b/www/templates/partials/navbar.html @@ -7,7 +7,7 @@ Home Try Online Docs - News + News GitHub