Add sitemap.xml/robots.txt and a clearer guest message on site pages
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 <x-layouts.app> 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 <url> 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.
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Site;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
|
class SitemapController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Lists every static page plus one URL per indexed site. Not paginated/sharded —
|
||||||
|
* fine at current scale, but a single sitemap is only valid up to 50,000 URLs
|
||||||
|
* (the sitemap protocol's hard limit), so this will need a sitemap index +
|
||||||
|
* multiple child sitemaps if the site count ever approaches that.
|
||||||
|
*/
|
||||||
|
public function __invoke(): Response
|
||||||
|
{
|
||||||
|
$sites = Site::select('id', 'updated_at')->orderBy('id')->get();
|
||||||
|
|
||||||
|
$xml = view('sitemap', ['sites' => $sites])->render();
|
||||||
|
|
||||||
|
return response($xml, 200)->header('Content-Type', 'application/xml');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
User-agent: *
|
|
||||||
Disallow:
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
|
<url>
|
||||||
|
<loc>{{ route('home') }}</loc>
|
||||||
|
<changefreq>daily</changefreq>
|
||||||
|
<priority>1.0</priority>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>{{ route('sites.index') }}</loc>
|
||||||
|
<changefreq>daily</changefreq>
|
||||||
|
<priority>0.8</priority>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>{{ route('discover') }}</loc>
|
||||||
|
<changefreq>daily</changefreq>
|
||||||
|
<priority>0.7</priority>
|
||||||
|
</url>
|
||||||
|
@foreach ($sites as $site)
|
||||||
|
<url>
|
||||||
|
<loc>{{ route('sites.show', $site) }}</loc>
|
||||||
|
<lastmod>{{ $site->updated_at->toAtomString() }}</lastmod>
|
||||||
|
<changefreq>weekly</changefreq>
|
||||||
|
<priority>0.5</priority>
|
||||||
|
</url>
|
||||||
|
@endforeach
|
||||||
|
</urlset>
|
||||||
@@ -1,4 +1,10 @@
|
|||||||
<x-layouts.app :title="$site->domain">
|
@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
|
||||||
|
<x-layouts.app :title="$site->domain" :description="$metaDescription">
|
||||||
<div class="mx-auto max-w-5xl px-4 py-8">
|
<div class="mx-auto max-w-5xl px-4 py-8">
|
||||||
<a href="{{ route('sites.index') }}" class="text-sm text-blue-600 hover:underline dark:text-blue-400">← Back to sites</a>
|
<a href="{{ route('sites.index') }}" class="text-sm text-blue-600 hover:underline dark:text-blue-400">← Back to sites</a>
|
||||||
|
|
||||||
@@ -25,6 +31,16 @@
|
|||||||
</p>
|
</p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
@guest
|
||||||
|
<div class="mt-4 rounded-lg border border-blue-200 bg-blue-50 px-4 py-3 text-sm text-blue-800 dark:border-blue-900 dark:bg-blue-950 dark:text-blue-300">
|
||||||
|
You're viewing limited data for this site.
|
||||||
|
<a href="{{ route('register') }}" class="font-medium underline">Create a free account</a>
|
||||||
|
or
|
||||||
|
<a href="{{ route('login') }}" class="font-medium underline">sign in</a>
|
||||||
|
to see all of its pages, backlinks, and subdomains.
|
||||||
|
</div>
|
||||||
|
@endguest
|
||||||
|
|
||||||
@if ($site->server || $site->powered_by || $site->generator)
|
@if ($site->server || $site->powered_by || $site->generator)
|
||||||
<div class="mt-3 flex flex-wrap gap-2">
|
<div class="mt-3 flex flex-wrap gap-2">
|
||||||
@if ($site->generator)
|
@if ($site->generator)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Http\Controllers\SiteController;
|
use App\Http\Controllers\SiteController;
|
||||||
|
use App\Http\Controllers\SitemapController;
|
||||||
use App\Livewire\Actions\Logout;
|
use App\Livewire\Actions\Logout;
|
||||||
use App\Livewire\Discover\Search as DiscoverSearch;
|
use App\Livewire\Discover\Search as DiscoverSearch;
|
||||||
use App\Livewire\Sites\Index as SitesIndex;
|
use App\Livewire\Sites\Index as SitesIndex;
|
||||||
@@ -11,6 +12,13 @@ Route::get('/sites', SitesIndex::class)->name('sites.index');
|
|||||||
Route::get('/sites/{site}', [SiteController::class, 'show'])->name('sites.show');
|
Route::get('/sites/{site}', [SiteController::class, 'show'])->name('sites.show');
|
||||||
Route::get('/discover', DiscoverSearch::class)->name('discover');
|
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')
|
Route::view('profile', 'profile')
|
||||||
->middleware(['auth'])
|
->middleware(['auth'])
|
||||||
->name('profile');
|
->name('profile');
|
||||||
|
|||||||
Reference in New Issue
Block a user