From a1b052b7cc060604dcc1b2e514dbd050f427679c Mon Sep 17 00:00:00 2001 From: ghost Date: Fri, 26 Jan 2024 09:38:31 +0200 Subject: [PATCH] implement link builder --- src/controller/room.php | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/controller/room.php b/src/controller/room.php index db2a8e5..18cb0d9 100644 --- a/src/controller/room.php +++ b/src/controller/room.php @@ -94,17 +94,9 @@ class Room [ $namespace['name'], $namespace['total'], - ( - $this->_config->gemini->server->port == 1965 ? + $this->_url( sprintf( - 'gemini://%s/room/%s', - $this->_config->gemini->server->host, - $namespace['namespace'] - ) : - sprintf( - 'gemini://%s:%d/%s', - $this->_config->gemini->server->host, - $this->_config->gemini->server->port, + '/room/%s', $namespace['namespace'] ) ) @@ -171,6 +163,7 @@ class Room return str_replace( [ '{logo}', + '{home}', '{subject}', '{posts}' ], @@ -178,6 +171,7 @@ class Room file_get_contents( __DIR__ . '/../../logo.ascii' ), + $this->_url(), $subject ? $subject : $namespace, implode( PHP_EOL, @@ -413,4 +407,22 @@ class Room ) ); } + + private function _url(?string $path = null) + { + return ( + $this->_config->gemini->server->port == 1965 ? + sprintf( + 'gemini://%s%s', + $this->_config->gemini->server->host, + $path + ) : + sprintf( + 'gemini://%s:%d%s', + $this->_config->gemini->server->host, + $this->_config->gemini->server->port, + $path + ) + ); + } } \ No newline at end of file