使得robots.txt由程式產生,加入若干html meta,加入自動產生html title的機制
This commit is contained in:
parent
0bbd14de7d
commit
57fedd69d4
35
app/Http/Controllers/PageController.php
Normal file
35
app/Http/Controllers/PageController.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 靜態頁面的controller
|
||||||
|
*
|
||||||
|
* Class PageController
|
||||||
|
* @package App\Http\Controllers
|
||||||
|
*/
|
||||||
|
class PageController extends Controller
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
return view('index');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Robots.txt
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function robotstxt(Request $request)
|
||||||
|
{
|
||||||
|
if(app('Option')->block_search_indexing) {
|
||||||
|
$content = view('components.robotsTxt.disallowAll');
|
||||||
|
} else {
|
||||||
|
$content = view('components.robotsTxt.default');
|
||||||
|
}
|
||||||
|
return response($content)->header('Content-type', 'text/plain');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -47,6 +47,10 @@ class SetSiteStates
|
|||||||
//預設語系
|
//預設語系
|
||||||
$siteState->defaultLanguage = config('app.fallback_locale');
|
$siteState->defaultLanguage = config('app.fallback_locale');
|
||||||
|
|
||||||
|
//設定預設的meta tag
|
||||||
|
$siteState->htmlMeta['description'] = app('Option')->site_description;
|
||||||
|
$siteState->htmlMeta['og:type'] = 'website';
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
app/Presenters/DocumentTitlePresenter.php
Normal file
19
app/Presenters/DocumentTitlePresenter.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Presenters;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\View;
|
||||||
|
|
||||||
|
class DocumentTitlePresenter
|
||||||
|
{
|
||||||
|
public function get()
|
||||||
|
{
|
||||||
|
$siteName = app('SiteName')->get();
|
||||||
|
$titleSection = trim(View::getSection('title'));
|
||||||
|
if(View::hasSection('title') && $titleSection) {
|
||||||
|
return $titleSection . ' - ' . $siteName;
|
||||||
|
} else {
|
||||||
|
return $siteName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
32
app/Presenters/SiteNamePresenter.php
Normal file
32
app/Presenters/SiteNamePresenter.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Presenters;
|
||||||
|
|
||||||
|
class SiteNamePresenter
|
||||||
|
{
|
||||||
|
private $siteName;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->siteName = $this->init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$configSiteName = config('app.name', 'Laravel');
|
||||||
|
try {
|
||||||
|
$optionSiteName = app('Option')->getOption('site_name');
|
||||||
|
if(!$optionSiteName) {
|
||||||
|
return $configSiteName;
|
||||||
|
}
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
return $configSiteName;
|
||||||
|
}
|
||||||
|
return $optionSiteName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get()
|
||||||
|
{
|
||||||
|
return $this->siteName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -42,7 +42,10 @@ class SingletonServiceProvider extends ServiceProvider
|
|||||||
return new \App\Presenters\Html\HtmlPresenter;
|
return new \App\Presenters\Html\HtmlPresenter;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$this->app->alias(\App\Presenters\SiteNamePresenter::class, 'SiteName');
|
||||||
|
$this->app->singleton(\App\Presenters\SiteNamePresenter::class, function($app){
|
||||||
|
return new \App\Presenters\SiteNamePresenter;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -3,7 +3,4 @@
|
|||||||
@section('title', 'Admin Area')
|
@section('title', 'Admin Area')
|
||||||
|
|
||||||
@section('admin-page-content')
|
@section('admin-page-content')
|
||||||
<pre>
|
|
||||||
{{ print_r(app('AdminMenu')->getMenu()) }}
|
|
||||||
</pre>
|
|
||||||
@endsection
|
@endsection
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="{{ app()->getLocale() }}">
|
<html lang="{{ app()->getLocale() }}">
|
||||||
<head>
|
<head>
|
||||||
|
@include('components.head.title')
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
|||||||
@ -1,4 +1,9 @@
|
|||||||
@extends('admin.layouts.app')
|
@extends('admin.layouts.app')
|
||||||
|
|
||||||
|
@section('title')
|
||||||
|
@lang('adminPageHeader.options.' . $slug)
|
||||||
|
@endsection
|
||||||
|
|
||||||
@section('admin-page-content')
|
@section('admin-page-content')
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
|
|||||||
2
resources/views/components/head/metaNoindex.blade.php
Normal file
2
resources/views/components/head/metaNoindex.blade.php
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<meta name="robots" content="noindex">
|
||||||
|
<meta name="googlebot" content="noindex">
|
||||||
3
resources/views/components/head/metaTags.blade.php
Normal file
3
resources/views/components/head/metaTags.blade.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
@foreach(@app('SiteState')->htmlMeta as $name => $content)
|
||||||
|
<meta name="{{ $name }}" content="{{ $content }}">
|
||||||
|
@endforeach
|
||||||
2
resources/views/components/head/title.blade.php
Normal file
2
resources/views/components/head/title.blade.php
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
@inject('documentTitlePresenter', App\Presenters\DocumentTitlePresenter)
|
||||||
|
<title>{{ $documentTitlePresenter->get() }}</title>
|
||||||
2
resources/views/components/robotsTxt/default.blade.php
Normal file
2
resources/views/components/robotsTxt/default.blade.php
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
User-agent: *
|
||||||
|
Disallow: /{{ config('admin.route') }}/
|
||||||
@ -1,2 +1,2 @@
|
|||||||
User-agent: *
|
User-agent: *
|
||||||
Disallow:
|
Disallow: /
|
||||||
@ -1,11 +1,15 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="{{ app()->getLocale() }}">
|
<html lang="{{ app()->getLocale() }}">
|
||||||
<head>
|
<head>
|
||||||
|
@include('components.head.title')
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||||
|
@include('components.head.metaTags')
|
||||||
|
@if(app('Option')->block_search_indexing)
|
||||||
|
@include('components.head.metaNoindex')
|
||||||
|
@endif
|
||||||
@yield('head-meta')
|
@yield('head-meta')
|
||||||
|
|
||||||
@stack('app-head-scripts')
|
@stack('app-head-scripts')
|
||||||
|
|||||||
@ -21,6 +21,8 @@ Auth::routes(['verify' => true]);
|
|||||||
*/
|
*/
|
||||||
Route::view('/', 'index')->name('index');
|
Route::view('/', 'index')->name('index');
|
||||||
|
|
||||||
|
Route::get('/robots.txt', 'PageController@robotstxt');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Admin routes
|
* Admin routes
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user