Coder Social home page Coder Social logo

butschster / laravelmetatags Goto Github PK

View Code? Open in Web Editor NEW
508.0 508.0 47.0 304 KB

The most powerful and extendable tools for managing SEO Meta Tags in your Laravel project

License: MIT License

PHP 100.00%
helper laravel meta meta-tags metas opengraph package php seo seo-meta seo-tags

laravelmetatags's Introduction

Hi there, I'm butschster! 👋

butschster

I'm a highly experienced fullstack PHP developer with over 15 years of development experience under my belt. I'm currently working at SpiralScout, where I'm building the open source Spiral Framework and diving into the Spiral Framework, Cycle ORM, Temporalio, and RoadRunner.

My extensive experience and skills in PHP development allow me to quickly and effectively solve problems and deliver top-quality solutions. I have a strong background in Laravel, VueJS, TailwindCSS.

In addition to my professional work, I am also an active contributor to open source. I contributed to projects such as laravel/framework, nunomaduro/termwind, roadrunner-server/roadrunner, e.t.c.

I am also the creator of many powerful, open-source tools:

  • Birddog - for RoadRunner server monitoring,
  • Buggregator - for PHP applications debugging,
  • butschster/meta-tags - Powerful and extendable tools for managing SEO Meta Tags in your Laravel project
  • SleepingOwlAdmin - Administrative interface builder for Laravel (Laravel admin)

You can find all my packages on packagist

These projects have allowed me to demonstrate my skills in project development and management, and have given me the opportunity to create valuable resources for the PHP community.

I'm really excited about Yii3 too and can't wait to give it a try!

Conclusion

I'm always looking for new opportunities to learn and grow, and I love contributing to open source. Feel free to reach out if you want to chat or collaborate – I'm always open to new connections and projects.

Twitter: @ButscH Telegram: @butschster

butschster github stats

laravelmetatags's People

Contributors

atiksoftware avatar butschster avatar henryavila avatar hladenkyi avatar imsus avatar joserick avatar jwcobb avatar laravel-shift avatar loranger avatar mohamedsabil83 avatar nguyentranchung avatar uintaam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravelmetatags's Issues

Not replacing default values

Describe the bug
I've set default values to config file based on documentation but they never get updated on my routes.

To Reproduce

Expected behavior

Getting my dynamic data meta

Screenshots

012

Desktop (please complete the following information):

  • OS: Win
  • Browser Opera
  • Version 10

Smartphone (please complete the following information):

  • Device: -
  • OS: -
  • Browser -
  • Version -

Additional context

my controller

use Butschster\Head\Facades\Meta;

///

$post = Post::where('slug', $slug)->where('online', true)->with(['user', 'user.posts', 'likes', 'categories'])->first();
if($post){
  views($post)->record();
  Meta::setTitle('Laravel')
   ->prependTitle($post->name)
   ->setKeywords(['a', 'b', 'c'])
   ->setDescription($post->body);
}

How to generate custom meta tag?

Hi
I need to create custom meta tags like this one <meta itemprop="arc:custom-name" content="meta content"> but even I pass an empty sting to name, the result is <meta name="" itemprop="arc:custom-name" content="meta content">.

Is there any way to achieve the pretended output?

Thanks in advance.

Cheers
rjs

Support for property tag

Is there any way to include "property" tag, besides or instead of "name"?

For example, many OG meta are documented to be written with property tag:
https://ogp.me/#structured

How can I write something like this ?

<meta property="og:title" content="The Rock" />
<meta property="og:type" content="video.movie" />
<meta property="og:url" content="https://www.imdb.com/title/tt0117500/" />
<meta property="og:image" content="https://ia.media-imdb.com/images/rock.jpg" />

Thank you

OpenGraph wrong tag attributename

In the OpenGraphPackage you are using the same tag generator like other meta-tags, but this is not working for OpenGraph:
Generated, wrong tag: <meta name="og:type" content="website">
Correct tag would be: <meta property="og:type" content="website">

See: https://developers.facebook.com/docs/sharing/webmasters

My quick "bugfix" local, is to extend vendor/butschster/meta-tags/src/Packages/Entities/Concerns/ManageMeta.php with:

public function addOgMeta(string $key, string $content)
{
$key = $this->prefix.$key;
$this->tags->put($key, Tag::meta([
'property' => $key,
'content' => $content,
]));
return $this;
}

And replace $this->addMeta with $this->addOgMeta in vendor/butschster/meta-tags/src/Packages/Entities/OpenGraphPackage.php

AddProviderToBootstrapFile Error

I am using Laravel 10. When I update the package from 3.0.0 to 3.0.2, I got an error:

Whoops\Run::handleError("A void function must not return a value", "butschster\meta-tags\src\Console\InstallCommand.php")

if (file_exists($this->getLaravel()->bootstrapPath('providers.php'))) {
// @phpstan-ignore-next-line
return ServiceProvider::addProviderToBootstrapFile("{$namespace}\Providers\MetaTagsServiceProvider"); <-- Error here
}

Bug with csrf token

При подключение пакета через конструктор контроллера, не генерируется csrf token

Facade example shows static method usage; however the functions are not actually static

Describe the bug
Facade examples show static method usage however the function definitions are not static functions.

To Reproduce
Use a facade implementation with ::setTitle or any other method and you will see it is not compatible with actual function definition.

Expected behavior
There should be no errors when using static methods with the Facade.

Screenshots
image

image

with PHP 8 I got error "require int, null given"

src/MetaTags/Entities/Title.php
with PHP 8 I got error "require int, null given"

fix it with adding "|null"
line 39: public function __construct(string $title = null, int|null $maxLength = self::DEFAULT_LENGTH)

Вставка description с кавычками

Когда вставляю текст с кавычками, тогда эти кавычки не экранируются.

<meta property="og:description" content="Some "text" with quotes">

Laravel 10 : Installing/updating any version from 3.0.1 throws a fatal error

When installing/updating the package in a Laravel 10 project, a fatal error occurs:

PHP Fatal error: A void function must not return a value in /var/www/laravel10/vendor/butschster/meta-tags/src/Console/InstallCommand.php on line 38

To Reproduce

  1. Install the latest Laravel 10 version
  2. composer require butschster/meta-tags
  3. Error

This commit is the cause of the issue: 43086d3

Note: Forcing the version to 3.0.0 fixes the issue.

Missing PHPDocblock on the Facade

  • "laravel/framework": "^8.0",
  • "butschster/meta-tags": "^1.13",
  • "barryvdh/laravel-ide-helper": "^2.8",

I'm using laravel-ide-helper in PHPStorm and found the Facade class is missing a small PHPDocblock which prevents code completion.

Here is the small missing DocBlock:

/**
 * Class Meta
 * @package Butschster\Head\Facades
 * @mixin MetaInterface
 */
class Meta extends Facade {
}

Multiple CSS

Describe the bug
When using addStyle multiple times, only the last one is inserted into the page via toHtml. I can't see to find a way of adding multiple stylesheets using the API

To Reproduce
Meta::addStyle('style.css', 'http://site.com/style1.css');
Meta::addStyle('style.css', 'http://site.com/style2.css');

Only style2.css is inserted into the page.

<link media="all" type="text/css" rel="stylesheet" href="http://site.com/style2.css">

Expected behavior
I would expect both to be inserted.

<link media="all" type="text/css" rel="stylesheet" href="http://site.com/style1.css">
<link media="all" type="text/css" rel="stylesheet" href="http://site.com/style2.css">

Additional context
Also, the name parameter is ignored, and doesn't seem to be used, so there's no need to pass style.css

    /**
     * @param string $name
     * @param string $src
     * @param array $attributes
     */
    public function __construct(string $name, string $src, array $attributes = [])
    {
        $this->name = $name;
        $this->src = $src;

        parent::__construct('link', $attributes, false);
    }

    /**
     * @return array
     */
    protected function getAttributes(): array
    {
        return array_merge([
            'media' => 'all',
            'type' => 'text/css',
            'rel' => 'stylesheet',
            'href' => $this->src,
        ], parent::getAttributes());
    }

I would guess this might also be the case for addScript?

access tag value

I need to access meta tag value but when I get a tag and then trying to get value property is private, is there any way to do that?

My current code is:
Meta::getTag("title")->title

Add Yandex metrika script builder

It would be cool to use builder for building yandex metrika script.

Something like this:

$tag = new YandexMetrika(20925319);
$tag->webvisor(false)->useCDN()->clickmap(false);

Some Name

What is the name that I have to put here? I don't understand this part, thanks

$og = new Butschster\Head\Packages\Entities\OpenGraphPackage('some_name');

phpunit tests fail when @meta_tags is in a view

I'm using this package for a while which works great. Now I am writing tests for my application but they fail when @meta_tags is present in the view.

Any idea how to resolve this?

I already tried to to remove all meta data in my custom code. This does not resolve the issue.

The exception

(1/1) InvalidArgumentException
Action Facade\Ignition\Http\Controllers\ShareReportController not defined.

The test

    public function testBasicTest()
    {
//        $this->withExceptionHandling();
        $response = $this->get('/');
        $response->dump();

        $response->assertStatus(200);
    }

Php unit result

F                                                                  2 / 2 (100%)

Time: 278 ms, Memory: 28.00 MB

There was 1 failure:

1) Tests\Feature\ExampleTest::testBasicTest
Expected status code 200 but received 500.
Failed asserting that false is true.

/Users/simonvanthuijl/PhpstormProjects/gv/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:166
/Users/simonvanthuijl/PhpstormProjects/gv/tests/Feature/ExampleTest.php:21

FAILURES!
Tests: 2, Assertions: 2, Failures: 1.
Simons-MacBook-Pro:gv simonvanthuijl$ 

html output from the dump function
Screen Shot 2019-10-22 at 00 20 29

Cannot call abstract method

Hello,

If I write this code, as the doc says, I get this message returned by phpStorm. My page doesn't bug but the editor doesn't seem to like it.

use Butschster\Head\Facades\Meta;

Meta::setTitle('Dashboard')
            ->setDescription('Dashboard');

Cannot call abstract method 'MetaInterface::setTitle'

Is there anything I can do?
Thank you

Get Tag's attributes as a property

Is your feature request related to a problem? Please describe.
Get the current value of a tags property. Eg, I wanted to get the current title that was set, as a string. But I had to do something like Meta::getTitle()->toArray()['content'] to get the string value.

Describe the solution you'd like
Can we leverage PHP's magic methods on the base Tag to get the value of a tag's attribute as a property? Like Meta::getTitle()->content (I know title is a special implementation, so maybe not the best example though)

Describe alternatives you've considered
See above

Условия отображения элементов

Стоит предусмотреть возможность скрывать или отображать информацию при наступлении определенных условий, например версия браузера, IP, тип устройства, клиент и т.д.

Overwriting default OpenGraph values

image

I have added default values in the service provider to show as default on all pages for OpenGraph, however, I need certain pages to pass their own values.

image

The above should have used the post values, but instead I still get the default values from the service provider.

How do I override values on a case by case basis?

How I can use multiple "Apple Touch Icon" with addLink() method?

Trying to use addLink() method to add multiple apple-touch-icon but only one is added to HTML because the package use an array_merge. How I can to do this?

Meta::addLink('apple-touch-icon', [
    'href' => asset('apple-icon-57x57.png'),
    'sizes' => '57x57',
])
->addLink('apple-touch-icon', [
    'href' => asset('apple-icon-60x60.png'),
    'sizes' => '60x60',
])
...

Full HTML tags:

<link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192"  href="/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">

Ampersand in query string gets incorrectly escaped

Describe the bug
This seems to be same issue as #5

To Reproduce

Write the following code

Meta::setHrefLang('zh-Hans', 'https://example.com/?foo=bar&lang=zh-hans');

Expected behavior

It outputs

<link rel="alternate" hreflang="zh-Hans" href="https://example.com/?foo=bar&amp;lang=zh-hans">

When it should output

<link rel="alternate" hreflang="zh-Hans" href="https://example.com/?foo=bar&lang=zh-hans">

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Currently I'm replacing all ampersands in my URLs with ESCAPED_AMPERSAND and then other way around after outputting the meta tags. It's not the best way to fix the issue but it works.

Cannot install on Laravel 7

@butschster

Describe the bug
Trait 'Illuminate\Console\DetectsApplicationNamespace' not found

# composer require butschster/meta-tags
Using version ^1.6 for butschster/meta-tags
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing butschster/meta-tags (v1.6.5): Loading from cache
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   Symfony\Component\ErrorHandler\Error\FatalError

  Trait 'Illuminate\Console\DetectsApplicationNamespace' not found

  at C:\Work\www\projects\dummy\vendor\butschster\meta-tags\src\Console\InstallCommand.php:9
     5| use Illuminate\Console\Command;
     6| use Illuminate\Console\DetectsApplicationNamespace;
     7| use Illuminate\Support\Str;
     8|
  >  9| class InstallCommand extends Command
    10| {
    11|     use DetectsApplicationNamespace;
    12|
    13|     /**

To Reproduce
Steps to reproduce the behavior:

  1. Create a fresh Laravel 7 project
  2. Install this package: composer require butschster/meta-tags

Expected behavior
Package installed without errors

Desktop (please complete the following information):

  • OS: Windows 10 / Ubuntu 18.04
  • PHP 7.4.3 (no opcache) / nginx 1.17.8
  • Browser: Any

Changes via package not reflected in `Meta::toHtml()`

Describe the bug
I've registered 2 packages, "twitter" and "facebook" (og) via the MetaTagsServiceProvider (in boot method). Eg: when using $package = Meta::getPackage('facebook') and then modifying some og tags, these changes are not reflected in the html output (using Meta::toHtml() in the base view). I have to call Meta::replacePackage($package) explicitly in the controller to make the html render the updated tags.

Is this intended behaviour? For me the replacePackage call feels a bit counter intuitive and redundant because I already registered the package to be included by default (via config).

To Reproduce

  1. Register a default package (OpenGraph)
  2. Set some default values
  3. In a Controller, get the package, change eg the title
  4. check HTML as it will not reflect the updated title

Expected behavior
it should reflect changes immediately (without replace package)

Screenshots
/

Desktop (please complete the following information):

  • OS: MacOS
  • Browser FF
  • Version /

Method `addScript()` not working

Describe the bug

There's no displayed error with this one, it's just the script tag that doesn't show up in the browser's source code.

// MetaTagsServiceProvider.php

protected function packages()
{
    // *NOTE THE COMMENTS BELLOW...
    PackageManager::create('app', function (Package $package) {
        $package->addScript('app.js', asset('js/app.js'), ['defer']);
    });
}

protected function registerMeta(): void
{
  $this->app->singleton(MetaInterface::class, function () {
      $meta = new Meta(
          $this->app[ManagerInterface::class],
          $this->app['config']
      );

      $meta->initialize();

      $meta->addLink('app.css', [
          'href' => asset('css/app.css'),
          'rel'  => 'stylesheet'
      ]);

      $meta->addLink('bootstrap-icons', [
          'rel'  => 'stylesheet',
          'href' => 'https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css'
      ]);

      // FIRST I TRIED THIS AND IT'S NOT WORKING...
      $meta->addScript('app.js', asset('js/app.js'), ['defer']);
      // THEN I TRIED IN THIS WAY BUT DOESN'T WORK EITHER*
      $meta->includePackages(['app']);

      return $meta;
  });
}
<!doctype html>
<html lang="en" class="h-100">
<head>
    <!-- META -->
    <title>My App</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="597dIm5sGMaTTI90tbPTs9l2QYFsJEOULSQi4Vwx">
<link href="http://myapp.test/css/app.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">    <!-- END META -->
</head>

Expected behavior
I expect to see <script src="http://myapp.test/js/app.js" defer></script> in the <head> tag on every page.

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.