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

[www] Add PostLink component example to docs/adding-a-list-of-markdown-blog-posts/ #3887

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions docs/docs/adding-a-list-of-markdown-blog-posts.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default IndexPage;

### Creating the GraphQL query

The only thing left to do is to provide the data to your component with a GraphQL query.
Second, you need to provide the data to your component with a GraphQL query. Let's add it, so that `index.js` looks like this:

```js
import React from "react";
Expand Down Expand Up @@ -74,4 +74,23 @@ export const pageQuery = graphql`
`;
```

This should get you a page with your posts sorted by descending date. You can further customise the `frontmatter` and the page component to get desired effects!
### Creating the `PostLink` component

The only thing left to do is to add the `PostLink` component. Create a new file `post-link.js` in `src/components/` and add the following:

```js
import React from "react";
import Link from "gatsby-link";

const PostLink = ({ post }) => (
<div>
<Link to={post.frontmatter.path}>
{post.frontmatter.title} ({post.frontmatter.date})
</Link>
</div>
);

export default PostLink;
```

This should get you a page with your posts sorted by descending date. You can further customise the `frontmatter` and the page and `PostLink` components to get desired effects!
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick, since you asked for an English review: "get desired effects" should be "get your desired effects" or "get the desired effects".

Other than regionally variant spellings like "customise"/"customize" (where I don't know your style guide so can't comment), everything else looks good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Thank you!