-
Notifications
You must be signed in to change notification settings - Fork 0
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
feature: preview links in CMS #233
base: main
Are you sure you want to change the base?
Conversation
This change contains 2 solutions: - an `/api/reroute/page` endpoint to find and redirect to the correct page url - a check in `pages/[locale]/[...path]/index.astro` that redirects to the canonical url if it doesn't match the current url
Deploying head-start with
|
Latest commit: |
a2391ec
|
Status: | ✅ Deploy successful! |
Preview URL: | https://bba16df6.head-start.pages.dev |
Branch Preview URL: | https://feat-preview-links.head-start.pages.dev |
}); | ||
}; | ||
|
||
export const GET: APIRoute = async ({ request }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a generic alternate approach that I used in the nododos-website. But I think the canonical url check in [locale]/[...path]/index.astro
is easier and probably the way to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm. I guess the canonical check works on localhost and preview as the generic page route is then always handled dynamically on the server. However the production environment has prerendered pages and will throw a 404 I suppose. So I guess we do need this reroute API handler.
In that case the config of the Preview field of the generic page will need to use that one instead.
const { locale } = Astro.params as { locale: SiteLocale }; | ||
const localeFromPath = Astro.params.locale as SiteLocale; | ||
const localeFromQuery = Astro.url.searchParams.get('locale') as SiteLocale; | ||
const locale = localeFromQuery || localeFromPath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now needed to have the Astro.rewrite('/404/')
work in [locale]/[...path]/index.astro
. It's the tradeoff for no longer needing to cast the response from the page query. Worth it? Or rather have that one fail as it did before?
const breadcrumbs = [...getParentPages(page), page].map((page) => | ||
const { page } = await datocmsRequest<PageQuery>({ query, variables }); | ||
|
||
if (!page) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check ensures this type casting is no longer needed:
as {
page: NonNullable<PageQuery['page']>; // Only NonNullable when statically generated. Handle as a 404 when this is a server route!
};
But it makes the 404
rewrite and locale setting in that file more complex. Worth it?
|
||
#### Model Deployments Links plugin | ||
|
||
The [Model Deployment Links plugin](https://www.datocms.com/marketplace/plugins/i/datocms-plugin-model-deployment-links) requires an API key: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this could also be achieved within a migration script using https://www.datocms.com/docs/content-management-api/resources/access-token/create . However it's difficult to reliably get the Editor role ID. Since this is a one time config step, I'm happy to have it as a manual step, rather than scripting the generation of access token.
To do
Changes
This change contains 2 solutions:
/api/reroute/page
endpoint to find and redirect to the correct page urlpages/[locale]/[...path]/index.astro
that redirects to the canonical url if it doesn't match the current urlAssociated issue
Part of #10
How to test
preview-links
environment (note: it's moved from personal to De Voorhoede organisation account, so we could add more sandbox environments)Checklist