11 files changed
+204
-41
No files matched your search
@@ -9,6 +9,8 @@ use App\Models\GarmentTemplate;
|
||||
use App\Models\LocalizedContent;
|
||||
use App\Support\GarmentPreview;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use XMLWriter;
|
||||
|
||||
@@ -29,15 +31,20 @@ class StudioController extends Controller
|
||||
return $this->page('catalog', 'catalog', compact('collections'));
|
||||
}
|
||||
|
||||
public function collection(string $slug)
|
||||
public function collection(string $slug): View
|
||||
{
|
||||
$collection = $this->find(Collection::published(), $slug);
|
||||
$designs = $collection->designs()->visible()->get();
|
||||
|
||||
return $this->page('collection', 'collection', compact('collection', 'designs'), $collection);
|
||||
return $this->page('collection', 'collection', [
|
||||
'collection' => $collection,
|
||||
'designs' => $designs,
|
||||
'shareImage' => $collection->coverUrl(),
|
||||
'shareImageAlt' => $collection->text('name'),
|
||||
], $collection);
|
||||
}
|
||||
|
||||
public function design(string $slug, GarmentPreview $preview)
|
||||
public function design(string $slug, GarmentPreview $preview): View
|
||||
{
|
||||
$design = $this->find(Design::visible()->with('collection'), $slug);
|
||||
$templates = $preview->options($design);
|
||||
@@ -48,14 +55,22 @@ class StudioController extends Controller
|
||||
defer(fn () => DesignDailyView::recordView($designId, $date));
|
||||
}
|
||||
|
||||
return $this->page('design', 'design', compact('design', 'templates'), $design);
|
||||
return $this->page('design', 'design', [
|
||||
'design' => $design,
|
||||
'templates' => $templates,
|
||||
'shareImage' => $this->canonicalRoute('artwork', ['id' => $design->id, 'file' => basename($design->artwork_path)]),
|
||||
'shareImageAlt' => $design->text('name'),
|
||||
], $design);
|
||||
}
|
||||
|
||||
public function guides()
|
||||
public function guides(): View
|
||||
{
|
||||
return $this->page('guide', 'guides', [
|
||||
'title' => __('guide.title'),
|
||||
'description' => __('guide.description'),
|
||||
'shareType' => 'article',
|
||||
'shareImage' => asset('porint/guide-workbench.webp'),
|
||||
'shareImageAlt' => __('guide.hero_alt'),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -88,25 +103,22 @@ class StudioController extends Controller
|
||||
return $this->serveWebp($template->photo, $file, GarmentTemplate::PHOTO_DIRECTORY);
|
||||
}
|
||||
|
||||
public function draft(int $id, string $locale, GarmentPreview $preview)
|
||||
public function draft(int $id, string $locale, GarmentPreview $preview): Response
|
||||
{
|
||||
abort_unless(request()->user()->canAccessPanel(Filament::getPanel('studio')), 403);
|
||||
app()->setLocale($locale);
|
||||
|
||||
$design = Design::with('collection')->findOrFail($id);
|
||||
$templates = $preview->options($design);
|
||||
$draft = true;
|
||||
$alternateLocale = $locale === 'fa' ? 'en' : 'fa';
|
||||
|
||||
return response()->view('studio.design', [
|
||||
'design' => $design,
|
||||
'templates' => $templates,
|
||||
'draft' => $draft,
|
||||
'draft' => true,
|
||||
'locale' => $locale,
|
||||
'alternateLocale' => $locale === 'fa' ? 'en' : 'fa',
|
||||
'alternates' => [
|
||||
'fa' => route('studio.preview', ['id' => $id, 'locale' => 'fa']),
|
||||
'en' => route('studio.preview', ['id' => $id, 'locale' => 'en']),
|
||||
],
|
||||
'alternateLocale' => $alternateLocale,
|
||||
'languageSwitchUrl' => route('studio.preview', ['id' => $id, 'locale' => $alternateLocale]),
|
||||
'title' => $design->text('name'),
|
||||
'description' => $design->text('description'),
|
||||
])->header('Cache-Control', 'private, no-store');
|
||||
@@ -134,12 +146,19 @@ class StudioController extends Controller
|
||||
return $private ? $response->setPrivate() : $response;
|
||||
}
|
||||
|
||||
public function sitemap()
|
||||
public function robots(): Response
|
||||
{
|
||||
return response("User-agent: *\nDisallow:\n\nSitemap: ".$this->canonicalRoute('sitemap')."\n", 200, [
|
||||
'Content-Type' => 'text/plain; charset=UTF-8',
|
||||
]);
|
||||
}
|
||||
|
||||
public function sitemap(): Response
|
||||
{
|
||||
$urls = [];
|
||||
foreach (['fa', 'en'] as $locale) {
|
||||
foreach (['home', 'catalog', 'guides'] as $page) {
|
||||
$urls[] = route("$locale.$page");
|
||||
$urls[] = $this->canonicalRoute("$locale.$page");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +168,7 @@ class StudioController extends Controller
|
||||
] as $page => $query) {
|
||||
foreach ($query->get() as $record) {
|
||||
foreach (['fa', 'en'] as $locale) {
|
||||
$urls[] = route("$locale.$page", ['slug' => $record->text('slug', $locale)]);
|
||||
$urls[] = $this->canonicalRoute("$locale.$page", ['slug' => $record->text('slug', $locale)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -173,21 +192,66 @@ class StudioController extends Controller
|
||||
return $query->where('slug_'.app()->getLocale(), $slug)->firstOrFail();
|
||||
}
|
||||
|
||||
private function page(string $view, string $page, array $data, ?LocalizedContent $record = null)
|
||||
/** @param array<string, int|string> $parameters */
|
||||
private function canonicalRoute(string $name, array $parameters = []): string
|
||||
{
|
||||
return rtrim(config('app.url'), '/').route($name, $parameters, absolute: false);
|
||||
}
|
||||
|
||||
private function page(string $view, string $page, array $data, ?LocalizedContent $record = null): View
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
$alternateLocale = $locale === 'fa' ? 'en' : 'fa';
|
||||
$alternates = [];
|
||||
foreach (['fa', 'en'] as $language) {
|
||||
$alternates[$language] = route("$language.$page", $record ? ['slug' => $record->text('slug', $language)] : []);
|
||||
$alternates[$language] = $this->canonicalRoute("$language.$page", $record ? ['slug' => $record->text('slug', $language)] : []);
|
||||
}
|
||||
$title = $record?->text('name') ?? $data['title'] ?? __("studio.titles.$page");
|
||||
$switchParameters = $record ? ['slug' => $record->text('slug', $alternateLocale)] : [];
|
||||
|
||||
return view("studio.$view", [
|
||||
...$data,
|
||||
'locale' => $locale,
|
||||
'alternateLocale' => $locale === 'fa' ? 'en' : 'fa',
|
||||
'alternateLocale' => $alternateLocale,
|
||||
'alternates' => $alternates,
|
||||
'title' => $record?->text('name') ?? $data['title'] ?? __("studio.titles.$page"),
|
||||
'description' => $record?->text('description') ?? $data['description'] ?? __('studio.description'),
|
||||
'languageSwitchUrl' => route("$alternateLocale.$page", $switchParameters),
|
||||
'title' => $title,
|
||||
'description' => $record?->text('description') ?? $data['description'] ?? __("studio.descriptions.$page"),
|
||||
'shareImage' => $data['shareImage'] ?? asset('porint/hero.webp'),
|
||||
'shareImageAlt' => isset($data['shareImage']) ? $data['shareImageAlt'] : __('studio.hero_alt'),
|
||||
'structuredData' => $this->structuredData($page, $locale, $title, $alternates[$locale], $record),
|
||||
]);
|
||||
}
|
||||
|
||||
private function structuredData(string $page, string $locale, string $title, string $url, ?LocalizedContent $record): ?array
|
||||
{
|
||||
if ($page === 'home') {
|
||||
return $locale === 'fa' ? [
|
||||
'@context' => 'https://schema.org',
|
||||
'@type' => 'WebSite',
|
||||
'name' => 'PORINT',
|
||||
'alternateName' => 'پورینت',
|
||||
'url' => $url,
|
||||
] : null;
|
||||
}
|
||||
|
||||
$trail = [[__('studio.home'), $this->canonicalRoute("$locale.home")]];
|
||||
if ($record) {
|
||||
$trail[] = [__('studio.catalog'), $this->canonicalRoute("$locale.catalog")];
|
||||
}
|
||||
if ($record instanceof Design) {
|
||||
$trail[] = [
|
||||
$record->collection->text('name'),
|
||||
$this->canonicalRoute("$locale.collection", ['slug' => $record->collection->text('slug')]),
|
||||
];
|
||||
}
|
||||
$trail[] = [$title, $url];
|
||||
|
||||
$items = [];
|
||||
foreach ($trail as $index => [$name, $itemUrl]) {
|
||||
$items[] = ['@type' => 'ListItem', 'position' => $index + 1, 'name' => $name, 'item' => $itemUrl];
|
||||
}
|
||||
|
||||
return ['@context' => 'https://schema.org', '@type' => 'BreadcrumbList', 'itemListElement' => $items];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class NoIndexStudio
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param Closure(Request): (Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$response = $next($request);
|
||||
|
||||
if ($request->is('studio', 'studio/*', 'up')) {
|
||||
$response->headers->set('X-Robots-Tag', 'noindex, nofollow');
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user