-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
67 lines (56 loc) · 2.02 KB
/
index.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
'use strict';
const YAML = require('yaml');
const writeFile = require('broccoli-file-creator');
const mergeTrees = require('broccoli-merge-trees');
const path = require('path');
const { readFileSync } = require('fs');
const netlifyIndexHtmlGenerator = require('./netlify-templates/index');
module.exports = {
name: require('./package').name,
getAddonOptions() {
let app = this._findHost();
let options = typeof app.options === 'object' ? app.options : {};
return options['empress-blog-netlify-cms'] || {};
},
treeForPublic() {
let addonConfig = this.getAddonOptions();
let publicPath = addonConfig.publicPath || 'admin';
let modulePath = addonConfig.modulePath;
let netlifyConfigJson = YAML.parse(readFileSync(path.resolve(__dirname, './netlify-templates/config.yml'), 'utf8'));
Object.assign(netlifyConfigJson, addonConfig['netlify-config'] || {});
let netlifyConfigOutputYml = YAML.stringify(netlifyConfigJson);
const netlifyConfigTree = writeFile(
`${publicPath}/config.yml`,
netlifyConfigOutputYml
);
const netlifyIndexHtmlTree = writeFile(
`${publicPath}/index.html`,
netlifyIndexHtmlGenerator(modulePath)
);
return mergeTrees([netlifyConfigTree, netlifyIndexHtmlTree]);
},
contentFor(type) {
let addonConfig = this.getAddonOptions();
let publicPath = addonConfig.publicPath || 'admin';
if (!addonConfig.disableIdentityScriptInIndex) {
if (type === 'head-footer') {
return '<script defer src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>';
}
if (type === 'body-footer') {
return (`
<script>
if (window.netlifyIdentity) {
window.netlifyIdentity.on("init", user => {
if (!user) {
window.netlifyIdentity.on("login", () => {
document.location.href = "/${publicPath}/";
});
}
});
}
</script>
`);
}
}
}
};