diff --git a/src/server.php b/src/server.php index ce7378b..24c1cbc 100644 --- a/src/server.php +++ b/src/server.php @@ -165,31 +165,50 @@ $server->setHandler( { if (str_starts_with($path, $directory) && $path != $directory) { + // Init H1 + $h1 = null; + // Init this directory URI $uri = $filesystem->getDirectoryUriByPath( $path ); - // Parse URI segments - $segments = []; - foreach ((array) explode(':', $uri) as $segment) + // Skip sections deeper this level + if (substr_count($uri, ':') > ($_uri ? substr_count($_uri, ':') + 1 : 0)) { - $segments[] = $segment; + continue; } - // Set default section alias - $alias = empty($_uri) ? $config->string->main : ''; + // Get section names + $segments = []; - // Find section name if exists in index file - if ($file = $filesystem->getPagePathByUri($uri . ':' . end($segments))) + foreach ((array) explode(':', $uri) as $segment) { - $alias = $reader->getH1( - $reader->toGemini( - file_get_contents( - $file + $segments[] = $segment; + + // Find section index if exists + if ($file = $filesystem->getPagePathByUri(implode(':', $segments) . ':' . $segment)) + { + $h1 = $reader->getH1( + $reader->toGemini( + file_get_contents( + $file + ) ) - ) - ); + ); + } + + // Find section page if exists + else if ($file = $filesystem->getPagePathByUri(implode(':', $segments))) + { + $h1 = $reader->getH1( + $reader->toGemini( + file_get_contents( + $file + ) + ) + ); + } } // Register section link @@ -198,12 +217,12 @@ $server->setHandler( $config->gemini->server->host, $config->gemini->server->port == 1965 ? null : ':' . $config->gemini->server->port, $uri, - $alias + $h1 ); } } - // Append sections list if exist + // Append sections if ($sections) { // Keep unique