From a8e79bd567ab45d403a2200db2f38930ad43cd5c Mon Sep 17 00:00:00 2001 From: Meghdad <61308304+MeghdadFadaee@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:42:49 +0330 Subject: [PATCH] add no index --- README.md | 1 + app/Http/Controllers/StudioController.php | 106 +++++++++++++++++----- app/Http/Middleware/NoIndexStudio.php | 26 ++++++ bootstrap/app.php | 2 + lang/en/studio.php | 5 +- lang/fa/studio.php | 5 +- public/robots.txt | 2 - resources/views/studio/guide.blade.php | 9 -- resources/views/studio/layout.blade.php | 18 +++- routes/studio.php | 1 + tests/Feature/PorintStudioTest.php | 70 +++++++++++++- 11 files changed, 204 insertions(+), 41 deletions(-) create mode 100644 app/Http/Middleware/NoIndexStudio.php delete mode 100644 public/robots.txt diff --git a/README.md b/README.md index aa65664..6ea2ed8 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ GitHub Actions runs the tests, TypeScript checks, and the Vite build for pushes ## Deployment and redistribution - Serve the `public/` directory over HTTPS. Set `APP_ENV=production`, `APP_DEBUG=false`, `APP_URL` to the canonical HTTPS origin, and `SESSION_SECURE_COOKIE=true` in the server environment. +- Permanently redirect HTTP and alternate hostnames to the canonical HTTPS origin. Route `/robots.txt` and `/sitemap.xml` through Laravel, including on Nginx deployments with an exact-match `/robots.txt` location. After deployment, verify both URLs on the public domain and submit `/sitemap.xml` in Google Search Console. - Install the locked dependencies and build Vite assets. Run `php artisan filament:assets` to publish Filament's generated assets and `php artisan migrate --force` to apply the schema. Use `php artisan migrate --seed` for a local demo. - Keep the SQLite database and `storage/app/private` outside the web root. Back them up with the application key. The staff panel uses authenticated sessions. Configure server and CDN access logs to follow the visitor-data policy. - `public/porint` and `database/seeders/artwork` contain the imagery needed to run the demo. Review redistribution rights for the supplied collection sheets and their derivatives before publishing the repository. Keep working originals and generated concepts in local storage. diff --git a/app/Http/Controllers/StudioController.php b/app/Http/Controllers/StudioController.php index 48f9d6f..5d7890d 100644 --- a/app/Http/Controllers/StudioController.php +++ b/app/Http/Controllers/StudioController.php @@ -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 $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]; + } } diff --git a/app/Http/Middleware/NoIndexStudio.php b/app/Http/Middleware/NoIndexStudio.php new file mode 100644 index 0000000..989420c --- /dev/null +++ b/app/Http/Middleware/NoIndexStudio.php @@ -0,0 +1,26 @@ +is('studio', 'studio/*', 'up')) { + $response->headers->set('X-Robots-Tag', 'noindex, nofollow'); + } + + return $response; + } +} diff --git a/bootstrap/app.php b/bootstrap/app.php index 023025b..252c7df 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -1,5 +1,6 @@ Route::group([], base_path('routes/studio.php')), ) ->withMiddleware(function (Middleware $middleware): void { + $middleware->append(NoIndexStudio::class); $middleware->redirectGuestsTo(fn () => route('filament.studio.auth.login')); }) ->withExceptions(function (Exceptions $exceptions): void { diff --git a/lang/en/studio.php b/lang/en/studio.php index ea04961..b64e5c2 100644 --- a/lang/en/studio.php +++ b/lang/en/studio.php @@ -2,7 +2,10 @@ return [ 'titles' => ['home' => 'Heat-transfer designs for clothing', 'catalog' => 'Heat-transfer collections'], - 'description' => 'Explore PORINT’s heat-transfer designs, see your favorite motifs on clothes, and learn how to apply and care for them.', + 'descriptions' => [ + 'home' => 'Explore PORINT’s heat-transfer designs, see your favorite motifs on clothes, and learn how to apply and care for them.', + 'catalog' => 'Browse PORINT’s heat-transfer collections, from Rose & Thorn to Sound Wave, and preview individual designs on T-shirts, hoodies, and more.', + ], 'catalog' => 'Collections', 'guides' => 'Print guide', 'language' => 'فارسی', diff --git a/lang/fa/studio.php b/lang/fa/studio.php index 0890a15..7f7b67f 100644 --- a/lang/fa/studio.php +++ b/lang/fa/studio.php @@ -2,7 +2,10 @@ return [ 'titles' => ['home' => 'طرح‌های چاپ حرارتی لباس', 'catalog' => 'مجموعه‌های چاپ حرارتی'], - 'description' => 'طرح‌های چاپ حرارتی لباس از استودیو پورینت؛ مجموعه‌ها را ببینید، طرح‌ها را روی لباس امتحان کنید و راهنمای نصب را بخوانید.', + 'descriptions' => [ + 'home' => 'طرح‌های چاپ حرارتی لباس از استودیو پورینت؛ مجموعه‌ها را ببینید، طرح‌ها را روی لباس امتحان کنید و راهنمای نصب را بخوانید.', + 'catalog' => 'مجموعه‌های طرح چاپ حرارتی پورینت، از «رز و خار» تا «موج صدا»، را ببینید و طرح‌ها را روی تی‌شرت، هودی و لباس‌های دیگر امتحان کنید.', + ], 'catalog' => 'مجموعه‌ها', 'guides' => 'راهنمای چاپ', 'language' => 'English', diff --git a/public/robots.txt b/public/robots.txt deleted file mode 100644 index eb05362..0000000 --- a/public/robots.txt +++ /dev/null @@ -1,2 +0,0 @@ -User-agent: * -Disallow: diff --git a/resources/views/studio/guide.blade.php b/resources/views/studio/guide.blade.php index c04b5b9..4e48e54 100644 --- a/resources/views/studio/guide.blade.php +++ b/resources/views/studio/guide.blade.php @@ -1,14 +1,5 @@ @extends('studio.layout') -@push('head') - - - - - - -@endpush - @section('content')