Browse Source

implement sections h1

main
ghost 11 months ago
parent
commit
942fe6eac2
  1. 56
      src/server.php

56
src/server.php

@ -147,15 +147,55 @@ $server->setHandler(
// Init reader // Init reader
$reader = new \Yggverse\Gemini\Dokuwiki\Reader(); $reader = new \Yggverse\Gemini\Dokuwiki\Reader();
// Build home page // Init home page content
$lines = [ $lines = [
PHP_EOL PHP_EOL
]; ];
// Build header
$h1 = [];
$segments = [];
foreach ((array) explode(':', $_uri) as $segment)
{
$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
)
)
);
}
// Reset title of undefined segment
else
{
$h1[] = null;
}
}
// Append header // Append header
$lines[] = sprintf( $lines[] = sprintf(
'# %s', '# %s',
$config->string->welcome empty($h1[0]) ? $config->string->welcome : implode(' - ', $h1)
); );
// Get children sections // Get children sections
@ -165,8 +205,8 @@ $server->setHandler(
{ {
if (str_starts_with($path, $directory) && $path != $directory) if (str_starts_with($path, $directory) && $path != $directory)
{ {
// Init H1 // Init link name
$h1 = null; $alt = null;
// Init this directory URI // Init this directory URI
$uri = $filesystem->getDirectoryUriByPath( $uri = $filesystem->getDirectoryUriByPath(
@ -189,7 +229,7 @@ $server->setHandler(
// Find section index if exists // Find section index if exists
if ($file = $filesystem->getPagePathByUri(implode(':', $segments) . ':' . $segment)) if ($file = $filesystem->getPagePathByUri(implode(':', $segments) . ':' . $segment))
{ {
$h1 = $reader->getH1( $alt = $reader->getH1(
$reader->toGemini( $reader->toGemini(
file_get_contents( file_get_contents(
$file $file
@ -201,7 +241,7 @@ $server->setHandler(
// Find section page if exists // Find section page if exists
else if ($file = $filesystem->getPagePathByUri(implode(':', $segments))) else if ($file = $filesystem->getPagePathByUri(implode(':', $segments)))
{ {
$h1 = $reader->getH1( $alt = $reader->getH1(
$reader->toGemini( $reader->toGemini(
file_get_contents( file_get_contents(
$file $file
@ -213,7 +253,7 @@ $server->setHandler(
// Reset title of undefined segment // Reset title of undefined segment
else else
{ {
$h1 = null; $alt = null;
} }
} }
@ -221,7 +261,7 @@ $server->setHandler(
$sections[] = sprintf( $sections[] = sprintf(
'=> /%s %s', '=> /%s %s',
$uri, $uri,
$h1 $alt
); );
} }
} }

Loading…
Cancel
Save