Files
my-projects-website/app/application/breadcrumbs/site.php
T
kor-elf 136451dc5a Add breadcrumbs to site documentation views
- Integrate breadcrumb rendering across documentation views (`index`, `category`, `view`, and `no-default-version`).
- Add support for dynamic JSON-LD breadcrumb generation.
2026-07-25 23:10:37 +05:00

61 lines
3.2 KiB
PHP

<?php
use App\Models\DocumentationCategory;
use App\Models\DocumentationVersion;
use App\Models\Documentation;
use App\Services\WebsiteTranslations;
use App\Enums\Site\ProjectSection;
use App\Models\Project;
use Diglactic\Breadcrumbs\Breadcrumbs;
use Illuminate\Support\Collection;
Breadcrumbs::for('home', function ($trail, Project $project, WebsiteTranslations $websiteTranslations) {
$trail->push($websiteTranslations->translate('Home'), ProjectSection::Home->url($project, $websiteTranslations->getLanguage()));
});
Breadcrumbs::for('feedbacks.index', function ($trail, Project $project, WebsiteTranslations $websiteTranslations) {
$trail->parent('home', $project, $websiteTranslations);
$trail->push($websiteTranslations->translate('site.Feedback'), ProjectSection::Feedback->url($project, $websiteTranslations->getLanguage()));
});
// Documentation
Breadcrumbs::for('documentation.no-default-version', function ($trail, Project $project, WebsiteTranslations $websiteTranslations) {
$trail->parent('home', $project, $websiteTranslations);
$trail->push($websiteTranslations->translate('site.Documentation'), ProjectSection::Documentation->url($project, $websiteTranslations->getLanguage()));
});
Breadcrumbs::for('documentation.index', function ($trail, Project $project, WebsiteTranslations $websiteTranslations, DocumentationVersion $version) {
$trail->parent('home', $project, $websiteTranslations);
$trail->push($websiteTranslations->translate('site.Documentation'), ProjectSection::DocumentationVersion->url($project, $websiteTranslations->getLanguage(), ['version' => $version->slug]));
});
Breadcrumbs::for('documentation.category-path', function ($trail, Project $project, WebsiteTranslations $websiteTranslations, DocumentationVersion $version, Collection $categoryPath) {
$trail->parent('documentation.index', $project, $websiteTranslations, $version);
foreach ($categoryPath as $pathItem) {
$trail->push(
$pathItem->content->title,
ProjectSection::DocumentationCategory->url($project, $websiteTranslations->getLanguage(), ['version' => $version->slug, 'slug' => $pathItem->slug])
);
}
});
Breadcrumbs::for('documentation.category', function ($trail, Project $project, WebsiteTranslations $websiteTranslations, DocumentationVersion $version, DocumentationCategory $category, ?Collection $categoryPath) {
$trail->parent('documentation.category-path', $project, $websiteTranslations, $version, $categoryPath ?? collect());
$trail->push(
$category->content->title,
ProjectSection::DocumentationCategory->url($project, $websiteTranslations->getLanguage(), ['version' => $version->slug, 'slug' => $category->slug])
);
});
Breadcrumbs::for('documentation.view', function ($trail, Project $project, WebsiteTranslations $websiteTranslations, DocumentationVersion $version, Documentation $documentation, ?Collection $categoryPath) {
$trail->parent('documentation.category-path', $project, $websiteTranslations, $version, $categoryPath ?? collect());
$trail->push(
$documentation->content->title,
ProjectSection::Documentation->url($project, $websiteTranslations->getLanguage(), ['version' => $version->slug, 'slug' => $documentation->slug])
);
});
// End Documentation