diff --git a/legacy_hook/src/DocumentationLinker.php b/legacy_hook/src/DocumentationLinker.php index 3b368e81..0c1c2b22 100644 --- a/legacy_hook/src/DocumentationLinker.php +++ b/legacy_hook/src/DocumentationLinker.php @@ -102,6 +102,8 @@ */ final readonly class DocumentationLinker { + private const MAIN_IDENTIFIER = 'main'; + private FilesystemAdapter $cache; private int $cacheTime; @@ -133,10 +135,16 @@ public function redirectToLink(): Response $matches) ) { [, $repository, $index] = $matches; - $version = str_replace('@', '', $matches[3] ?? '') ?: 'main'; + $version = str_replace('@', '', $matches[3] ?? '') ?: self::MAIN_IDENTIFIER; $entrypoint = $this->resolveEntryPoint($repository, $version); $objectsContents = $this->getObjectsFile($entrypoint); + if ($objectsContents === '' && $version !== self::MAIN_IDENTIFIER) { + // soft-fail to resolve a maybe not-yet released version to main. + $entrypoint = $this->resolveEntryPoint($repository, self::MAIN_IDENTIFIER); + $objectsContents = $this->getObjectsFile($entrypoint); + } + if ($objectsContents === '') { return new ResponseDescriber(404, [], 'Invalid shortcode, no objects.inv.json found.'); } @@ -194,7 +202,7 @@ private function parseInventoryForIndex(string $index, array $json): string // std:confval + pagelink.html#some-entry // to: // pagelink.html#confval-some-entry - $link = str_replace('#', '#-' . $docNodeTypeParts[1], $indexMetaData[2]); + $link = str_replace('#', '#' . $docNodeTypeParts[1] . '-', $indexMetaData[2]); } } }