]> git.bts.cx Git - cx.git/commitdiff
Basic page support
authorBen Sherratt <redacted>
Fri, 3 Jul 2026 17:51:30 +0000 (18:51 +0100)
committerBen Sherratt <redacted>
Fri, 3 Jul 2026 17:51:30 +0000 (18:51 +0100)
cx/cx.php
cx/lib/posts.php
cx/templates/admin/post.php
cx/templates/public/base.php
public/design/css/style.css

index 2c71761dd179e4ba3e6c3f7c6b8a207af7cb8e27..d54b3d4f12133e19af14f2169a948d4e8171b959 100644 (file)
--- a/cx/cx.php
+++ b/cx/cx.php
@@ -102,8 +102,8 @@ function cx_route($path) {
                                        $template_variables['post_slug'] = '';
                                        $template_variables['post_date'] = '';
                                        $template_variables['post_data'] = '';
+                                       $template_variables['post_is_page'] = false;
                                        $template_variables['post_is_draft'] = true;
-                                       
 
                                        $template_class = 'admin';
                                        $template = 'post';
@@ -115,6 +115,7 @@ function cx_route($path) {
                                        $template_variables['post_slug'] = $post->slug;
                                        $template_variables['post_date'] = $post->date;
                                        $template_variables['post_data'] = $post->data;
+                                       $template_variables['post_is_page'] = $post->is_page;
                                        $template_variables['post_is_draft'] = $post->is_draft;
 
                                        $template_class = 'admin';
@@ -125,14 +126,15 @@ function cx_route($path) {
                                        if (isset($slug) == false) $slug = null;
                                        $date = cx_form_input_sanitized_date_time('post_date');
                                        if (isset($date) == false) $date = null;
+                                       $page = cx_form_input_sanitized('post_is_page') == 'page';
                                        $draft = cx_form_input_sanitized('post_is_draft') == 'draft';
                                        $data = cx_form_input_sanitized_allowing_html('post_data');
                                        
                                        if (isset($_GET['id']) == false or $_GET['id'] == 0) {
-                                               cx_posts_add_post(1, $title, $slug, $date, $draft, $data);
+                                               cx_posts_add_post(1, $title, $slug, $date, $page, $draft, $data);
                                        } else {
                                                $id = $_GET['id'];
-                                               cx_posts_update_post($id, $title, $slug, $date, $draft, $data);
+                                               cx_posts_update_post($id, $title, $slug, $date, $page, $draft, $data);
                                        }
                                        
                                        cx_http_redirect(cx_url_admin('/'));
@@ -168,15 +170,28 @@ function cx_route($path) {
 
                $template = 'list';
                $template_variables['page_number'] = $page_number;
-       } else if (count($path_components) >= 3) { // FIXME sometime, needs more flexibility...
-               $year = $path_components[0];
-               $month = $path_components[1];
-               $slug = $path_components[2];
+       } else {
+               if (count($path_components) >= 1) {
+                       $slug = $path_components[0];
+                       $page_id = cx_posts_find_page_id($slug);
+                       if ($page_id) {
+                               $template = 'post';
+                               $template_variables['post_id'] = cx_posts_find_page_id($slug);
+                       }
+               }
 
-               $template = 'post';
-               $template_variables['post_id'] = cx_posts_find_post_id($slug);
+               if ($template == null && count($path_components) >= 3) { // FIXME sometime, needs more flexibility...
+                       $year = $path_components[0];
+                       $month = $path_components[1];
+                       $slug = $path_components[2];
+                       $post_id = cx_posts_find_article_id($slug);
+                       if ($post_id) {
+                               $template = 'post';
+                               $template_variables['post_id'] = cx_posts_find_article_id($slug);
+                       }
+               }
        }
-       
+
        if ($template != null) {
                $output = cx_template_render($template_class, $template, $template_variables);
                echo($output);
index b187c51c46c41f3a55b72b39a085d9792d77ab20..64374333e6636212486f084cd7c838c6016a2b96 100644 (file)
@@ -71,7 +71,7 @@ function cx_post_make_slug($title) {
        return $slug;
 }
 
-function cx_posts_add_post($site_id, $title, $slug, $date, $draft, $data) {
+function cx_posts_add_post($site_id, $title, $slug, $date, $page, $draft, $data) {
        $creation_time = $update_time = time();
        
        if ($slug == null) {
@@ -94,10 +94,10 @@ function cx_posts_add_post($site_id, $title, $slug, $date, $draft, $data) {
                        post_data,
                        post_data_version)
                VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);';
-       cx_db_exec($sql, $site_id, $creation_time, $update_time, $slug, $date, false, $draft, $title, $data, 1);
+       cx_db_exec($sql, $site_id, $creation_time, $update_time, $slug, $date, $page, $draft, $title, $data, 1);
 }
 
-function cx_posts_update_post($post_id, $title, $slug, $date, $draft, $data) {
+function cx_posts_update_post($post_id, $title, $slug, $date, $page, $draft, $data) {
        $update_time = time();
        
        if ($slug == null) {
@@ -112,12 +112,13 @@ function cx_posts_update_post($post_id, $title, $slug, $date, $draft, $data) {
                SET post_update_time = ?,
                post_slug = ?,
                post_date = ?,
+               post_is_page = ?,
                post_is_draft = ?,
                post_title = ?,
                post_data = ?
                WHERE post_id == ?;';
                //LIMIT 1;';
-       cx_db_exec($sql, $update_time, $slug, $date, $draft, $title, $data, $post_id);
+       cx_db_exec($sql, $update_time, $slug, $date, $page, $draft, $title, $data, $post_id);
 }
 
 function cx_posts_delete_post($post_id) {
@@ -189,8 +190,7 @@ function cx_posts_find_post($post_id) {
                post_title,
                post_data
                FROM posts
-               WHERE post_is_page == FALSE
-               AND post_id == ?
+               WHERE post_id == ?
                LIMIT 1;';
 
        foreach (cx_db_query($sql, $post_id) as $post) {
@@ -201,11 +201,29 @@ function cx_posts_find_post($post_id) {
        return null;
 }
 
-function cx_posts_find_post_id($post_slug) {
+function cx_posts_find_article_id($post_slug) {
        $sql = 'SELECT
                post_id
                FROM posts
                WHERE post_slug == ?
+               AND post_is_page == FALSE
+               AND post_is_draft == FALSE
+               LIMIT 1;';
+
+       foreach (cx_db_query($sql, $post_slug) as $post) {
+               return $post['post_id'];
+       }
+
+       return null;
+}
+
+function cx_posts_find_page_id($post_slug) {
+       $sql = 'SELECT
+               post_id
+               FROM posts
+               WHERE post_slug == ?
+               AND post_is_page == TRUE
+               AND post_is_draft == FALSE
                LIMIT 1;';
 
        foreach (cx_db_query($sql, $post_slug) as $post) {
index aa7f870ca25dcec0922b5ff71440f6e29f41e17c..6ce9e069b2b183bee3fb81c7eee6c2d3bb0224d8 100644 (file)
@@ -5,6 +5,7 @@
 <p>title: <input name="post_title" type="text" value="<?= $post_title ?>"></p>
 <p>slug: <input name="post_slug" type="text" value="<?= $post_slug ?>"></p>
 <p>date: <input name="post_date" type="text" value="<?= $post_date ? date('Y-m-d H:i:s', $post_date) : "" ?>"></p>
+<p>page: <input name="post_is_page" type="checkbox" value="page" <?= $post_is_page ? "checked" : "" ?>></p>
 <p>draft: <input name="post_is_draft" type="checkbox" value="draft" <?= $post_is_draft ? "checked" : "" ?>></p>
 <p><textarea name="post_data"  cols="60" rows="40"><?= $post_data ?></textarea></p>
 
index 8629d34791096bc801fdc78e8b51d5b509b9d005..10c5cd17613bc062fe8daa59e30cb141651c94f8 100644 (file)
   <p>Find me <a href="https://mastodon.gamedev.place/@btsherratt" rel="me">@btsherratt</a> or on <a href="https://bts.itch.io/">itch.io</a></p>
 </header>
 
-<?php /*<nav>
+<nav>
 
 <ul role="list">
 <li><a href="<?= cx_url('/'); ?>">Home</a></li>
 
 <?php foreach (cx_pages_get() as $page): ?>
-<li><a href="<?= cx_url($page->url); ?>"><?= $page->title ?></a></li>
+<li><a href="<?= cx_url('/' . $page->slug); ?>"><?= $page->title ?></a></li>
 <?php endforeach; ?>
 </ul>
 
-</nav> */ ?>
+</nav>
 
 <?= cx_template_content(); ?>
 
index 27e627b0db15a2fbda74e8e243ca772d0778515f..a5c06ec02b33420c6a10a5dd521e8d556529fcb8 100644 (file)
@@ -12,6 +12,7 @@
 /* Layout */
 
 body {
+       background: #fcfcfc;
        display: flex;
        flex-direction: column;
        min-height: 100vh;
@@ -30,10 +31,6 @@ body > * {
        margin-right: auto;
 }
 
-header {
-       margin-bottom: 8vh;
-}
-
 header h1 {
        font-size: 2em;
 }
@@ -43,6 +40,15 @@ header h1 a {
        text-decoration: none;
 }
 
+header p {
+       font-size: 0.8em;
+}
+
+nav {
+       margin-top: 2vh;
+       margin-bottom: 4vh;
+}
+
 nav ul {
        list-style: none;
        display: flex;
@@ -131,6 +137,11 @@ a {
        text-underline-offset: 0.08em;
 }
 
+a:hover {
+       background-color: navy;
+       color: #fcfcfc;
+}
+
 a:focus {
        outline: 1px solid currentColor;
        outline-offset: 0.2em;