pedroborges / kirby-meta-tags

⬢ HTML meta tags generator for Kirby. Supports Open Graph and Twitter Cards out of the box.
MIT License
97 stars 11 forks source link

How to define multiple preconnect and prefetch links? #7

Closed bvdputte closed 6 years ago

bvdputte commented 6 years ago

I would like to use multiple "prefetch" and "preconnect" links:

e.g.:

c::set('meta-tags.default', function(Page $page, Site $site) {
    return [
        'link' => [
            'prefetch' => "https://use.typekit.net",
            'preconnect' => "https://use.typekit.net"
            'prefetch' => "https://some.other-domain.tld",
            'preconnect' => "https://some.other-domain.tld"
        ],
});

Only the last are being printed :-S

pedroborges commented 6 years ago

Here's what I use:

c::set('meta-tags.default', function(Page $page, Site $site) {
    return [
        'link' => [
            'prefetch' => [
              ['href' => 'https://use.typekit.net'],
              ['href' => 'https://some.other-domain.tld'],
            ],
            'preconnect' => [
              ['href' => 'https://use.typekit.net'],
              ['href' => 'https://some.other-domain.tld'],
            ],
        ],
    ];
});
bvdputte commented 6 years ago

Ah yes, of course. This works then. Thx!

But, is it expected if I want to extend this via template specific meta-tags config that I'ld have to redefine everything which is already defined in the default config?

e.g.:

c::set('meta-tags.default', function(Page $page, Site $site) {
    return [
        'link' => [
            'prefetch' => [
              ['href' => 'https://use.typekit.net'],
            ],
            'preconnect' => [
              ['href' => 'https://use.typekit.net'],
            ],
        ],
    ];
});

icw

c::set('meta-tags.templates', function(Page $page, Site $site) {
    'sometemplate' => function($page, $site) {
        return [
            'link' => [
                'prefetch' => [
                    ['href' => 'https://use.typekit.net'], // already defined in default ?
                    ['href' => 'https://some.other-domain.tld']
                ],
                'preconnect' => [
                    ['href' => 'https://use.typekit.net'], // already defined in default ?
                    ['href' => 'https://some.other-domain.tld']
                ],
            ],
        ];
    }
});

When I do not add the typekit domains again in the meta-tags.templates config, they are not being output.


This probably due to the array_merge that's happening. Not really sure if you can workaround that easily. If not, maybe make this more obvious somewhere?

bvdputte commented 6 years ago

Nevermind. Upgrading to Kirby 2.5.12 fixed this. Probably something in the a array helper class in the toolkit.