-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.js
executable file
·88 lines (71 loc) · 3.37 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'use strict';
var assign = require('object-assign');
var pathFn = require('path');
var gen = require('./lib/generator');
var ic = require('./lib/copyAssets.js');
var lg = require('./lib/log.js');
var su = require('./lib/settingsUpdate.js');
var cache = require('./lib/cache.js');
var isEnableAMP = true;
lg.setConfig(hexo.config);
ic.setConfig(hexo.config);
if(hexo.config.generator_amp && hexo.config.generator_amp.onlyForDeploy){
lg.log("info", "'onlyForDeploy' option deprecated. Please set the 'cache' option." , null);
}
//default path
var ejsPath = '../template/sample-amp.ejs';
var cssPath = '../template/sample-amp.css';
var logoPath = '../template/sample-logo.png';
var sitelogoPath = '../template/sample-yoursite-logo.png';
var avatarPath = '../template/sample-avator.png';
var placeholderPath = '../template/sample-placeholder.png';
var substituteTitleImagePath = '../template/sample-substituteTitleImage.png';
//------------------------------------
// copy template file
//------------------------------------
if(hexo.config.generator_amp && hexo.config.generator_amp.templateDir && hexo.config.generator_amp.assetDistDir && hexo.config.generator_amp.logo && hexo.config.generator_amp.logo.path && hexo.config.generator_amp.substituteTitleImage && hexo.config.generator_amp.substituteTitleImage.path){
ic.initCopy( pathFn.join(hexo.config.generator_amp.templateDir) , [ejsPath, cssPath, logoPath, sitelogoPath, substituteTitleImagePath, avatarPath , placeholderPath]);
}else{
lg.log("error", "Please set the generator_amp option." , "_config.yml");
return null;
}
var avatorDefaultPath = "sample/" + pathFn.basename( avatarPath );
if(hexo.config.authorDetail && hexo.config.authorDetail.avatar && hexo.config.authorDetail.avatar.path){
avatorDefaultPath = hexo.config.authorDetail.avatar.path;
}
var placeholderDefaultPath = "sample/" + pathFn.basename( placeholderPath );
if(hexo.config.generator_amp.placeholderImg && hexo.config.generator_amp.placeholderImg.path){
placeholderDefaultPath = hexo.config.generator_amp.placeholderImg.path;
}
var siteLogImagePath = "";
if(hexo.config.generator_amp.logo_topImage && hexo.config.generator_amp.logo_topImage.path){
siteLogImagePath = hexo.config.generator_amp.logo_topImage.path;
}else{
siteLogImagePath = hexo.config.generator_amp.logo.path;
}
var copyAssetsStatus = ic.copyAssets(hexo.config.generator_amp.templateDir, hexo.config.generator_amp.assetDistDir, [hexo.config.generator_amp.logo.path, hexo.config.generator_amp.substituteTitleImage.path, avatorDefaultPath, siteLogImagePath , placeholderDefaultPath]);
if(!copyAssetsStatus)return null;
hexo.config.generator_amp = assign({
}, hexo.config.generator_amp, {
"defaultAssetsPath" : {
"tmpl" : ejsPath ,
"css" : cssPath ,
"logo": logoPath ,
"avator" : avatarPath ,
"placeholder": placeholderPath ,
"substituteTitleImage" : substituteTitleImagePath
}
});
var shush = su.chkUpdate(hexo.config);
var cacheHash = cache.getCacheHash(hexo.config);
hexo.config.generator_amp = assign({},
hexo.config.generator_amp, {
"hash" : shush ,
"isCacheUpdate": (shush != cacheHash),
"isCacheClear": (shush != cacheHash)
}
);
hexo.extend.generator.register('amp', module.exports = function(locals) {
return gen( locals , hexo );
});
hexo.extend.filter.register('after_post_render', require('./lib/eyeCatchVars') );