Skip to content

Commit e84d881

Browse files
committed
Added no-index when open mirror
1 parent 68c9f8e commit e84d881

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

app/View/Components/MetaNoIndex.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace App\View\Components;
4+
5+
use Illuminate\View\Component;
6+
7+
class MetaNoIndex extends Component
8+
{
9+
/**
10+
* Current domain to compare against.
11+
*
12+
* @var string
13+
*/
14+
public string $expectedDomain;
15+
16+
public function __construct()
17+
{
18+
$this->expectedDomain = parse_url(config('app.url'), PHP_URL_HOST);
19+
}
20+
21+
/**
22+
* Check if the current URL matches the expected one.
23+
*/
24+
public function shouldRender(): bool
25+
{
26+
$currentDomain = parse_url(request()->fullUrl(), PHP_URL_HOST);
27+
28+
return $currentDomain !== $this->expectedDomain;
29+
}
30+
31+
/**
32+
* Get the view / contents that represent the component.
33+
*/
34+
public function render()
35+
{
36+
return '<meta name="robots" content="noindex, nofollow">';
37+
}
38+
}

resources/views/html.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
image="{!! route('cover', ['text' => View::getSection('cover') ?? View::getSection('title', config('site.description'))]) !!}"
4040
{{-- csp="*.laravel.su *.gravatar.com *.githubusercontent.com" --}} />
4141

42+
<x-meta-no-index />
43+
4244
<link rel="preconnect" href="https://fonts.googleapis.com">
4345
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
4446
<link href="https://fonts.googleapis.com/css2?family=Raleway:wght@400;500;600;700;800&display=swap"

0 commit comments

Comments
 (0)