-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (36 loc) · 1.91 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
const config = require("./lib/config")(hexo);
const ResourceManager = require('./lib/resource-manager');
function insertToHtml(layout) {
hexo.extend.generator.register("mbti-card", function(locals) {
const resourceManager = new ResourceManager(hexo, { cardType: 'common', ...config });
const { defaultCss, defaultScripts, externalScripts } = resourceManager.generateCardContent();
hexo.extend.injector.register('head_end', defaultCss, layout);
hexo.extend.injector.register('body_end', defaultScripts, layout);
hexo.extend.injector.register('body_end', externalScripts, layout);
config.cards.forEach((cardConfig, index) => {
const resourceManager = new ResourceManager(hexo, cardConfig);
const { defaultCss, defaultScripts, externalScripts } = resourceManager.generateCardContent();
hexo.extend.injector.register('head_end', defaultCss, layout);
hexo.extend.injector.register('body_end', defaultScripts, layout);
hexo.extend.injector.register('body_end', externalScripts, layout);
const renderScript = `
<script>
initialize${cardConfig.cardType.charAt(0).toUpperCase() + cardConfig.cardType.slice(1)}MBTI(${JSON.stringify(cardConfig)});
</script>
`;
hexo.extend.injector.register('body_end', renderScript, layout);
});
});
}
hexo.extend.filter.register('after_init', () => {
const commonResourceManager = new ResourceManager(hexo, { cardType: 'common', ...config });
commonResourceManager.copyResources();
config.cards.forEach(cardConfig => {
const resourceManager = new ResourceManager(hexo, cardConfig);
resourceManager.copyResources();
});
});
const layouts = [...new Set(config.cards.map(card => card.layout))];
layouts.forEach(layout => {
insertToHtml(layout);
});