1
1
const path = require ( `path` )
2
- const { createFilePath } = require ( `gatsby-source-filesystem` )
3
2
4
3
exports . createPages = async ( { graphql, actions, reporter } ) => {
5
4
const { createPage } = actions
@@ -8,90 +7,73 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
8
7
const verticalArticle = path . resolve ( `./src/templates/vertical-article.tsx` )
9
8
const horizontalArticle = path . resolve ( `./src/templates/horizontal-article.tsx` )
10
9
11
- const resultAllMarkdowns = await graphql (
10
+ const resultContentfulMarkdowns = await graphql (
12
11
`
13
12
{
14
- allMarkdownRemark(
15
- filter: { fields: { draft: { eq: false } } }
16
- sort: { fields: [frontmatter___publishedAt], order: DESC }
17
- limit: 1000
18
- ) {
19
- nodes {
20
- id
21
- frontmatter {
22
- vol
23
- writing
24
- }
25
- fields {
13
+ allContentfulMarkdownArticle(sort: {fields: publishedAt, order: DESC}) {
14
+ edges {
15
+ node {
16
+ id
26
17
slug
18
+ isVirticalWriting
19
+ publishedAt
20
+ }
21
+ next {
22
+ id
23
+ }
24
+ previous {
25
+ id
27
26
}
28
27
}
29
28
}
30
29
}
31
30
`
32
31
)
33
32
34
- if ( resultAllMarkdowns . errors ) {
33
+ if ( resultContentfulMarkdowns . errors ) {
35
34
reporter . panicOnBuild (
36
35
`There was an error loading your article posts` ,
37
- resultAllMarkdowns . errors
36
+ resultContentfulMarkdowns . errors
38
37
)
39
38
return
40
39
}
41
40
42
- const posts = resultAllMarkdowns . data . allMarkdownRemark . nodes
41
+ const posts = resultContentfulMarkdowns . data . allContentfulMarkdownArticle . edges
43
42
44
43
// Create blog posts pages
45
44
// But only if there's at least one markdown file found at "content/blog" (defined in gatsby-config.js)
46
45
// `context` is available in the template as a prop and as a variable in GraphQL
47
46
48
47
if ( posts . length > 0 ) {
49
48
posts . forEach ( ( post , index ) => {
50
- const previousPostId = index === 0 ? null : posts [ index - 1 ] . id
51
- const nextPostId = index === posts . length - 1 ? null : posts [ index + 1 ] . id
52
-
53
- const { slug } = post . fields
49
+ const { slug } = post . node
54
50
if ( ! slug ) return
55
51
56
- if ( post . frontmatter . writing === "horizontal" ) {
52
+ if ( post . node . isVirticalWriting === true ) {
57
53
createPage ( {
58
- path : `/articles${ slug } ` ,
59
- component : horizontalArticle ,
54
+ path : `/articles/ ${ slug } / ` ,
55
+ component : verticalArticle ,
60
56
context : {
61
- id : post . id ,
62
- previousPostId,
63
- nextPostId,
57
+ id : post . node . id ,
58
+ previousPostId : post . previous ? post . previous . id : null ,
59
+ nextPostId : post . next ? post . next . id : null ,
64
60
} ,
65
61
} )
66
- } else if ( post . frontmatter . writing === "vertical" ) {
62
+ } else {
67
63
createPage ( {
68
- path : `/articles${ slug } ` ,
69
- component : verticalArticle ,
64
+ path : `/articles/ ${ slug } / ` ,
65
+ component : horizontalArticle ,
70
66
context : {
71
- id : post . id ,
72
- previousPostId,
73
- nextPostId,
67
+ id : post . node . id ,
68
+ previousPostId : post . previous ? post . previous . id : null ,
69
+ nextPostId : post . next ? post . next . id : null ,
74
70
} ,
75
71
} )
76
72
}
77
73
} )
78
74
}
79
75
}
80
76
81
- exports . onCreateNode = ( { node, actions, getNode } ) => {
82
- const { createNodeField } = actions
83
-
84
- if ( node . internal . type === `MarkdownRemark` ) {
85
- const value = createFilePath ( { node, getNode } )
86
-
87
- createNodeField ( {
88
- name : `slug` ,
89
- node,
90
- value,
91
- } )
92
- }
93
- }
94
-
95
77
exports . createSchemaCustomization = ( { actions } ) => {
96
78
const { createTypes } = actions
97
79
@@ -103,48 +85,7 @@ exports.createSchemaCustomization = ({ actions }) => {
103
85
// article posts are stored inside "content/article" instead of returning an error
104
86
createTypes ( `
105
87
type SiteSiteMetadata {
106
- author: Author
107
88
siteUrl: String
108
- social: Social
109
- }
110
-
111
- type Author {
112
- name: String
113
- summary: String
114
- }
115
-
116
- type Social {
117
- twitter: String
118
- }
119
-
120
- type MarkdownRemark implements Node @infer {
121
- frontmatter: Frontmatter
122
- fields: Fields
123
- }
124
-
125
- type Frontmatter @infer {
126
- title: String
127
- description: String
128
- author: String
129
- vol: String
130
- align: String
131
- writing: String
132
- profile: String
133
- twitter: String
134
- instagram: String
135
- minnakikeru: String
136
- bandcamp: String
137
- linktree: String
138
- hatena: String
139
- createdAt: Date @dateformat
140
- updatedAt: Date @dateformat
141
- publishedAt: Date @dateformat
142
- disableSideHeader: Boolean
143
- featuredImage: File
144
- }
145
-
146
- type Fields {
147
- slug: String
148
89
}
149
90
` )
150
91
}
0 commit comments