From aa27bcc9b7fee02363d28abf0c49d6e89a71b6f9 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 6 May 2024 20:03:46 +0300 Subject: [PATCH] urlencode fs navigation links --- src/Controller/Nex.php | 39 +++++++++++++++++++++++++++------------ src/Model/Filesystem.php | 10 ++++++++-- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/Controller/Nex.php b/src/Controller/Nex.php index 2175b07..ba838b3 100644 --- a/src/Controller/Nex.php +++ b/src/Controller/Nex.php @@ -125,21 +125,36 @@ class Nex implements MessageComponentInterface foreach ($list as $item) { // Build gemini text link - $link = ['=>']; - - if ($item['name']) + if ($item['link']) { - $link[] = $item['file'] ? $item['name'] - : $item['name'] . '/'; - } + $link = + [ + '=>', // gemtext format + $item['file'] ? $item['link'] + : $item['link'] . '/' + ]; - if ($item['time'] && $this->_environment->get('time')) - { - $link[] = date('Y-m-d', $item['time']); - } + // Append modification time on enabled + if ($item['time'] && $this->_environment->get('time')) + { + $link[] = date( + 'Y-m-d', // gemfeed format + $item['time'] + ); + } + + // Append alt name on link urlencoded + if ($item['name'] != $item['link']) + { + $link[] = $item['name']; + } - // Append link to the new line - $line[] = implode(' ', $link); + // Append link to the new line + $line[] = implode( + ' ', + $link + ); + } } // Merge lines to response diff --git a/src/Model/Filesystem.php b/src/Model/Filesystem.php index e6b9136..b225be7 100644 --- a/src/Model/Filesystem.php +++ b/src/Model/Filesystem.php @@ -135,8 +135,11 @@ class Filesystem $directories[] = [ 'file' => false, - 'name' => $name, 'path' => $path, + 'name' => $name, + 'link' => urlencode( + $name + ), 'time' => filemtime( $path ) @@ -149,8 +152,11 @@ class Filesystem $files[] = [ 'file' => true, - 'name' => $name, 'path' => $path, + 'name' => $name, + 'link' => urlencode( + $name + ), 'time' => filemtime( $path )