updated page contents
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 5 Feb 2023 04:22:52 +0000 (22:22 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 5 Feb 2023 04:22:52 +0000 (22:22 -0600)
src/app.onyx
www/news-articles/test-article.html [new file with mode: 0644]
www/static/css/new_style.css
www/templates/pages/404.html [new file with mode: 0644]
www/templates/pages/docs.html [new file with mode: 0644]
www/templates/pages/homepage.html
www/templates/pages/news.html [new file with mode: 0644]
www/templates/pages/news_article.html [new file with mode: 0644]
www/templates/partials/footer.html
www/templates/partials/navbar.html

index 848f06e9978f85a8837ef1b293aaa04bc86edf8e..494c1f261fe4560156a398fb93241908bcb976a7 100644 (file)
@@ -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 (file)
index 0000000..aa53365
--- /dev/null
@@ -0,0 +1,7 @@
+<h1>
+    Hello, from the first test article!
+</h1>
+
+<p>
+    These articles are working as desired!
+</p>
index 1095d831f783fc405f27d747528c6473d4e0521c..3bf5e8c7cce35cf7ac0373bcbb913cb7b8b71c5b 100644 (file)
@@ -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 (file)
index 0000000..d5ed672
--- /dev/null
@@ -0,0 +1,15 @@
+{{block "content"}}
+
+{% partial "navbar" %}
+
+<main>
+    <div class="container">
+        <h1>404 - Page not found</h1>
+    </div>
+
+    {% partial "footer" %}
+</main>
+
+{{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 (file)
index 0000000..9addbe8
--- /dev/null
@@ -0,0 +1,11 @@
+{{block "content"}}
+
+{% partial "navbar" %}
+
+<main>
+    {% partial "footer" %}
+</main>
+
+{{endblock}}
+
+{{extends "base"}}
\ No newline at end of file
index 6436b6d8b7080ae9bb7bc42f0dc62f8769863cf6..2861ffab146fcf641874e30d06931ae60077f83e 100644 (file)
@@ -43,6 +43,7 @@ factorial :: (n: i32) -> i32 {
     </div>
     </div>
 
+<!--
     <div class="container light" id="install">
     <h2>Installation</h2>
     <br />
@@ -58,7 +59,6 @@ factorial :: (n: i32) -> i32 {
         <h4>Debian / Ubuntu</h4>
             <p>
                 Debian and Ubuntu will soon have the option of adding an APT repository for Onyx.
-                <!-- For now, a Debian package is available <a href="https://repo.onyxlang.io/deb">here</a>. -->
             </p>
 
         <h4>All Others</h4>
@@ -79,6 +79,7 @@ $ ./build.sh</pre>
         <p>Currently, Onyx is not supported on MacOS.</p>
 
     </div>
+-->
 
     {% partial "footer" %}
 </main>
diff --git a/www/templates/pages/news.html b/www/templates/pages/news.html
new file mode 100644 (file)
index 0000000..f16282a
--- /dev/null
@@ -0,0 +1,23 @@
+{{block "content"}}
+
+{% partial "navbar" %}
+
+<main>
+    <div class="container">
+        <h1>News</h1>
+
+        <ul>
+            {{ foreach $article in $articles }}
+            <li>
+                <a href="/news?a={% $article %}">{% $article %}</a>
+            </li>
+            {{ endforeach }}
+        </ul>
+    </div>
+
+    {% partial "footer" %}
+</main>
+
+{{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 (file)
index 0000000..ac5d491
--- /dev/null
@@ -0,0 +1,15 @@
+{{block "content"}}
+
+{% partial "navbar" %}
+
+<main>
+    <div class="container">
+        {% $article %}
+    </div>
+
+    {% partial "footer" %}
+</main>
+
+{{endblock}}
+
+{{extends "base"}}
\ No newline at end of file
index 33b61a66bcb2bc7e4464195db1e56264bd87de83..9db883826eb1dcfd145796838dd245b43d159b64 100644 (file)
@@ -13,8 +13,8 @@
 
         <div style="flex-grow: 1">
             <h3>Resources</h3>
-            <p>Docs</p>
-            <p>News</p>
+            <a href="/docs">Docs</a>
+            <a href="/news">News</a>
         </div>
 
         <div style="flex-grow: 1">
index 44cb691befbfe646a9e758496520daea3c24b7d3..7e497644f648f48cd18842b82fdf71b9fc7e6701 100644 (file)
@@ -7,7 +7,7 @@
             <a href="/"><span>Home</span></a>
             <a href="/playground"><span>Try Online</span></a>
             <a href="/docs"><span>Docs</span></a>
-            <a href="/"><span>News</span></a>
+            <a href="/news"><span>News</span></a>
             <a href="https://github.com/onyx-lang/onyx" target="_blank"><span>GitHub</span></a>
         </div>
     </navbar>