Skip to content

Commit

Permalink
Merge pull request #93 from przemuh/master
Browse files Browse the repository at this point in the history
Added support for Mdx
  • Loading branch information
angeloocana committed Feb 3, 2020
2 parents 8682f74 + 465029d commit 0b52d7b
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions packages/gatsby-plugin-i18n/src/onCreateNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ import { isInPagesPaths, getSlugAndLang } from 'ptz-i18n';
import Result from 'folktale/result';
import { isNil, chain } from 'ramda';

const getValidFile = filePath =>
isNil(filePath)
? Result.Error('No file name')
: Result.Ok(filePath);
const getValidFile = filePath =>
isNil(filePath) ? Result.Error('No file name') : Result.Ok(filePath);

const getFilePath = node => {
switch(node.internal.type){
case 'File': return getValidFile(node.absolutePath);
case 'MarkdownRemark': return getValidFile(node.fileAbsolutePath);
default: return Result.Error('Skiping file type: ' + node.internal.type);
switch (node.internal.type) {
case 'File':
return getValidFile(node.absolutePath);
case 'MarkdownRemark':
case 'Mdx':
return getValidFile(node.fileAbsolutePath);
default:
return Result.Error('Skiping file type: ' + node.internal.type);
}
};


/**
* Add custom url pathname for blog posts.
* @param {*} args args
* @param {*} pluginOptions plugin options from gatsby-config.js
* @returns {void} void
*/
const onCreateNode = ({ node, actions }, pluginOptions) => {

const options = {
...defaultOptions,
...pluginOptions
Expand All @@ -33,16 +33,18 @@ const onCreateNode = ({ node, actions }, pluginOptions) => {
return getFilePath(node)
.map(filePath =>
chain(isInPaths => {

if(isInPaths === false){
if (isInPaths === false) {
return 'Skipping page, not in pagesPaths';
}

const slugAndLang = getSlugAndLang(options, filePath);

const { createNodeField } = actions;

if(node.internal.type === 'MarkdownRemark'){
if (
node.internal.type === 'MarkdownRemark' ||
node.internal.type === 'Mdx'
) {
createNodeField({
node,
name: 'langKey',
Expand All @@ -62,7 +64,4 @@ const onCreateNode = ({ node, actions }, pluginOptions) => {
.merge();
};

export {
onCreateNode
};

export { onCreateNode };

0 comments on commit 0b52d7b

Please sign in to comment.