Created
June 1, 2017 12:59
-
-
Save vlgutv22/73a95699968968830e140cbff62b69a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = (dato, root, i18n) => { | |
i18n.availableLocales.forEach((locale) => { | |
i18n.withLocale(locale, () => { | |
['config.toml'].forEach(file => { | |
root.addToDataFile(file, 'toml', { | |
title: dato.site.globalSeo.siteName, | |
languages: parseLocales(i18n.availableLocales) | |
}); | |
}); | |
dato.pages.forEach((page) => { | |
root.createPost(`content/${page.slug}.${locale}.md`, 'yaml', { | |
frontmatter: { | |
title: page.title, | |
type: "page", | |
layout: "page", | |
slug: '/' + page.slug, | |
menu: page.menues.map(item => item.menuname) | |
} | |
}); | |
}); | |
}); | |
}); | |
} | |
function parseLocales(obj) { | |
var values = []; | |
for (var i = 0; i < obj.length; i++) { | |
var item = obj[i] + ': {languageName: "' + obj[i] + '", weight:'+ i +'}'; | |
values.push(item) | |
} | |
return eval('({' + values + '})'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment