[gatsby-theme-minimal-blog] shadowing additional frontmatter #829
Replies: 2 comments
-
Exactly what I needed; thanks to you, I found how to add the I tried to edit the parent file and was able to receive the author. Currently, I am trying to work with StaticQuery but was not yet successful. I will try tomorrow a bit more. I will keep you posted if I find a good solution. |
Beta Was this translation helpful? Give feedback.
-
I figured out how to do this via #438 (comment). There's no modification required to gatsby-node at all - you can just inject a field into the frontmatter and query for it via GQL. Here's what I did: Shadow the homepage query to include mdx frontmatter ( <truncated>
nodes {
<truncated>
description
tags {
name
slug
}
+ ... on MdxPost {
+ parent {
+ ... on Mdx {
+ frontmatter {
+ $YOUR_FIELD
+ }
+ }
+ }
+ }
}
<truncated> This makes it available in the export type MBHomepageProps = {
posts: {
slug: string
title: string
date: string
excerpt: string
description: string
timeToRead?: number
tags?: {
name: string
slug: string
}[]
+ parent: {
+ frontmatter: {
+ [key: string]: any
+ }
+ }
}[]
} You can then access your custom field via I used this to add a This is an old discussion, but I hope it helps someone stumbling here by Google :-) |
Beta Was this translation helpful? Give feedback.
-
@LekoArts shared a concise solution for adding frontmatter to a Post. Following that approach, I was able to add a new frontmatter field that is showing up in interactive queries (see my modified
gatsby-node.js
below).Unfortunately, I'm still unable to access the new field when shadowing.
Assuming one wanted to access this new
author
field inblog-list-item.tsx
, for example, what changes would be necessary? I tried the following unsuccessfully:I thought perhaps I needed to also shadow
@lekoarts/gatsby-theme-minimal-blog-core/src/templates/blog-query.tsx
, but that didn't seem to work either. In fact, that gives me a warning:Beta Was this translation helpful? Give feedback.
All reactions