After declaring default images/descriptions for SEO snippets using Page Models as described in #58, I noticed the preview snippets don't show these defaults. So I looked into that and found some more problems:
previews don't use site meta information as fallback
not all options are respected, e.g. pageTitleAsHomePageTitle in google_search_preview
preview thumbnails use the full image instead of the cropped ->thumb() used on the actual site
some unused code and data
This is a refactor of the way data is passed to the preview snippets fixing the above as well as making sure that Page Model overrides are reflected in the previews.
All data is now loaded from the server on load. When there are changes to the page fields in the panel, those are reflected immediately (using the reactive values from the store), but on save server data is re-fetched to ensure consistency.
Considerations:
Because the panel can't call methods on the page model and the server can't see unsaved changes (they only exist in the browser's localStorage), there's no single source of truth during edits and some incorrect previews are still possible – though only during live editing, re-fetching after saves makes sure the previews eventually show up in the correct way, no matter what.
If you select a new thumbnail in the panel, the preview will show the full image as the panel can't call ->thumb() like the backend can. After save, the cropped version is shown.
If a preview loads with a value stored in a field of the SEO tab, and you empty that field, the fallback defined on the Page Model doesn't show up in realtime. After saving, it appears.
The preview will always show the value from a changed field, even if the overridden method does not read the original field but always returns its own value (meta_description() { return $MY_TEXT; }). After save, $MY_TEXT shows up.
I think this approach is a good compromise given Kirby's current architecture.
(afaik there are plans to move dirty/changed state to server as well, which would allow fixing these inaccuracies in the future)
After declaring default images/descriptions for SEO snippets using Page Models as described in #58, I noticed the preview snippets don't show these defaults. So I looked into that and found some more problems:
pageTitleAsHomePageTitle
ingoogle_search_preview
->thumb()
used on the actual siteThis is a refactor of the way data is passed to the preview snippets fixing the above as well as making sure that Page Model overrides are reflected in the previews.
All data is now loaded from the server on load. When there are changes to the page fields in the panel, those are reflected immediately (using the reactive values from the store), but on save server data is re-fetched to ensure consistency.
Considerations:
Because the panel can't call methods on the page model and the server can't see unsaved changes (they only exist in the browser's
localStorage
), there's no single source of truth during edits and some incorrect previews are still possible – though only during live editing, re-fetching after saves makes sure the previews eventually show up in the correct way, no matter what.->thumb()
like the backend can. After save, the cropped version is shown.meta_description() { return $MY_TEXT; }
). After save,$MY_TEXT
shows up.I think this approach is a good compromise given Kirby's current architecture. (afaik there are plans to move dirty/changed state to server as well, which would allow fixing these inaccuracies in the future)