Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Mdx #93

Merged
merged 1 commit into from
Feb 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 };