Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Jan 10, 2018
1 parent 7f8f5f2 commit f31db82
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 293 deletions.
56 changes: 28 additions & 28 deletions examples/using-faker/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,38 @@ import Link from "gatsby-link"
import "./index.css"

const IndexPage = ({ data }) => (
<div>
<div className="page-grid">
<div className="address-section">
<h4>Address</h4>
<div>{data.personalData.address.streetAddress}</div>
<div>{data.personalData.address.streetName}</div>
<div>{data.personalData.address.city}</div>
<div>
{data.personalData.address.state} -
{data.personalData.address.zipCode}
</div>
</div>
<div className="email-section">
{data.personalData.internet.email} /
{data.personalData.phone.phoneNumber}
</div>
<div className="summary-section">
<h4> Summary</h4>
{data.personalData.lorem.paragraph}
<div>
<div className="page-grid">
<div className="address-section">
<h4>Address</h4>
<div>{data.personalData.address.streetAddress}</div>
<div>{data.personalData.address.streetName}</div>
<div>{data.personalData.address.city}</div>
<div>
{data.personalData.address.state} -
{data.personalData.address.zipCode}
</div>
</div>
<div className="company-section">
<h3>Worked at</h3>
{data.allCompanyData.edges.map(({ node }) => (
<div>
<div>{node.company.companyName}</div>
<div>{node.company.companySuffix}</div>
</div>
))}
<div className="email-section">
{data.personalData.internet.email} /
{data.personalData.phone.phoneNumber}
</div>
<div className="summary-section">
<h4> Summary</h4>
{data.personalData.lorem.paragraph}
</div>
</div>
)
<div className="company-section">
<h3>Worked at</h3>
{data.allCompanyData.edges.map(({ node }) => (
<div>
<div>{node.company.companyName}</div>
<div>{node.company.companySuffix}</div>
</div>
))}
</div>
</div>
)

export default IndexPage

Expand Down
24 changes: 12 additions & 12 deletions examples/using-remark/src/pages/2017-11-14---excerpts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ tags:

```graphql
{
allMarkdownRemark {
edges {
node {
excerpt(pruneLength:280)
}
}
}
allMarkdownRemark {
edges {
node {
excerpt(pruneLength: 280)
}
}
}
}
```

You can also manually mark in your markdown where to stop excerpting—similar to Jekyl. `gatsby-transformer-remark` uses [gray-matter]() to parse markdown frontmatter, so you can specify an excerpt_separator, as well as any of the other options mentioned [here](), in the `gatsby-config.js` file.

```json
{
resolve: `gatsby-transformer-remark`,
options: {
excerpt_separator: `<!-- end -->`
}
resolve: `gatsby-transformer-remark`,
options: {
excerpt_separator: `<!-- end -->`
}
}
```

Any file that does not have the given excerpt_separator will fall back to the default pruning method.

You can see the results [here](/excerpt-example)
You can see the results [here](/excerpt-example)
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ You can manually mark in your markdown where to stop excerpting—similar to Jek

```json
{
resolve: `gatsby-transformer-remark`,
options: {
excerpt_separator: `<!-- end -->`
}
resolve: `gatsby-transformer-remark`,
options: {
excerpt_separator: `<!-- end -->`
}
}
```

Any file that does not have the given excerpt_separator will fall back to the default pruning method.
Any file that does not have the given excerpt_separator will fall back to the default pruning method.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ draft: false
example: true
author: Daisy Buchanan
---

This example uses the default pruning method.

`gatsby-transformer-remark` allows you to get an excerpt from a markdown post. By default, it will prune the first 140 characters, but you can optionally specify a `pruneLength` in the graphql query.

```graphql
{
allMarkdownRemark {
edges {
node {
excerpt(pruneLength:280)
}
}
}
allMarkdownRemark {
edges {
node {
excerpt(pruneLength: 280)
}
}
}
}
```
```
13 changes: 5 additions & 8 deletions examples/using-remark/src/pages/excerpt-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class Index extends React.Component {
marginBottom: rhythm(2),
}}
>
This page demonstrates the different types of excerpts you can use with gatsby-transformer-remark
This page demonstrates the different types of excerpts you can use
with gatsby-transformer-remark
</h1>
<ul
css={{
Expand All @@ -45,9 +46,7 @@ class Index extends React.Component {
<Link to={post.node.fields.slug} className="link-underline">
{post.node.frontmatter.title}
</Link>
<p>
{post.node.excerpt}
</p>
<p>{post.node.excerpt}</p>
</li>
))}
</ul>
Expand All @@ -61,9 +60,7 @@ export default Index

export const pageQuery = graphql`
query ExcerptExampleQuery {
allMarkdownRemark(
filter: { frontmatter: { example: { eq: true } } }
) {
allMarkdownRemark(filter: { frontmatter: { example: { eq: true } } }) {
edges {
node {
fields {
Expand All @@ -77,4 +74,4 @@ export const pageQuery = graphql`
}
}
}
`
`
7 changes: 1 addition & 6 deletions examples/using-remark/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ export const pageQuery = graphql`
allMarkdownRemark(
limit: 2000
sort: { fields: [frontmatter___date], order: DESC }
filter: {
frontmatter: {
draft: { ne: true }
example: { ne: true }
}
}
filter: { frontmatter: { draft: { ne: true }, example: { ne: true } } }
) {
edges {
node {
Expand Down
7 changes: 1 addition & 6 deletions examples/using-remark/src/pages/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ export const pageQuery = graphql`
}
allMarkdownRemark(
limit: 2000
filter: {
frontmatter: {
draft: { ne: true }
example: { ne: true }
}
}
filter: { frontmatter: { draft: { ne: true }, example: { ne: true } } }
) {
group(field: frontmatter___tags) {
fieldValue
Expand Down
138 changes: 69 additions & 69 deletions packages/gatsby-transformer-remark/src/__tests__/extend-node.js
Original file line number Diff line number Diff line change
@@ -1,100 +1,100 @@
const _ = require(`lodash`)
const {
graphql,
GraphQLObjectType,
GraphQLList,
GraphQLSchema,
} = require(`graphql`)
graphql,
GraphQLObjectType,
GraphQLList,
GraphQLSchema,
} = require(`graphql`)
const { onCreateNode } = require(`../gatsby-node`)
const { inferObjectStructureFromNodes } = require(`../../../gatsby/src/schema/infer-graphql-type`)
const {
inferObjectStructureFromNodes,
} = require(`../../../gatsby/src/schema/infer-graphql-type`)

// given a set of nodes and a query, return the result of the query
async function queryResult(nodes, fragment, { types = [] } = {}) {
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: `RootQueryType`,
fields: () => {
return {
listNode: {
name: `LISTNODE`,
type: new GraphQLList(
new GraphQLObjectType({
name: `MarkdownRemark`,
fields: inferObjectStructureFromNodes({
nodes,
types: [...types],
}),
})
),
resolve() {
return nodes
},
},
}
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: `RootQueryType`,
fields: () => {
return {
listNode: {
name: `LISTNODE`,
type: new GraphQLList(
new GraphQLObjectType({
name: `MarkdownRemark`,
fields: inferObjectStructureFromNodes({
nodes,
types: [...types],
}),
})
),
resolve() {
return nodes
},
}),
})
},
}
},
}),
})

const result = await graphql(
schema,
`query {
const result = await graphql(
schema,
`query {
listNode {
${fragment}
}
}
`,
)
return result
`
)
return result
}

describe(`Excerpt is generated correctly from schema`, () => {

const node = {
id: `whatever`,
children: [],
internal: {
contentDigest: `whatever`,
mediaType: `text/markdown`,
},
}

// Make some fake functions its expecting.
const loadNodeContent = node => Promise.resolve(node.content)
const node = {
id: `whatever`,
children: [],
internal: {
contentDigest: `whatever`,
mediaType: `text/markdown`,
},
}

// Make some fake functions its expecting.
const loadNodeContent = node => Promise.resolve(node.content)


it(`correctly loads a default excerpt`, async () => {
const content = `---
it(`correctly loads a default excerpt`, async () => {
const content = `---
title: "my little pony"
date: "2017-09-18T23:19:51.246Z"
---
Where oh where is my little pony?
`

node.content = content

const createNode = markdownNode => {
queryResult([ markdownNode ],
`
node.content = content

const createNode = markdownNode => {
queryResult(
[markdownNode],
`
excerpt
frontmatter {
title
}
`,
{
types: [ { name: `MarkdownRemark` } ],
}).then(result => {
expect(_.isString(result.data.listNode.excerpt))
})
{
types: [{ name: `MarkdownRemark` }],
}
const createParentChildLink = jest.fn()
const boundActionCreators = { createNode, createParentChildLink }
).then(result => {
expect(_.isString(result.data.listNode.excerpt))
})
}
const createParentChildLink = jest.fn()
const boundActionCreators = { createNode, createParentChildLink }

await onCreateNode({
node,
loadNodeContent,
boundActionCreators,
})
await onCreateNode({
node,
loadNodeContent,
boundActionCreators,
})

})
})
Loading

0 comments on commit f31db82

Please sign in to comment.