Drop .0 or .0.0 from version for display

This commit is contained in:
Daniel J. Summers 2024-05-30 19:16:42 -04:00
parent 1b65694e05
commit cfa56ec44f
3 changed files with 19 additions and 7 deletions

View File

@ -3,6 +3,22 @@
/** The current Feed Reader Central version */ /** The current Feed Reader Central version */
const FRC_VERSION = '1.0.0-alpha7'; const FRC_VERSION = '1.0.0-alpha7';
/**
* Drop .0 or .0.0 from the end of the version to format it for display
*
* @return string The version of the application for user display
*/
function display_version(): string {
[$major, $minor, $rev] = explode('.', FRC_VERSION);
$minor = $minor == '0' ? '' : ".$minor";
$rev = match (true) {
$rev == '0' => '',
str_starts_with($rev, '0-') => substr($rev, 1),
default => ".$rev"
};
return "v$major$minor$rev";
}
spl_autoload_register(function ($class) { spl_autoload_register(function ($class) {
$file = implode(DIRECTORY_SEPARATOR, [__DIR__, 'lib', "$class.php"]); $file = implode(DIRECTORY_SEPARATOR, [__DIR__, 'lib', "$class.php"]);
if (file_exists($file)) { if (file_exists($file)) {

View File

@ -22,7 +22,7 @@ function printfn(string $format, mixed ...$values): void {
* @param string $title The title to display on the command line * @param string $title The title to display on the command line
*/ */
function cli_title(string $title): void { function cli_title(string $title): void {
$appTitle = 'Feed Reader Central ~ v' . FRC_VERSION; $appTitle = 'Feed Reader Central ~ ' . display_version();
$dashes = ' +' . str_repeat('-', strlen($title) + 2) . '+' . str_repeat('-', strlen($appTitle) + 2) . '+'; $dashes = ' +' . str_repeat('-', strlen($title) + 2) . '+' . str_repeat('-', strlen($appTitle) + 2) . '+';
printfn($dashes); printfn($dashes);
printfn(' | %s | %s |', $title, $appTitle); printfn(' | %s | %s |', $title, $appTitle);

View File

@ -50,13 +50,9 @@ function nav_link(string $link, bool $isFirst = false) {
* Render the title bar for the page * Render the title bar for the page
*/ */
function title_bar(): void { function title_bar(): void {
$version = match (true) { $version = display_version();; ?>
str_ends_with(FRC_VERSION, '.0.0') => substr(FRC_VERSION, 0, strlen(FRC_VERSION) - 4),
str_ends_with(FRC_VERSION, '.0') => substr(FRC_VERSION, 0, strlen(FRC_VERSION) - 2),
default => FRC_VERSION
}; ?>
<header hx-target=#main hx-push-url=true> <header hx-target=#main hx-push-url=true>
<div><a href=/ class=title>Feed Reader Central</a><span class=version>v<?=$version?></span></div> <div><a href=/ class=title>Feed Reader Central</a><span class=version><?=$version?></span></div>
<nav><?php <nav><?php
if (key_exists(Key::USER_ID, $_SESSION)) { if (key_exists(Key::USER_ID, $_SESSION)) {
$db = Data::getConnection(); $db = Data::getConnection();