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

feat: add more comprehensive preview implementation #59

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

jonaskuske
Copy link

@jonaskuske jonaskuske commented Jul 27, 2022

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)

@jonaskuske jonaskuske changed the title feat: add more comprehensive preview implementation Draft: feat: add more comprehensive preview implementation Jul 29, 2022
@jonaskuske jonaskuske changed the title Draft: feat: add more comprehensive preview implementation feat: add more comprehensive preview implementation Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant