Comments (5)
Can you give an example of a post
and snippet
frontMatter so we can determine the relationship?
Thank you
from next-mdx.
post.md:
---
title: Post
---
snippet.md:
---
title: Snippet
belongsToPost: post
---
from next-mdx.
OK. Let me see. I'll try to put together a quick example.
from next-mdx.
OK I created an example here:
Demo: https://next-mdx-post-snippet.vercel.app
Repo: https://github.com/arshad/next-mdx-post-snippet
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 post
export 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
from next-mdx.
OK so as I suspected I would need to do the filtering myself. Thanks either way :)
from next-mdx.
Related Issues (9)
- Add support for next-mdx.config.js HOT 1
- Render inlineCode and code HOT 2
- Handling Next localization with next.config.js HOT 1
- Add reading time, word count HOT 2
- Multiple slugs for the same document
- Error with datetime in frontmatter: object` ("[object Date]") cannot be serialized as JSON HOT 1
- getMdxNode's context type is incompatible with nextjs's HOT 2
- rendering images in mdx posts HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next-mdx.