-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.js
36 lines (32 loc) · 1012 Bytes
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* eslint-env node, es6 */
const fp = require('lodash/fp')
const {createFilePath} = require('gatsby-source-filesystem')
const trans = {
authors: 'reporteres',
articles: 'materias',
editorials: 'editorias',
about: 'sobre',
}
const createUrl = fp.flow(
createFilePath,
fp.replace(/(^\/|\/$)/g, ''),
fp.split('/'),
array => array.reduce((url, segment, index) => {
if(index === 0 && segment === 'docs') return url
if(index === 1) return [...url, trans[segment] || segment]
return [...url, segment]
}, []),
fp.join('/'),
string => `/${string}/`.replace(/\/+/, '/')
)
exports.createPages = async (...args) => {
await require('./gatsby/create-default-pages')(...args)
await Promise.all([
require('./gatsby/create-tag-pages')(...args),
require('./gatsby/create-post-pages')(...args),
])
}
exports.onCreateNode = ({node, actions: {createNodeField}, getNode}) => {
if (node.internal.type !== 'MarkdownRemark') return
createNodeField({name: 'slug', node, value: createUrl({node, getNode})})
}