spatie / blender

The Laravel template used for our CMS like projects
https://freek.dev/on-open-sourcing-blender
877 stars 148 forks source link

Improve SEO value handling & rendering #347

Closed sebastiandedeyne closed 7 years ago

sebastiandedeyne commented 7 years ago

There are currently two kinds of values we need to deal with regarding SEO:

Title Used in the title tag and in some meta tags, can be set by a view, by a model or have a default value.

Other meta values Other meta and open graph tags.

Proposal

A "meta" object to deal with these values.

The default values would be set in the layout file via an array, or via a view composer. Child views could pass values to merge with the original meta array.

{{-- layout.blade.php --}}

<html>
    <head>
        {{-- Full example... --}}
        @php(meta()->push($meta ?? []))
        <title>{{ meta()->title() }}</title>
        {{ meta()->tags() }}

        {{-- ...which could be distilled to something leaner like this... --}}
        {{ meta()->with($meta ?? []) }}
    </head>
    <body>
    </body>
</html>
{{-- page.blade.php --}}

@component('layout', [
    'meta' => [
        'title' => 'My page',
        'canonical' => 'https://spatie.be/page',
        'og:image' => '/path/to/image',
    ],
])
    Page contents...
@endcomponent

We can also add some fun things like easier title handling.

// A default title when none is provided
meta()->defaultTitle('Spatie');

// If a custom title is provided, transform it
meta()->transformTitle(function (string $title): string {
    return "{$title} — Spatie webdesign Antwerpen";
});