update
This commit is contained in:
@@ -143,11 +143,7 @@ final class Router
|
||||
|
||||
public static function shortcodeDocsIndex(): string
|
||||
{
|
||||
return (new TemplateLoader())->capture('documentation-index', [
|
||||
'products' => self::productsWithVersions(),
|
||||
'base_slug' => trim((string) Plugin::settings()['docs_base_slug'], '/'),
|
||||
'url_builder' => UrlBuilder::class,
|
||||
]);
|
||||
return (new self())->captureRoute('index');
|
||||
}
|
||||
|
||||
public static function shortcodeDocsApp(array $atts = []): string
|
||||
@@ -188,12 +184,12 @@ final class Router
|
||||
$atts = shortcode_atts(['product' => ''], $atts, 'kb_product_index');
|
||||
$router = new self();
|
||||
|
||||
return $router->captureProduct((string) $atts['product']);
|
||||
return $router->captureRoute('product', sanitize_title((string) $atts['product']));
|
||||
}
|
||||
|
||||
private function renderIndex(): void
|
||||
{
|
||||
echo $this->captureIndex();
|
||||
echo $this->captureRoute('index');
|
||||
}
|
||||
|
||||
private function captureIndex(): string
|
||||
@@ -207,7 +203,7 @@ final class Router
|
||||
|
||||
private function renderProduct(string $productSlug): void
|
||||
{
|
||||
echo $this->captureProduct($productSlug);
|
||||
echo $this->captureRoute('product', $productSlug);
|
||||
}
|
||||
|
||||
private function captureProduct(string $productSlug): string
|
||||
@@ -229,7 +225,7 @@ final class Router
|
||||
|
||||
private function renderVersion(string $productSlug, string $versionSlug): void
|
||||
{
|
||||
echo $this->captureVersion($productSlug, $versionSlug);
|
||||
echo $this->captureRoute('version', $productSlug, $versionSlug);
|
||||
}
|
||||
|
||||
private function captureVersion(string $productSlug, string $versionSlug): string
|
||||
@@ -257,7 +253,7 @@ final class Router
|
||||
|
||||
private function renderPage(string $productSlug, string $versionSlug, string $pageSlug): void
|
||||
{
|
||||
echo $this->capturePage($productSlug, $versionSlug, $pageSlug);
|
||||
echo $this->captureRoute('page', $productSlug, $versionSlug, $pageSlug);
|
||||
}
|
||||
|
||||
private function capturePage(string $productSlug, string $versionSlug, string $pageSlug): string
|
||||
@@ -301,13 +297,35 @@ final class Router
|
||||
|
||||
private function captureRoute(string $route, string $productSlug = '', string $versionSlug = '', string $pageSlug = ''): string
|
||||
{
|
||||
return match ($route) {
|
||||
$content = match ($route) {
|
||||
'index' => $this->captureIndex(),
|
||||
'product' => $productSlug ? $this->captureProduct($productSlug) : $this->captureIndex(),
|
||||
'version' => ($productSlug && $versionSlug) ? $this->captureVersion($productSlug, $versionSlug) : $this->captureIndex(),
|
||||
'page' => ($productSlug && $versionSlug) ? $this->capturePage($productSlug, $versionSlug, $pageSlug) : $this->captureIndex(),
|
||||
default => $this->captureIndex(),
|
||||
};
|
||||
|
||||
return $this->captureShell($content, $productSlug, $versionSlug, $pageSlug);
|
||||
}
|
||||
|
||||
private function captureShell(string $content, string $productSlug = '', string $versionSlug = '', string $pageSlug = ''): string
|
||||
{
|
||||
$activePages = [];
|
||||
|
||||
if ($productSlug && $versionSlug) {
|
||||
$activePages = $this->pagesForVersion($productSlug, $versionSlug);
|
||||
}
|
||||
|
||||
return (new TemplateLoader())->capture('docs-app', [
|
||||
'content' => $content,
|
||||
'products' => self::productsWithVersions(),
|
||||
'active_product_slug' => $productSlug,
|
||||
'active_version_slug' => $versionSlug,
|
||||
'active_page_slug' => $pageSlug,
|
||||
'active_pages' => $activePages,
|
||||
'base_slug' => trim((string) Plugin::settings()['docs_base_slug'], '/'),
|
||||
'url_builder' => UrlBuilder::class,
|
||||
]);
|
||||
}
|
||||
|
||||
private function render404(): void
|
||||
|
||||
Reference in New Issue
Block a user