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 all 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
27 changes: 23 additions & 4 deletions docs/docs/adding-a-list-of-markdown-blog-posts.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Has anyone heard about GatsbyJS yet?

The first step will be to create the page which will display your posts, in `src/pages/`. You can for example use `index.js`.

```js
```jsx
import React from "react";
import PostLink from "../components/post-link";

Expand All @@ -39,9 +39,9 @@ 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
```jsx
import React from "react";
import PostLink from "../components/post-link";

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:

```jsx
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 your 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.

this is technically correct. Another, more streamlined way to write this sentence is "You can further customize the frontmatter, page, and PostLink components to get your 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.

Is the page a component? If so, the existing wording is better.