GithubHelp home page GithubHelp logo

heywhy / seotamic Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cnj-digital/seotamic

0.0 1.0 0.0 557 KB

A Statamic v3 SEO addon

JavaScript 1.42% PHP 74.93% CSS 0.07% Vue 20.76% Blade 0.60% Antlers 2.22%

seotamic's Introduction

PRO Version: If you are having issues with the license, make sure to add 'cnj/seotamic' => 'pro' in the config/statamic/editions.php addons array.

Seotamic - Statamic SEO Addon

Statamic v3.3+ only. Automatically adds a SEO tab to all your collection entries where you can fine tune SEO for every entry. Works perfectly with Antlers, Blade and in headless mode (PRO edition) with the Statamic REST API or GraphQL integration out of the box.

Quick Antlers usage sample

{{ seotamic }}

Generates the whole array of SEO settings:

<title>My Page Title</title>
<meta name="description" content="SEO friendly description" />
<link rel="canonical" href="https://mysite.com/page" />
<meta property="og:url" content="https://mysite.com/page" />
<meta property="og:site_name" content="Site name" />
<meta property="og:title" content="My Page Title" />
<meta property="og:description" content="SEO friendly description" />
<meta property="og:image" content="https://mysite.com/img/og.jpg" />
...

Version 3 changes

Version 3 has breaking changes. If you update from version 1 or 2, your global settings will not be transfered. The data layout is a bit different and so is the data on specific entries.

The string tags were changed to arrays so to access the data you need to use the :meta or :social prefixes. For example {{ seotamic:title }} becomes {{ seotamic:meta:title }}.

Migration from version 2

If you are migrating from version 2, you can use the following command to migrate your data:

php artisan seotamic:migrate

This will migrate your global settings and all the entries. It will also remove the old fields from the entries. Make sure to backup your data before running the command.

Installation

Include the package with composer:

composer require cnj/seotamic

The package requires Laravel 9+ and PHP 8.0+. It will auto register.

The SEO & Social section tab will appear on all collection entries automatically.

Configuration (optional)

You can override the default options by publishing the configuration:

php artisan vendor:publish --provider="Cnj\Seotamic\ServiceProvider" --tag=config

This will copy the default config file to `config/seotamic.php'.

If you need to change the default assets container, make sure to apply the change in the Blueprints as well.

Usage

Usage is fairly simple and straight forward. You can visit the global Settings by following the Seotamic link on the navigation in the CP. Make sure to follow the instructions on each field.

Meta preview

After this you can fine tune the output of each collection entry by editing the SEO settings under the entry's SEO tab. In version 3 you can also preview the output of the meta and social settings. The previews should give an accurate representation of the output.

Social preview

Antlers

There are several antler tags available, the easiest is to just include the do everything base tag in the head of your layout:

{{ seotamic }}

If you need more control you can manually get each part of the output by using:

{{ seotamic:meta:title }}
{{ seotamic:meta:description }}
{{ seotamic:meta:canonical }}
{{ seotamic:meta:robots }}

This will return strings, so you need to wrap them in the appropriate tags, ie:

<title>{{ seotamic:meta:title }}</title>

Social ones will still return everything with these tags (the general one returns this as well)

{{ seotamic:og }}
{{ seotamic:twitter }}

If you need more control you can manually get each part of the output by using:

{{ seotamic:social:title }}
{{ seotamic:social:description }}
{{ seotamic:social:image }}
{{ seotamic:social:site_name }}

This will return strings, so you need to wrap them in the appropriate tags.

Blade

Similarly to the Antlers usage, you can use the same tags using Blade:

{!! Statamic::tag('seotamic')->context(get_defined_vars()) !!}

It works similary to the Antlers tags, so you can use single values as well.

Headless (PRO)

Headless use is straightforward. If using the REST API or GraphQL, the entry will include three Seotamic fields: seotamic_meta, seotamic_social with the prefilled SEO data.

Headless usage is supported only for the PRO version.

Sitemap (PRO)

Sitemap is autogenerated under the /sitemap.xml url if the sitemap config options are set to true (default).

Sitemap is supported only for the PRO version.

Dynamic OG Image injection

In projects where you want the OG Image to be dynamic, for now you can use this ViewModel and inject it to your collection in order to dynamically assign the OG Image.

<?php

namespace App\ViewModels;

use Statamic\View\ViewModel;

class OgImage extends ViewModel
{
    public function data(): array
    {
        $social = $this->cascade->get('seotamic_social');

        if ($social) {
          return [ ...$social, 'image' => 'https://myimageurl.com/image.jpg', ];
        }

        return [];
    }
}

In the example above we use a hardcoded image url which you can change to suit your usecase. Then in your collections you just have to inject the ViewModel.

title: Posts
inject:
  view_model: App\ViewModels\OgImage

Credits

This package was built by CNJ Digital.

Version 3 License

Version 3 is a commercial addon for Statamic. It is open source but not free to use. You can purchase a license at Statamic Marketplace.

Version 2 and 1 License

Version 2 and 1 were licensed under the MIT License.

seotamic's People

Contributors

martink635 avatar ryanmitchell avatar jmartsch avatar lokmanm avatar beatwiz avatar heywhy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.