Browse Source

complete sections list

main
ghost 11 months ago
parent
commit
6ec414838a
  1. 37
      src/server.php

37
src/server.php

@ -165,25 +165,43 @@ $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))
{
$h1 = $reader->getH1(
$reader->toGemini(
file_get_contents(
$file
)
)
);
}
// Find section name if exists in index file // Find section page if exists
if ($file = $filesystem->getPagePathByUri($uri . ':' . end($segments))) else if ($file = $filesystem->getPagePathByUri(implode(':', $segments)))
{ {
$alias = $reader->getH1( $h1 = $reader->getH1(
$reader->toGemini( $reader->toGemini(
file_get_contents( file_get_contents(
$file $file
@ -191,6 +209,7 @@ $server->setHandler(
) )
); );
} }
}
// Register section link // Register section link
$sections[] = sprintf( $sections[] = sprintf(
@ -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

Loading…
Cancel
Save