Skip to content

Instantly share code, notes, and snippets.

@vlgutv22
Created June 1, 2017 12:59
Show Gist options
  • Save vlgutv22/73a95699968968830e140cbff62b69a7 to your computer and use it in GitHub Desktop.
Save vlgutv22/73a95699968968830e140cbff62b69a7 to your computer and use it in GitHub Desktop.
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