Filter files based on parent dir
This commit is contained in:
parent
f8e2ba3177
commit
c064850324
|
@ -20,6 +20,20 @@ module.exports = {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
|
{
|
||||||
|
resolve: `gatsby-source-filesystem`,
|
||||||
|
options: {
|
||||||
|
name: `data`,
|
||||||
|
path: `${__dirname}/content/pages`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
resolve: `gatsby-transformer-remark`,
|
||||||
|
options: {
|
||||||
|
filter: node => node.sourceInstanceName === `data`,
|
||||||
|
type: `MarkdownPage`
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
resolve: `gatsby-source-filesystem`,
|
resolve: `gatsby-source-filesystem`,
|
||||||
options: {
|
options: {
|
||||||
|
@ -27,11 +41,12 @@ module.exports = {
|
||||||
path: `${__dirname}/content/posts/`,
|
path: `${__dirname}/content/posts/`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
`gatsby-plugin-react-helmet`,
|
|
||||||
{
|
{
|
||||||
resolve: `gatsby-transformer-remark`,
|
resolve: `gatsby-transformer-remark`,
|
||||||
options: {
|
options: {
|
||||||
excerpt_separator: `<!-- end -->`
|
filter: node => node.sourceInstanceName === `pages`,
|
||||||
|
excerpt_separator: `<!-- end -->`,
|
||||||
|
type: `BlogPost`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -43,6 +58,7 @@ module.exports = {
|
||||||
},
|
},
|
||||||
`gatsby-transformer-sharp`,
|
`gatsby-transformer-sharp`,
|
||||||
`gatsby-plugin-sharp`,
|
`gatsby-plugin-sharp`,
|
||||||
|
`gatsby-plugin-react-helmet`,
|
||||||
{
|
{
|
||||||
resolve: `gatsby-plugin-manifest`,
|
resolve: `gatsby-plugin-manifest`,
|
||||||
options: {
|
options: {
|
||||||
|
|
|
@ -5,11 +5,17 @@ exports.onCreateNode = ({ node, getNode, actions }) => {
|
||||||
const { createNodeField } = actions
|
const { createNodeField } = actions
|
||||||
if (node.internal.type === `MarkdownRemark`) {
|
if (node.internal.type === `MarkdownRemark`) {
|
||||||
const slug = createFilePath({ node, getNode, basePath: `pages` })
|
const slug = createFilePath({ node, getNode, basePath: `pages` })
|
||||||
|
const parent = getNode(node.parent)
|
||||||
createNodeField({
|
createNodeField({
|
||||||
node,
|
node,
|
||||||
name: `slug`,
|
name: `slug`,
|
||||||
value: slug,
|
value: slug,
|
||||||
})
|
})
|
||||||
|
createNodeField({
|
||||||
|
node,
|
||||||
|
name: 'collection',
|
||||||
|
value: parent.sourceInstanceName,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +25,7 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
|
||||||
const result = await graphql(
|
const result = await graphql(
|
||||||
`
|
`
|
||||||
{
|
{
|
||||||
allMarkdownRemark(filter: {frontmatter: {draft: {ne: true}}}) {
|
allMarkdownRemark(filter:{frontmatter: {draft: {ne: true}}, fields: {collection: {eq: "posts"}}}) {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
fields {
|
fields {
|
||||||
|
@ -41,7 +47,6 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
|
||||||
// Create pages for each markdown file.
|
// Create pages for each markdown file.
|
||||||
const blogPostTemplate = path.resolve(`src/templates/blog-post.js`)
|
const blogPostTemplate = path.resolve(`src/templates/blog-post.js`)
|
||||||
result.data.allMarkdownRemark.edges.forEach(({ node }) => {
|
result.data.allMarkdownRemark.edges.forEach(({ node }) => {
|
||||||
console.log(node);
|
|
||||||
createPage({
|
createPage({
|
||||||
path: `/posts${node.fields.slug}`,
|
path: `/posts${node.fields.slug}`,
|
||||||
component: blogPostTemplate,
|
component: blogPostTemplate,
|
||||||
|
|
|
@ -12,7 +12,7 @@ const IndexPage = () => {
|
||||||
query {
|
query {
|
||||||
allMarkdownRemark(
|
allMarkdownRemark(
|
||||||
sort: { order: DESC, fields: [frontmatter___date] }
|
sort: { order: DESC, fields: [frontmatter___date] }
|
||||||
filter: {frontmatter: {draft: {ne: true}}}
|
filter: {frontmatter: {draft: {ne: true}}, fields: {collection: {eq: "posts"}}}
|
||||||
) {
|
) {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
|
|
Loading…
Reference in New Issue