Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REQUEST: Define a fallback page field for description. #14

Open
AhoyLemon opened this issue Mar 4, 2021 · 10 comments · May be fixed by #58
Open

REQUEST: Define a fallback page field for description. #14

AhoyLemon opened this issue Mar 4, 2021 · 10 comments · May be fixed by #58
Labels
enhancement New feature or request

Comments

@AhoyLemon
Copy link

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 added a commit to AhoyLemon/kirby-meta-knight that referenced this issue Mar 8, 2021
This is something I mentioned in Issue diesdasdigital#14, and I ended up adding these changes to my own site. I'm putting it in as a PR just in case you think it would help you as well.

So basically, what this does in a nutshell is add an excerpt of page->text() as a fallback between manually enterered meta info and the sitewide meta info.

So, for example, OpenGraph looks like...

1. OpenGraph Description
2. Meta Description
3. Excerpt of Page Text
4. Sitewide Meta Description
5. blank/error message

If this is unhelpful or not what you were thinking for this plugin, do please ignore. Just providing what I did in case it helps others.
@jonathanmuth
Copy link
Contributor

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?

@AhoyLemon
Copy link
Author

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

@iocouto
Copy link

iocouto commented Mar 26, 2021

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.

@jonathanmuth
Copy link
Contributor

@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.

@AhoyLemon
Copy link
Author

AhoyLemon commented Apr 12, 2021

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.

@squareclouds
Copy link

squareclouds commented Jul 2, 2021

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

@rootman
Copy link
Contributor

rootman commented Jul 29, 2021

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 :)

@MaluNoPeleke
Copy link

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
Copy link

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.

@jonaskuske
Copy link

jonaskuske commented Jul 27, 2022

@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);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

7 participants