This repository has been archived by the owner on Feb 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Filtering documents by relationship #6
Comments
Can you give an example of a Thank you |
post.md:
snippet.md:
|
OK. Let me see. I'll try to put together a quick example. |
OK I created an example here: Demo: https://next-mdx-post-snippet.vercel.app Here are some key parts: Define your MDX types{
"post": {
"contentPath": "content/posts",
"basePath": "/blog"
},
"snippet": {
"contentPath": "content/snippets"
}
} Set the post in the snippet---
title: Hello World
post: <------- This must match the key we used above in next-mdx.json
- first-post <-----------------
---
```jsx
export function HelloWorld() {
return <p>Hello World</p>
} Get the snippets for a postexport async function getStaticProps(context) {
const post = await getMdxNode("post", context)
if (!post) {
return {
notFound: true,
}
}
const snippets = await getAllMdxNodes("snippet")
return {
props: {
post,
snippets: snippets.filter((snippet) =>
snippet.relationships.post.some(({ slug }) => slug === post.slug)
),
},
}
} Hope this helps |
OK so as I suspected I would need to do the filtering myself. Thanks either way :) |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I have two types of nodes: Post and Snippet. I would like a Post to be composed of multiple snippets (which Snippet it belongs to is defined in the Snipper's front matter), while retaining the ability to refer to a Snippet on its own.
Is it possible to call
getAll*Nodes('snippet')
from the Post document and only have it return the Snippets that belong to the post?The text was updated successfully, but these errors were encountered: