kirby-meta-knight icon indicating copy to clipboard operation
kirby-meta-knight copied to clipboard

REQUEST: Define a fallback page field for description.

Open AhoyLemon opened this issue 3 years ago • 10 comments

Hiya! I was just checking out MetaKnight and I really like it, but there's one specific thing keeping me from adopting it for sites right now.

The way that I built my own fallbacks is that it looks for the meta description, but if it can't find one it looks for $page->text().

If it finds $page->text(), then it'll trim the first 180 characters of that, and turn that into the page description.

But if it can't find that, it'll just use the backup site meta instead.

Obviously every Kirby site is gonna be built differently, but do you think it would be possible to implement configs for fallbacks before it goes to site description?

I can PR some changes to meta_information.php if you like.

AhoyLemon avatar Mar 04 '21 16:03 AhoyLemon

Thanks for your feedback. This is a very interesting idea. I'll look into adding it as a config option.

The one thing I am worried about is that fallbacks aren't self-explanatory. I need to come up with a better way of communicating where the plugin is pulling the fall back information from. Maybe a small label in the preview section?

jonathanmuth avatar Mar 11 '21 11:03 jonathanmuth

I share your concern, although in general I think the preview boxes do a pretty good job of showcasing what's getting used and why.

But, here's an idea... image

AhoyLemon avatar Mar 12 '21 15:03 AhoyLemon

I'd like to extend this request to all fields, not just "Description". The ability to be able to pull information automatically from other fields on the page is pretty essential.

A typical use-case is when a site has a Blog with Article pages. In general, the Article page will already have:

  • a 'Teaser' field, which is used for 'Description'
  • a 'Tags' field, which can be used for 'Keywords'
  • a 'Main Image' or 'Featured Image', which is what should be used for social media previews and embeds
  • an 'Author' field

We don't really want to have to ask the client to enter all that information twice, in different places. Specially for small-business clients, who have to do everything themselves, we want to keep work to a minimum.

Ideally, we would love to be able to setup the Meta Knight fields so they would take precedence over the 'default' fields on the page - i.e., if the client does enter something in the Meta Knight 'Description' field, then that would be used in preference over what's been entered in the 'Teaser' field for the article. This would give clients that have an 'SEO Expert' working with them the ability to 'override' the metadata defaults if they want, while not having to do so for every single Article page.

A possible way to make it work would be to setup 'default' field values directly in the page's blueprint:

metaknight:
  # Keys are default Meta Knight field names
  # Values are the names of 'default' fields, already present on this page
  description: article_teaser
  author: article_author

Then, when outputting the metadata fields in the template, the method would:

  1. look for the value in the Meta Knight field - if the value is there, use it.
  2. if the value is not there, then look in the blueprint, to see if a 'default' field has been set. If so, use the value from that field.
  3. if no value has been set for a 'default' field, or the 'default' field doesn't exist, or is empty, or the value is in the wrong format, or any other issue is found, omit the tag.

iocouto avatar Mar 26 '21 05:03 iocouto

@iocouto Thank you so much for thinking this through and coming up with a possible solution. You are absolutely right, nobody wants to enter the same information twice. Would be great if we can find a way to setup default fields via a page's blueprint.

While this shouldn't be too difficult to implement in the template, I'd also like to display the 'default' field values in the SEO tab's previews. Not 100% sure how I would do that. I'll need some time to think it through. Any help is appreciated.

jonathanmuth avatar Apr 07 '21 20:04 jonathanmuth

What about setting up fallback order in config.php. Thinking something like this....

'diesdasdigital.meta-knight' => [
        'fallbackFields' => [
            'description' => [
                'page_description',
                'summary'
                'text',
            ],
            'image' => [
                'hero'
                'pic',
            ]
        ]
]

So this is saying...

"if you don't have a meta description for this page, see if there's something in $page->page_description();, if not, check $page->summary();. If not, check $page->text();. If none of those, go to the sitewide default.

Similarly, check $page->hero() and then $page->pic() for fallback images.

AhoyLemon avatar Apr 12 '21 16:04 AhoyLemon

hi all, sorry if i didnt read all comments, but maybe storing the defaults from the site.yml? not sure if that helps with the previews. right now i have a tab for default seo in my site.yml and then each page has the same tab. and then in the templates i just check if the page has SEO data, if not, i call the site data.

i know its a bit different than the defaults ahoy is talking about, but i think this would be the lowest level of default as a fail safe

squareclouds avatar Jul 02 '21 11:07 squareclouds

This would be really helpful. I have looked into it a little and I really like the suggestion of @iocouto to define the fallbacks on a blueprint/template base.

In PHP it should be something like $page->blueprint()->metaknight()['fallbacks']['description']

As for the VUE part, looking at the network tab shows that the blueprint data is part of the data request too.

I wanted to tinker around a bit, but I encountered some postcss8 error when building.

Anyway, @jonathanmuth is this somewhere on you list in the coming months or are you busy? If busy, I can have a go at it if time permits, as I am currently quite busy as well, but I think this feature would save a lot of time for future clients so there is a good reason to squeeze it in :)

rootman avatar Jul 29 '21 08:07 rootman

This would be a really great feature and as I cannot develop it by my own I can help you testing it on my 3.6 alpha test environment for my personal blog.

MaluNoPeleke avatar Aug 31 '21 08:08 MaluNoPeleke

Is there any workaround for this in the meanwhile? I just migrated with my website from Ghost CMS to Kirby CMS and don't want to manually define all the SEO related fields for 100 pages but with the current implementation of MetaKnight social sharing images for one article are not the right ones but instead always the one from the site settings and I would like to define specific fields such as @iocouto mentioned. I see this as a mapping task: You always have a header field for the main article image -> map it to all the social sharing images. If not set for an article fall back to default etc.

MaluNoPeleke avatar Dec 20 '21 13:12 MaluNoPeleke

@MaluNoPeleke Have a look at https://github.com/jonaskuske/kirby-meta-knight/blob/docs/source-seo-from-content/README.md#sourcing-seo-data-from-existing-page-content :)

TL;DR:

<?php // site/models/default.php

class DefaultPage extends Page {
  public function meta_description() {
    return parent::meta_description()->or($your_fallback_here);
  }
}

jonaskuske avatar Jul 27 '22 01:07 jonaskuske