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

Gatsby theme blog core #16166

Merged

Conversation

ChristopherBiscardi
Copy link
Contributor

@ChristopherBiscardi ChristopherBiscardi commented Jul 28, 2019

cc/ @NickyMeuleman

Create gatsby-theme-blog-core

This PR creates a parent theme called gatsby-theme-blog-core which is then used as the parent of gatsby-theme-blog.

gatsby-theme-blog-core

The core theme is a theme meant to encourage re-use of the BlogPost core type to build an ecosystem of compatible blog themes on the same base. The BlogPost interface itself enables people to create backing implementations from any node type in the Gatsby ecosystem, leading us one step further down the path to supporting any CMS. The core theme implements this approach for Mdx nodes sourced from the included filesystem source. More info on the ability to source from multiple node types here.

The theme:

  • contains all data structures, sources, and processing
  • Contains page creation (createPage calls) with templates that render JSON.stringify(props.data, null, 2)

gatsby-theme-blog

gatsby-theme-blog becomes effectively a collection of components used to render a Gatsby site. This allows anyone to do the same by shadowing two components from the core theme (src/gatsby-theme-blog-core/components/posts.js and src/gatsby-theme-blog-core/components/post.js).

  • removed gatsby-node.js as it no longer does anything
  • shadowed gatsby-theme-blog-core components to implement theme-ui, etc based layouts

@NickyMeuleman
Copy link
Contributor

NickyMeuleman commented Jul 28, 2019

Thanks for tagging me to this PR!

I read your comment on pagination in the other thread.
How do you feel about it being an option to include (default is no pagination)?

I did this in my themejam submission, the relevant section in gatsby-node:
https://github.com/NickyMeuleman/gatsby-theme-nicky-blog/blob/d37c8f35c2dbde1365edcce001e926fc3005ccdb/theme/gatsby-node.js#L188-L224


Also on that site, I'm transforming the tags array in the frontmatter of a post to an array of objects in graphQL that have this form { name: String, slug: String }. That worked surprisingly well, ability to query both fields.
Unfortunately, for the page that groups all tags. I couldn't figure out how to query a group of them AND access both fields in graphQL:

query MyQuery {
  allBlogPost {
    group(field: tags) {
      fieldValue {
        name
        slug
      }
    }
  }
}

errors out, as the fieldValue alone returns a string: "object Object"
(as a dirty fix, I resorted to passing that info via the pageContext, instead of querying for the data in a page/component)

@ChristopherBiscardi
Copy link
Contributor Author

@NickyMeuleman

Thanks for tagging me to this PR!

🎉

I read your comment on pagination in the other thread.
How do you feel about it being an option to include (default is no pagination)?

I don't like including it by default. I think we should include it as an extension to the data model in some way. I don't know exactly what that looks like yet, but it means we won't have to support n* features in -core if we can pull off "data extension" like this.

(personally I don't think pagination is useful, especially for the amount of content the "average" blogger puts out and the purpose of having a page listing. Why make it harder for people to CMD+F through your list of posts? ...but this is a different discussion than the data one above).

Unfortunately, for the page that groups all tags. I couldn't figure out how to query a group of them AND access both fields in graphQL:

I generally avoid nested fields unless it's an additional type. I think in -core we'll solve this problem using a Tag extension that can be used across other interfaces (BlogPost, Note, etc). Then you'd be able to do this if you wanted a list of all tags and such:

query MyQuery {
  allTag {
    name
    slug
  }
}

@ChristopherBiscardi
Copy link
Contributor Author

Implemented BlogPost as an Interface in the last commit. Nothing had to change in gatsby-theme-blog

@ChristopherBiscardi ChristopherBiscardi marked this pull request as ready for review August 2, 2019 22:34
@ChristopherBiscardi ChristopherBiscardi requested a review from a team as a code owner August 2, 2019 22:34
@KyleAMathews
Copy link
Contributor

👍 to post-query.js

tags: [String]!
keywords: [String]!
excerpt: String!
body: String!
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicated body field

Suggested change
body: String!

title: String!
body: String!
slug: String!
date: Date! @dateformat(formatString: "DD-MM-YYYY")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
date: Date! @dateformat(formatString: "DD-MM-YYYY")
date: Date! @dateformat

Or, if we want a default format string, we should have it on MdxBlogPost as well

jxnblk
jxnblk previously approved these changes Aug 5, 2019

```sh
# create a new Gatsby site using the blog theme starter
gatsby new my-themed-blog https://github.com/gatsbyjs/gatsby-starter-blog-theme
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be referencing gatsby-starter-blog-theme-core in this README?

Suggested change
gatsby new my-themed-blog https://github.com/gatsbyjs/gatsby-starter-blog-theme
gatsby new my-themed-blog https://github.com/gatsbyjs/gatsby-starter-blog-theme-core

themes/gatsby-theme-blog/gatsby-config.js Show resolved Hide resolved
@ChristopherBiscardi
Copy link
Contributor Author

Rebased and made all suggested changes. This should be good to go.

Copy link
Contributor

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

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

Looking great!

id
excerpt
slug
title
Copy link
Contributor

Choose a reason for hiding this comment

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

title, date, excerpt aren't used anymore right?

johno
johno previously approved these changes Aug 13, 2019
Copy link
Contributor

@johno johno left a comment

Choose a reason for hiding this comment

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

🏗 😻

Co-Authored-By: John Otander <johnotander@gmail.com>
@ChristopherBiscardi ChristopherBiscardi merged commit c222872 into gatsbyjs:master Aug 13, 2019
LekoArts added a commit to LekoArts/gatsby-themes that referenced this pull request Aug 23, 2019
Basically the same process as:
gatsbyjs/gatsby#16166

> A Gatsby theme for creating a blog child theme. It includes all of the data structures you need to get up and running building a blog and includes no additional theming or style opinions.

Just for the Emma theme. Which means:

You can totally customize the design now, but keep the data structure. So awesome <3
As the Theme UI styling for example happens in `emma`, not `emma-core`.
anteroselin added a commit to anteroselin/gatsby-theme that referenced this pull request Mar 6, 2023
Basically the same process as:
gatsbyjs/gatsby#16166

> A Gatsby theme for creating a blog child theme. It includes all of the data structures you need to get up and running building a blog and includes no additional theming or style opinions.

Just for the Emma theme. Which means:

You can totally customize the design now, but keep the data structure. So awesome <3
As the Theme UI styling for example happens in `emma`, not `emma-core`.
infinitesky4444 added a commit to infinitesky4444/gatsby that referenced this pull request Jun 27, 2023
Basically the same process as:
gatsbyjs/gatsby#16166

> A Gatsby theme for creating a blog child theme. It includes all of the data structures you need to get up and running building a blog and includes no additional theming or style opinions.

Just for the Emma theme. Which means:

You can totally customize the design now, but keep the data structure. So awesome <3
As the Theme UI styling for example happens in `emma`, not `emma-core`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants