-
Notifications
You must be signed in to change notification settings - Fork 0
/
dato.config.js
95 lines (86 loc) · 3.15 KB
/
dato.config.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const htmlTag = require('html-tag');
// This function helps transforming structures like:
//
// [{ tagName: 'meta', attributes: { name: 'description', content: 'foobar' } }]
//
// into proper HTML tags:
//
// <meta name="description" content="foobar" />
const toHtml = (tags) => (
tags.map(({ tagName, attributes, content }) => (
htmlTag(tagName, attributes, content)
)).join("")
);
// Arguments that will receive the mapping function:
//
// * dato: lets you easily access any content stored in your DatoCMS
// administrative area;
//
// * root: represents the root of your project, and exposes commands to
// easily create local files/directories;
//
// * i18n: allows to switch the current locale to get back content in
// alternative locales from the first argument.
//
// Read all the details here:
// https://github.com/datocms/js-datocms-client/blob/master/docs/dato-cli.md
module.exports = (dato, root, i18n) => {
// Add to the existing Hugo config files some properties coming from data
// stored on DatoCMS
['config.dev.toml', 'config.prod.toml'].forEach(file => {
root.addToDataFile(file, 'toml', {
title: dato.site.globalSeo.siteName,
languageCode: i18n.locale
});
});
// Create a YAML data file to store global data about the site
root.createDataFile('data/settings.yml', 'yaml', {
name: dato.site.globalSeo.siteName,
language: dato.site.locales[0],
intro: dato.home.introText,
copyright: dato.home.copyright,
// iterate over all the `social_profile` item types
socialProfiles: dato.socialProfiles.map(profile => {
return {
type: profile.profileType.toLowerCase().replace(/ +/, '-'),
url: profile.url,
};
}),
faviconMetaTags: toHtml(dato.site.faviconMetaTags),
seoMetaTags: toHtml(dato.home.seoMetaTags)
});
// Create a markdown file with content coming from the `about_page` item
// type stored in DatoCMS
root.createPost(`content/about.md`, 'yaml', {
frontmatter: {
title: dato.aboutPage.title,
subtitle: dato.aboutPage.subtitle,
photo: dato.aboutPage.photo.url({ w: 800, fm: 'jpg', auto: 'compress' }),
seoMetaTags: toHtml(dato.aboutPage.seoMetaTags),
menu: { main: { weight: 100 } }
},
content: dato.aboutPage.bio
});
// Create a `work` directory (or empty it if already exists)...
root.directory('content/work', dir => {
// ...and for each of the works stored online...
dato.works.forEach((work, index) => {
// ...create a markdown file with all the metadata in the frontmatter
dir.createPost(`${work.slug}.md`, 'yaml', {
frontmatter: {
title: work.title,
coverImage: work.coverImage.url({ w: 450, fm: 'jpg', auto: 'compress' }),
image: work.coverImage.url({ fm: 'jpg', auto: 'compress' }),
detailImage: work.coverImage.url({ w: 600, fm: 'jpg', auto: 'compress' }),
excerpt: work.excerpt,
seoMetaTags: toHtml(work.seoMetaTags),
extraImages: work.gallery.map(item =>
item.url({ h: 300, fm: 'jpg', auto: 'compress' })
),
weight: index,
},
content: work.description
});
});
});
};