Repository navigation
WIP: added q.contentBlocks utility - #375
scottrippey wants to merge 15 commits into
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
q.contentBlocks utilityq.contentBlocks utility
|
@scottrippey Hey mate, just wanted to say this would be a great feature to have in the package! Thanks for your hard work. |
|
@Rhym I don't currently have the resources to work on this PR, but I'd be happy to accept contributions if you're able. |
|
Thanks for the reply, @scottrippey . I fully understand. If possible, I just have one issue left with my migration. I can't for the life of me figure out how to split the content here into a fragment for reuse. I have tried so many different ways, and it just doesn't like it: import { runQuery } from "@/lib/sanity";
import { q, type InferFragmentType } from "./groqd-client";
import { linkExternalFragment } from "./fragments/link-external";
import { linkInternalFragment } from "./fragments/link-internal";
const fragment = q.fragmentForType<"contactPage">().project((sub) => ({
title: true,
ogTitle: true,
ogDescription: true,
content: sub.field("content[]").project((contentSub) => ({
"...": true,
markDefs: contentSub.field("markDefs[]").project((markDefsSub) => ({
"...": true,
...markDefsSub.conditionalByType({
"annotation.link": {
_type: true,
_key: true,
links: markDefsSub
.field("links[]")
.project((linksSub) => ({
...linksSub.conditionalByType({
linkInternal: linkInternalFragment,
linkExternal: linkExternalFragment,
}),
}))
.slice(0),
},
}),
})),
})),
}));
export type SanityContactPage = InferFragmentType<typeof fragment>;
export const getContactPageQuery = () =>
runQuery(q.star.filterByType("contactPage").slice(0).project(fragment), {}); |
aa2c3df to
4cd85f2
Compare
…stom block array. Add tests for both.
…tead of assuming the parser is for the objects in the array
…n inferring type, and also the q.contentBlock helper should be able to be used with an ellipsis property
… the output of that parser in the output type.
| : TProjectionMap extends { "...": Parser } | ||
| ? InferParserOutput<TProjectionMap["..."]> |
There was a problem hiding this comment.
This allows ellipsis parsers to return their type instead of being skipped. It's because Parser<TResultItem, infer TOutput> is too specific and gets skipped.
Feature:
q.customBlock()andq.customBlocks()Bug fixes:
fieldmethod will parse the array instead of objects on the array."..."projection, that parser's type will now be in the result, instead of ignored.