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

Fix issue where we get 'Unable to resolve image' if the user does not… #18

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions astro/src/pages/blog/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ export async function getStaticPaths() {

const { post } = Astro.props;

const resolvedImage = post.mainImage
? getSanityImageURL(post.mainImage).width(1200).url()
: null;

const seo = {
title: post.title,
description: post.description,
image: getSanityImageURL(post.mainImage).width(1200).url(),
}
image: resolvedImage,
};
---

<Layout seo={seo}>
Expand Down
1 change: 1 addition & 0 deletions sanity/schemas/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default {
name: 'publishedAt',
title: 'Published at',
type: 'datetime',
validation: Rule => Rule.required(),
Copy link
Contributor Author

@roblevintennis roblevintennis Oct 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based this off of the initialValue templates docs: https://www.sanity.io/docs/initial-value-templates#dec5ffddbcc2 which shows how to prefill such fields

},
{
name: 'excerpt',
Expand Down