Skip to content

Commit

Permalink
Merge pull request #654 from art-institute-of-chicago/feature/better-…
Browse files Browse the repository at this point in the history
…page-titles

Add filter selections to page titles [WEB-2998]
  • Loading branch information
nikhiltri authored Jan 10, 2025
2 parents fcc7bdc + dcd1b06 commit 6c9b324
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 7 deletions.
15 changes: 15 additions & 0 deletions app/Http/Controllers/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ public function index()
);
}

if (request('category') || request('type')) {
$cat = $page->articlesCategories->first(function ($value) {
return $value->id == request('category');
});
$titles = array_filter([
'Articles',
$cat?->name,
Str::title(request('type')),
request('page') ? 'Page ' . request('page') : null,
]);
$this->seo->setTitle(implode(', ', $titles));
} else {
$this->seo->setTitle('Articles');
}

return view('site.articles', [
'primaryNavCurrent' => 'collection',
'page' => $page,
Expand Down
7 changes: 5 additions & 2 deletions app/Http/Controllers/AuthorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public function index(Request $request)
$items = $this->repository->published()->ordered()->paginate();

$title = 'Authors';
$titles = array_filter([
$title,
request('page') ? 'Page ' . request('page') : null,
]);
$this->seo->setTitle(implode(', ', $titles));

$subNav = [
['label' => $title, 'href' => route('authors.index'), 'active' => true]
Expand All @@ -30,8 +35,6 @@ public function index(Request $request)
['label' => 'Publications', 'href' => route('articles_publications'), 'links' => $subNav]
];

$this->seo->setTitle($title);

$view_data = [
'title' => $title,
'subNav' => $subNav,
Expand Down
11 changes: 9 additions & 2 deletions app/Http/Controllers/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,16 @@ public function index()
$activeFilters = $this->collection()->activeFilters();

if ($activeFilters->count()) {
$this->seo->setTitle(implode(', ', $activeFilters->pluck('label')->all()));
$titles = $activeFilters->pluck('label')->all();
$titles[] = request('page') ? 'Page ' . request('page') : null;
$titles = array_filter($titles);
$this->seo->setTitle(implode(', ', $titles));
} else {
$this->seo->setTitle('Discover Art & Artists');
$titles = array_filter([
'Discover Art & Artists',
request('page') ? 'Page ' . request('page') : null,
]);
$this->seo->setTitle(implode(', ', $titles));
}

if ($collection->count()) {
Expand Down
8 changes: 7 additions & 1 deletion app/Http/Controllers/EducatorResourcesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ public function index(Request $request)
$items = $this->collection()->orderByDate()->paginate();

$title = 'Educator Resources';
$cat = ResourceCategory::where('id', request('category'))->first();
$titles = array_filter([
$title,
$cat?->name,
request('page') ? 'Page ' . request('page') : null,
]);

$this->seo->setTitle($title);
$this->seo->setTitle(implode(', ', $titles));

$subNav = [
['label' => $title, 'href' => route('collection.resources.educator-resources'), 'active' => true]
Expand Down
24 changes: 23 additions & 1 deletion app/Http/Controllers/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\EventProgram;
use App\Repositories\EventRepository;
use Carbon\Carbon;
use Illuminate\Support\Str;
use View;

class EventsController extends FrontController
Expand Down Expand Up @@ -39,9 +40,30 @@ public function index()
$ongoing = null;
$eventsByDay = $this->repository->groupByDate($collection);

$programName = null;
if (request('program')) {
$subtitle = 'These are events related to ' . EventProgram::find(request('program'))->name . '.';
$programName = EventProgram::find(request('program'))->name;
$subtitle = 'These are events related to ' . $programName . '.';
}

$type = collect(Event::$eventTypes)->first(function ($value, $key) {
return $key == request('type');
});
$audience = collect(Event::$eventAudiences)->first(function ($value, $key) {
return $key == request('audience');
});
$titles = array_filter([
'Events',
request('start') ? Carbon::parse(request('start'))->toFormattedDateString() : null,
request('end') ? Carbon::parse(request('end'))->toFormattedDateString() : null,
Str::title(request('time')),
$type,
$audience,
$programName,
request('page') ? 'Page ' . request('page') : null,
]);

$this->seo->setTitle(implode(', ', $titles));
} else {
// Divide the collection by normal events and ongoing ones
$ongoing = $collection->filter(function ($item) {
Expand Down
8 changes: 8 additions & 0 deletions app/Http/Controllers/ExhibitionHistoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public function index(Request $request, ExhibitionHistoryService $service)
$extraResults = $this->apiRepository->searchApi(request('q'), self::PER_PAGE);
}

$titles = array_filter([
'Exhibition History',
request('year'),
request('page') ? 'Page ' . request('page') : null,
]);

$this->seo->setTitle(implode(', ', $titles));

$viewData = [
'page' => $page,
'years' => $years,
Expand Down
8 changes: 7 additions & 1 deletion app/Http/Controllers/PrintedPublicationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ public function index(Request $request)
$items = $this->collection()->ordered()->paginate();

$title = 'Print Publications';
$cat = CatalogCategory::where('id', request('category'))->first();

$this->seo->setTitle($title);
$titles = array_filter([
$title,
$cat?->name,
request('page') ? 'Page ' . request('page') : null,
]);
$this->seo->setTitle(implode(', ', $titles));

$navElements = NavHelpers::get_nav_for_publications($title);

Expand Down

0 comments on commit 6c9b324

Please sign in to comment.