complete sections list

This commit is contained in:
ghost 2024-02-02 17:18:25 +02:00
parent 708b539964
commit 6ec414838a

View File

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