feat: add more comprehensive preview implementation #59
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)