2018-11-18 23:52:57 +01:00
|
|
|
const { createMarkdownFields } = require('./gatsby/createMarkdownFields')
|
|
|
|
const { createExifFields } = require('./gatsby/createExifFields')
|
2018-10-14 02:25:24 +02:00
|
|
|
const {
|
|
|
|
generatePostPages,
|
|
|
|
generateTagPages,
|
|
|
|
generateRedirectPages
|
|
|
|
} = require('./gatsby/createPages')
|
2018-09-30 03:11:08 +02:00
|
|
|
const { itemsPerPage } = require('./config')
|
2018-09-06 22:28:28 +02:00
|
|
|
|
2018-07-17 23:33:55 +02:00
|
|
|
exports.onCreateNode = ({ node, actions, getNode }) => {
|
|
|
|
const { createNodeField } = actions
|
|
|
|
|
2018-09-13 00:46:40 +02:00
|
|
|
// Markdown files
|
2018-07-17 23:33:55 +02:00
|
|
|
if (node.internal.type === 'MarkdownRemark') {
|
2018-10-14 02:25:24 +02:00
|
|
|
createMarkdownFields(node, createNodeField, getNode)
|
2018-09-13 00:46:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Image files
|
|
|
|
if (node.internal.mediaType === 'image/jpeg') {
|
2018-10-14 02:25:24 +02:00
|
|
|
createExifFields(node, createNodeField)
|
2018-09-12 21:03:35 +02:00
|
|
|
}
|
2018-09-09 21:20:19 +02:00
|
|
|
}
|
|
|
|
|
2018-07-17 23:33:55 +02:00
|
|
|
exports.createPages = ({ graphql, actions }) => {
|
2018-09-24 23:50:48 +02:00
|
|
|
const { createPage, createRedirect } = actions
|
2018-07-17 23:33:55 +02:00
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
resolve(
|
|
|
|
graphql(
|
|
|
|
`
|
|
|
|
{
|
2018-08-30 22:50:09 +02:00
|
|
|
allMarkdownRemark(sort: { fields: [fields___date], order: DESC }) {
|
2018-07-17 23:33:55 +02:00
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
fields {
|
|
|
|
slug
|
2018-07-19 00:22:06 +02:00
|
|
|
date
|
2018-07-17 23:33:55 +02:00
|
|
|
}
|
2018-07-19 23:04:41 +02:00
|
|
|
frontmatter {
|
2018-08-30 22:50:09 +02:00
|
|
|
type
|
2018-07-19 23:04:41 +02:00
|
|
|
tags
|
|
|
|
}
|
2018-07-17 23:33:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
).then(result => {
|
|
|
|
if (result.errors) {
|
|
|
|
/* eslint no-console: "off" */
|
|
|
|
console.log(result.errors)
|
|
|
|
reject(result.errors)
|
|
|
|
}
|
|
|
|
|
2018-07-19 00:22:06 +02:00
|
|
|
const posts = result.data.allMarkdownRemark.edges
|
2018-09-29 20:43:10 +02:00
|
|
|
const numPages = Math.ceil(posts.length / itemsPerPage)
|
2018-07-19 00:22:06 +02:00
|
|
|
|
2018-09-04 02:57:39 +02:00
|
|
|
// Generate posts & posts index
|
2018-10-14 02:25:24 +02:00
|
|
|
generatePostPages(createPage, posts, numPages)
|
2018-07-19 23:04:41 +02:00
|
|
|
|
2018-09-04 02:57:39 +02:00
|
|
|
// Generate Tag Pages
|
2018-09-29 20:43:10 +02:00
|
|
|
generateTagPages(createPage, posts, numPages)
|
2018-07-19 23:04:41 +02:00
|
|
|
|
2018-09-24 23:50:48 +02:00
|
|
|
// create manual redirects
|
2018-10-14 02:25:24 +02:00
|
|
|
generateRedirectPages(createRedirect)
|
2018-09-24 23:50:48 +02:00
|
|
|
|
2018-07-17 23:33:55 +02:00
|
|
|
resolve()
|
|
|
|
})
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|