ideas icon indicating copy to clipboard operation
ideas copied to clipboard

Add optional rel field for Bard Links

Open jeremydouglas opened this issue 4 years ago • 2 comments

Currently nofollow links on Bard is either all-in or all-out.

It would be helpful to be able to specify this on a per-link basis. Using a text input would allow setting nofollow, sponsored, etc. As an example:

image

jeremydouglas avatar Nov 12 '21 17:11 jeremydouglas

I was thinking sort of the same thing, but instead of having link_noreferrer, link_nooperner and target_blank a toggle with true/false, change it to be a radio of true/false/external so internal links and assets are left as they are, but external links default to open in a new window with proper SEO rel value.

FrittenKeeZ avatar Jan 24 '22 09:01 FrittenKeeZ

@jeremydouglas did you implement a solution yourself in the end?

simonridley avatar Oct 31 '22 17:10 simonridley

This would be super useful. Is there an example implementation anywhere?

tadekrzewuski-lc avatar Sep 25 '23 07:09 tadekrzewuski-lc

We ended up doing it ourselves using the jacksleight/statamic-bard-mutator package:

Mutator::html('link', function ($value) {
    $href = $value[1]['href'] ?? null;
    if (URL::isExternal($href) && !Str::startsWith($href, ['mailto:', 'tel:'])) {
        $value[1]['rel'] = 'external noopener';
        $value[1]['target'] = '_blank';
    }

    return $value;
});

FrittenKeeZ avatar Sep 25 '23 07:09 FrittenKeeZ

Thanks, this is helpful! I also found a way by using https://jacksleight.dev/docs/bard-texstyle/attributes but it feels a bit clunky as it's being set in a separate button in the toolbar... and to get this you need the pro version. I'll see if I can achieve this directly in the link button in Bard.

tadekrzewuski-lc avatar Sep 25 '23 08:09 tadekrzewuski-lc