butschster / LaravelMetaTags

The most powerful and extendable tools for managing SEO Meta Tags in your Laravel project
MIT License
550 stars 52 forks source link

Multiple CSS #35

Closed olimortimer closed 3 years ago

olimortimer commented 3 years ago

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?

butschster commented 3 years ago

Hello, @olimortimer

Every tag should have unique name

Meta::addStyle('style.css', 'http://site.com/style1.css');
Meta::addStyle('style2.css', 'http://site.com/style2.css');
olimortimer commented 3 years ago

Thank you, I didn't even think to try that. Apologies.