From 5442bf19b06287eb719cd141d0a111cedd86ea14 Mon Sep 17 00:00:00 2001 From: Shikiryu Date: Mon, 27 Jul 2020 12:02:57 +0200 Subject: [PATCH] :sparkles: Ajoute le module SEO Pour #8 Co-authored-by: Clement Reviewed-on: https://git.shikiryu.com/Shikiryu/MyHomeCollection/pulls/12 --- app/Http/Controllers/PublicController.php | 15 +++++ composer.json | 1 + composer.lock | 69 ++++++++++++++++++++++- config/app.php | 2 + config/seotools.php | 68 ++++++++++++++++++++++ resources/views/layouts/app.blade.php | 4 ++ 6 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 config/seotools.php diff --git a/app/Http/Controllers/PublicController.php b/app/Http/Controllers/PublicController.php index 9919619..e5deea7 100644 --- a/app/Http/Controllers/PublicController.php +++ b/app/Http/Controllers/PublicController.php @@ -3,12 +3,27 @@ namespace App\Http\Controllers; use App\Home; +use Artesaos\SEOTools\Traits\SEOTools as SEOToolsTrait; +use DateTime; class PublicController extends Controller { + use SEOToolsTrait; + public function show($slug) { $home = Home::where('slug', $slug)->firstOrFail(); + $this->seo() + ->setTitle($home->title) + ->setDescription($home->excerpt()) + ->addImages(array_map(static function($picture) { + return asset($picture); + }, $home->pictures)); + $this->seo() + ->opengraph() + ->addProperty('article:published_time', $home->created_at->format(DateTime::ATOM)) + ->addProperty('article:author', 'Shikiryu'); + return view('public.view', ['home' => $home]); } } diff --git a/composer.json b/composer.json index a4a9eb7..5c890e5 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,7 @@ "php": "^7.2.5", "ext-json": "*", "absmoca/leboncoin": "dev-master", + "artesaos/seotools": "^0.18.0", "emanueleminotto/simple-html-dom": "^1.5", "fabpot/goutte": "^3.1", "fideloper/proxy": "^4.2", diff --git a/composer.lock b/composer.lock index 678827e..ccf10df 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "71386ccf87ea9b8b3be2921f40baca69", + "content-hash": "b1bb2469deb87a0a1452b8b376e64e1a", "packages": [ { "name": "absmoca/leboncoin", @@ -43,6 +43,73 @@ "description": "SDK du plus célèbre site entre particuliers en France", "time": "2019-01-06T10:00:50+00:00" }, + { + "name": "artesaos/seotools", + "version": "v0.18.0", + "source": { + "type": "git", + "url": "https://github.com/artesaos/seotools.git", + "reference": "91c9fc3ee18db01d220dd47708f303b8eff8078b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/artesaos/seotools/zipball/91c9fc3ee18db01d220dd47708f303b8eff8078b", + "reference": "91c9fc3ee18db01d220dd47708f303b8eff8078b", + "shasum": "" + }, + "require": { + "ext-json": "*", + "illuminate/config": "5.8.* || ^6.0 || ^7.0", + "illuminate/support": "5.8.* || ^6.0 || ^7.0", + "php": ">=7.1" + }, + "require-dev": { + "orchestra/testbench": "~3.8.4 || ^4.0 || ^5.0", + "phpspec/phpspec": "~5.1.1 || ^6.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Artesaos\\SEOTools\\Providers\\SEOToolsServiceProvider" + ], + "aliases": { + "SEOMeta": "Artesaos\\SEOTools\\Facades\\SEOMeta", + "OpenGraph": "Artesaos\\SEOTools\\Facades\\OpenGraph", + "Twitter": "Artesaos\\SEOTools\\Facades\\TwitterCard", + "JsonLd": "Artesaos\\SEOTools\\Facades\\JsonLd", + "SEO": "Artesaos\\SEOTools\\Facades\\SEOTools" + } + } + }, + "autoload": { + "psr-4": { + "Artesaos\\SEOTools\\": "src/SEOTools/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Vinicius", + "email": "luiz.vinicius73@gmail.com" + } + ], + "description": "SEO Tools for Laravel and Lumen", + "keywords": [ + "JSON-LD", + "laravel", + "lumen", + "metatags", + "opengraph", + "seo", + "seotools", + "webmaster" + ], + "time": "2020-06-19T22:31:46+00:00" + }, { "name": "asm89/stack-cors", "version": "v2.0.1", diff --git a/config/app.php b/config/app.php index ae0804b..706dd01 100644 --- a/config/app.php +++ b/config/app.php @@ -165,6 +165,7 @@ return [ /* * Package Service Providers... */ + Artesaos\SEOTools\Providers\SEOToolsServiceProvider::class, /* * Application Service Providers... @@ -220,6 +221,7 @@ return [ 'Response' => Illuminate\Support\Facades\Response::class, 'Route' => Illuminate\Support\Facades\Route::class, 'Schema' => Illuminate\Support\Facades\Schema::class, + 'SEO' => Artesaos\SEOTools\Facades\SEOTools::class, 'Session' => Illuminate\Support\Facades\Session::class, 'Storage' => Illuminate\Support\Facades\Storage::class, 'Str' => Illuminate\Support\Str::class, diff --git a/config/seotools.php b/config/seotools.php new file mode 100644 index 0000000..d56585a --- /dev/null +++ b/config/seotools.php @@ -0,0 +1,68 @@ + [ + /* + * The default configurations to be used by the meta generator. + */ + 'defaults' => [ + 'title' => 'Le projet Bretagne', // set false to total remove + 'titleBefore' => false, // Put defaults.title before page title, like 'It's Over 9000! - Dashboard' + 'description' => false, // set false to total remove + 'separator' => ' - ', + 'keywords' => ['immobilier'], + 'canonical' => false, // Set null for using Url::current(), set false to total remove + 'robots' => false, // Set to 'all', 'none' or any combination of index/noindex and follow/nofollow + ], + /* + * Webmaster tags are always added. + */ + 'webmaster_tags' => [ + 'google' => null, + 'bing' => null, + 'alexa' => null, + 'pinterest' => null, + 'yandex' => null, + 'norton' => null, + ], + + 'add_notranslate_class' => false, + ], + 'opengraph' => [ + /* + * The default configurations to be used by the opengraph generator. + */ + 'defaults' => [ + 'title' => 'Le projet Bretagne', // set false to total remove + 'description' => false, + 'url' => false, // Set null for using Url::current(), set false to total remove + 'type' => 'article', + 'site_name' => 'Le projet Bretagne', + 'images' => [], + ], + ], + 'twitter' => [ + /* + * The default values to be used by the twitter cards generator. + */ + 'defaults' => [ + 'card' => 'summary', + 'site' => '@shikiryu', + ], + ], + 'json-ld' => [ + /* + * The default configurations to be used by the json-ld generator. + */ + 'defaults' => [ + 'title' => 'Le projet Bretagne', // set false to total remove + 'description' => false, // set false to total remove + 'url' => false, // Set null for using Url::current(), set false to total remove + 'type' => 'WebPage', + 'images' => [], + ], + ], +]; diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index daee28a..ef24308 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -4,6 +4,10 @@ + @if(Auth::guest()) + {!! SEO::generate() !!} + @endif +