From: Ben Sherratt Date: Fri, 3 Jul 2026 17:51:30 +0000 (+0100) Subject: Basic page support X-Git-Url: https://git.bts.cx/cx.git/commitdiff_plain/4083179b42caa6de33cd4cec006d7ffe46e48a60?ds=inline Basic page support --- diff --git a/cx/cx.php b/cx/cx.php index 2c71761..d54b3d4 100644 --- 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); diff --git a/cx/lib/posts.php b/cx/lib/posts.php index b187c51..6437433 100644 --- a/cx/lib/posts.php +++ b/cx/lib/posts.php @@ -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) { diff --git a/cx/templates/admin/post.php b/cx/templates/admin/post.php index aa7f870..6ce9e06 100644 --- a/cx/templates/admin/post.php +++ b/cx/templates/admin/post.php @@ -5,6 +5,7 @@

title:

slug:

date: ">

+

page: >

draft: >

diff --git a/cx/templates/public/base.php b/cx/templates/public/base.php index 8629d34..10c5cd1 100644 --- a/cx/templates/public/base.php +++ b/cx/templates/public/base.php @@ -46,17 +46,17 @@

Find me @btsherratt or on itch.io

- + */ ?> + diff --git a/public/design/css/style.css b/public/design/css/style.css index 27e627b..a5c06ec 100644 --- a/public/design/css/style.css +++ b/public/design/css/style.css @@ -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;