From b5f2fb62c9f92c078b85e4a8fde3a556b90c5710 Mon Sep 17 00:00:00 2001 From: "DIR\\gizem.bicer" Date: Tue, 3 Feb 2026 22:37:31 +0100 Subject: [PATCH] FIX change in the way of working NavButton Placeholders. Now they navigate through all the contents regardless the level --- .../AbstractMarkdownPlaceholderResolver.php | 11 ++ .../placeholders/NavButtonsPlaceholder.md | 7 -- .../Placeholders/ImageNumberResolver.php | 13 +-- .../Placeholders/ImageReferenceResolver.php | 12 +-- .../Placeholders/NavButtonResolver.php | 100 +++++++----------- 5 files changed, 50 insertions(+), 93 deletions(-) diff --git a/CommonLogic/TemplateRenderer/AbstractMarkdownPlaceholderResolver.php b/CommonLogic/TemplateRenderer/AbstractMarkdownPlaceholderResolver.php index 895a88d50..8674e055e 100644 --- a/CommonLogic/TemplateRenderer/AbstractMarkdownPlaceholderResolver.php +++ b/CommonLogic/TemplateRenderer/AbstractMarkdownPlaceholderResolver.php @@ -9,6 +9,17 @@ abstract class AbstractMarkdownPlaceholderResolver extends AbstractPlaceholderResolver { + protected function getDocsPath(string $currentPagePath) : string + { + $rootDir = FilePathDataType::findFolderPath($currentPagePath); + $normalizedFull = FilePathDataType::normalize($rootDir); + $parts = explode("/Docs/", string: $normalizedFull); + if(count($parts) == 1) { + return $normalizedFull; + } + return $parts[0]. "/Docs/"; + } + protected function scanMarkdownDirectory(string $directory, int $maxDepth = PHP_INT_MAX, int $currentDepth = 0, $relativePath = ''): array { if ($currentDepth > $maxDepth) { return []; diff --git a/Docs/documentation/placeholders/NavButtonsPlaceholder.md b/Docs/documentation/placeholders/NavButtonsPlaceholder.md index 02746e26b..1757a24a2 100644 --- a/Docs/documentation/placeholders/NavButtonsPlaceholder.md +++ b/Docs/documentation/placeholders/NavButtonsPlaceholder.md @@ -7,13 +7,6 @@ The order is determined by both **numerical** and **alphabetical** sorting of th - Sorting is done first numerically (e.g., `1. Intro`, `1.1 Usage`), then alphabetically (e.g., `GettingStarted`, `Overview`). - This placeholder does **not** support any options. - -### How It Works - -- If the current file represents a **first-level heading** (e.g., a top-level topic or `1. Introduction`), the navigation buttons will link to other **first-level heading** (`2. How To Use`, `3. Summary`) files. -- If the current file represents a **second-level heading** (i.e., a sub-topic under a parent folder e.g., `1.1 Required Hardware`), the buttons will navigate only among other **second-level heading** (`1.2 Required Software`, `1.3 Required Apps`) files within the same parent. - - ### Example Usage ```html diff --git a/Facades/DocsFacade/Placeholders/ImageNumberResolver.php b/Facades/DocsFacade/Placeholders/ImageNumberResolver.php index dd685bfe0..ba853e020 100644 --- a/Facades/DocsFacade/Placeholders/ImageNumberResolver.php +++ b/Facades/DocsFacade/Placeholders/ImageNumberResolver.php @@ -22,7 +22,7 @@ public function __construct(string $pagePathAbsolute, string $prefix = 'ImageCap public function resolve(array $placeholders) : array { $vals = []; - $rootDirectory = $this->getDocsPath(); + $rootDirectory = $this->getDocsPath($this->pagePath); $markdownStructure = $this->getFlattenMarkdownFiles($rootDirectory); $names = array_map(fn($ph) => $ph['name'], $placeholders); @@ -66,15 +66,4 @@ function countImagesAndUpdate($files, $targetFile, $order) { $currentAbbildungNumber += count($matches[0]); } } - - protected function getDocsPath() : string - { - $rootDir = FilePathDataType::findFolderPath($this->pagePath); - $normalizedFull = FilePathDataType::normalize($rootDir); - $parts = explode("/Docs/", string: $normalizedFull); - if(count($parts) == 1) { - return $normalizedFull; - } - return $parts[0]. "/Docs/"; - } } \ No newline at end of file diff --git a/Facades/DocsFacade/Placeholders/ImageReferenceResolver.php b/Facades/DocsFacade/Placeholders/ImageReferenceResolver.php index 54abc64f4..488b748c8 100644 --- a/Facades/DocsFacade/Placeholders/ImageReferenceResolver.php +++ b/Facades/DocsFacade/Placeholders/ImageReferenceResolver.php @@ -24,7 +24,7 @@ public function __construct(string $pagePathAbsolute, string $prefix = 'ImageRef public function resolve(array $placeholders) : array { $vals = []; - $rootDirectory = $this->getDocsPath(); + $rootDirectory = $this->getDocsPath($this->pagePath); $markdownStructure = $this->getFlattenMarkdownFiles($rootDirectory); $names = array_map(fn($ph) => $ph['name'], $placeholders); @@ -77,14 +77,4 @@ protected function searchTheFile(string $filePath, string $imageId) } } - protected function getDocsPath() : string - { - $rootDir = FilePathDataType::findFolderPath($this->pagePath); - $normalizedFull = FilePathDataType::normalize($rootDir); - $parts = explode("/Docs/", string: $normalizedFull); - if(count($parts) == 1) { - return $normalizedFull; - } - return $parts[0]. "/Docs/"; - } } \ No newline at end of file diff --git a/Facades/DocsFacade/Placeholders/NavButtonResolver.php b/Facades/DocsFacade/Placeholders/NavButtonResolver.php index d1222fed6..ae6686d69 100644 --- a/Facades/DocsFacade/Placeholders/NavButtonResolver.php +++ b/Facades/DocsFacade/Placeholders/NavButtonResolver.php @@ -24,86 +24,59 @@ public function __construct(string $pagePathAbsolute, string $prefix = 'NavButto public function resolve(array $placeholders) : array { $vals = []; - $rootDirectory = FilePathDataType::findFolderPath($this->pagePath); + $rootDirectory = $this->getDocsPath($this->pagePath); $names = array_map(fn($ph) => $ph['name'], $placeholders); $filteredNames = $this->filterPlaceholders($names); + $fileList = $this->getFlattenMarkdownFiles($rootDirectory); foreach ($placeholders as $i => $placeholder) { if (in_array($placeholder['name'], $filteredNames)) { - $fileList = $this->getSiblings($rootDirectory); - $val = $this->createButtons($fileList); + $val = $this->createButtons($fileList, $this->pagePath); $vals[$i] = $val; } } return $vals; } - - protected function getSiblings(string $directory): array { - if (strtolower(basename($this->pagePath)) === 'index.md') { - return $this->getIndexSiblings($directory); - } else { - return $this->getRegularSiblings($directory); - } - } - - protected function getIndexSiblings(string $directory): array { - $parent = dirname($directory); - $subfolders = glob($parent . '/*', GLOB_ONLYDIR); - - $siblings = []; - foreach ($subfolders as $folder) { - $indexPath = $folder . DIRECTORY_SEPARATOR . 'index.md'; - if (file_exists($indexPath)) { - $siblings[] = [ - 'title' => MarkdownDataType::findHeadOfFile($indexPath), - 'link' => FilePathDataType::normalize($indexPath) - ]; - } - } - - $sorter = new RowDataArraySorter(); - $sorter->addCriteria('title', SORT_ASC); - return $sorter->sort($siblings); - } - - protected function getRegularSiblings(string $directory): array { - $siblings = []; - $files = glob($directory . '/*.md'); - - foreach ($files as $filePath) { - if (strtolower(basename($filePath)) === 'index.md') { - continue; - } - - $siblings[] = [ - 'title' => MarkdownDataType::findHeadOfFile($filePath), - 'link' => FilePathDataType::normalize($filePath) - ]; - } - $sorter = new RowDataArraySorter(); - $sorter->addCriteria('title', SORT_ASC); - return $sorter->sort($siblings); - } - protected function createButtons(array $files): string + protected function createButtons(array $flatList, string $currentPath): string { - $currentIndex = array_search(FilePathDataType::normalize($this->pagePath), array_column($files, 'link')); - + $normalizedCurrent = FilePathDataType::normalize($currentPath); + + $normalizedList = array_map( + fn($p) => FilePathDataType::normalize($p), + $flatList + ); + + $currentIndex = array_search($normalizedCurrent, $normalizedList); + if ($currentIndex === false) { - ""; + return ''; } - $prev = $currentIndex > 0 ? $files[$currentIndex - 1] : null; - $next = $currentIndex < count($files) - 1 ? $files[$currentIndex + 1] : null; - + $buttons = []; - if ($prev) $buttons[] = $this->mdButon('Zurück',$this->getRelativePath($this->pagePath, $prev['link'])); - if ($next) $buttons[] = $this->mdButon('Weiter',$this->getRelativePath($this->pagePath, $next['link'])); - $buttonBlock = implode(' ', $buttons) . "\n"; - return $buttonBlock; + if ($currentIndex > 0) { + $prevPath = $flatList[$currentIndex - 1]; + $buttons[] = $this->mdButon( + 'Zurück', + $this->getRelativePath($this->pagePath, $prevPath) + ); + } + + if ($currentIndex < count($flatList) - 1) { + $nextPath = $flatList[$currentIndex + 1]; + $buttons[] = $this->mdButon( + 'Weiter', + $this->getRelativePath($this->pagePath, $nextPath) + ); + } + + return implode(' ', $buttons); } - function getRelativePath(string $from, string $to): string { + + function getRelativePath(string $from, string $to): string + { $from = is_dir($from) ? rtrim($from, '/') . '/' : dirname($from) . '/'; $from = FilePathDataType::normalize(realpath($from)); $to = FilePathDataType::normalize(realpath($to)); @@ -120,7 +93,8 @@ function getRelativePath(string $from, string $to): string { return str_repeat('../', count($fromParts)) . implode('/', $toParts); } - function mdButon(string $buttonText, string $path) { + function mdButon(string $buttonText, string $path): string + { return "[
 " . $buttonText . " 
]($path)"; }