From b181dd7e1cf5cda2cb36888de95a83f4ab5a8ae6 Mon Sep 17 00:00:00 2001 From: m105 Date: Sat, 25 Jul 2026 16:25:08 +0300 Subject: [PATCH] Add sitemap.xml/robots.txt and a clearer guest message on site pages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sitemap lists the static pages plus one URL per indexed site (644 URLs currently); not sharded — fine at this scale, but the sitemap protocol caps a single file at 50,000 URLs, so this will need a sitemap index if the site count ever gets there. robots.txt moved from a static public file to a route so it can point at the real sitemap URL in any environment (a static file would also silently shadow the dynamic route in production, since webservers serve existing public/ files before hitting Laravel's router at all). Site detail page: guests now get one prominent banner up top ("you're viewing limited data — register or sign in to see everything") in addition to the existing per-section "N of M results" notices, so the overall gating is obvious immediately rather than only on scroll. Also gave site pages a real per-page meta description (using the site's own description/title) instead of falling back to the generic site-wide one — worth doing now that these pages are actually in the sitemap and indexable. Caught and fixed a real Blade bug along the way: an inline :description="..." expression on with escaped double-quoted PHP strings corrupted the compiler's directive parsing in a way that only surfaced as a 500 on a page rendering the guest @guest block below it (mismatched @if/@endif at compile time) — not on the expression itself. Fixed by computing the description in a @php block first and passing a plain variable instead. Verified over real HTTP: sitemap.xml validates as well-formed XML (644 entries), robots.txt correctly emits the live sitemap URL, the guest banner and site-specific meta description both render correctly. Full test suite (31 tests) passes. --- app/Http/Controllers/SitemapController.php | 24 ++++++++++++++++++++ public/robots.txt | 2 -- resources/views/sitemap.blade.php | 26 ++++++++++++++++++++++ resources/views/sites/show.blade.php | 18 ++++++++++++++- routes/web.php | 8 +++++++ 5 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 app/Http/Controllers/SitemapController.php delete mode 100644 public/robots.txt create mode 100644 resources/views/sitemap.blade.php diff --git a/app/Http/Controllers/SitemapController.php b/app/Http/Controllers/SitemapController.php new file mode 100644 index 0000000..30a9067 --- /dev/null +++ b/app/Http/Controllers/SitemapController.php @@ -0,0 +1,24 @@ +orderBy('id')->get(); + + $xml = view('sitemap', ['sites' => $sites])->render(); + + return response($xml, 200)->header('Content-Type', 'application/xml'); + } +} 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/sitemap.blade.php b/resources/views/sitemap.blade.php new file mode 100644 index 0000000..cfe4f9b --- /dev/null +++ b/resources/views/sitemap.blade.php @@ -0,0 +1,26 @@ + + + + {{ route('home') }} + daily + 1.0 + + + {{ route('sites.index') }} + daily + 0.8 + + + {{ route('discover') }} + daily + 0.7 + +@foreach ($sites as $site) + + {{ route('sites.show', $site) }} + {{ $site->updated_at->toAtomString() }} + weekly + 0.5 + +@endforeach + diff --git a/resources/views/sites/show.blade.php b/resources/views/sites/show.blade.php index 9e89eab..51cc8cf 100644 --- a/resources/views/sites/show.blade.php +++ b/resources/views/sites/show.blade.php @@ -1,4 +1,10 @@ - +@php + $metaDescription = $site->description + ?: ($site->title + ? "{$site->title} ({$site->domain}) — competitor analysis, backlinks, and tech stack." + : "Competitor analysis for {$site->domain}: pages, backlinks, and tech stack."); +@endphp +
← Back to sites @@ -25,6 +31,16 @@

@endif + @guest +
+ You're viewing limited data for this site. + Create a free account + or + sign in + to see all of its pages, backlinks, and subdomains. +
+ @endguest + @if ($site->server || $site->powered_by || $site->generator)
@if ($site->generator) diff --git a/routes/web.php b/routes/web.php index d2ef9bf..905c01f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,7 @@ name('sites.index'); Route::get('/sites/{site}', [SiteController::class, 'show'])->name('sites.show'); Route::get('/discover', DiscoverSearch::class)->name('discover'); +Route::get('/sitemap.xml', SitemapController::class)->name('sitemap'); + +Route::get('/robots.txt', function () { + return response("User-agent: *\nDisallow:\nSitemap: ".url('/sitemap.xml')."\n") + ->header('Content-Type', 'text/plain'); +})->name('robots'); + Route::view('profile', 'profile') ->middleware(['auth']) ->name('profile');