-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
64 lines (55 loc) · 2.23 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
const path = require('path');
hexo.config.images = Object.assign(
{
enable: true,
base_dir: '.images',
manifestFileName: 'images.json',
excludeSourceImages: true,
specialImages: [],
templates: {
image: path.relative(hexo.base_dir, path.resolve(__dirname, 'lib', 'templates', 'image.ejs')),
video: path.relative(hexo.base_dir, path.resolve(__dirname, 'lib', 'templates', 'video.ejs'))
}
},
hexo.config.images
);
if (hexo.config.images.enable) {
/**
* Process source images and write to cache folder
* when post content or file(s) changed - what happens first.
*
* ⚠️ Note: if images already validated in the current cycle,
* it won't be runned again until "after_generate".
*/
const invalidateImages = require('./lib/invalidateImages')(hexo);
const injectMetadata = require('./lib/injectMetadata')(hexo);
let imagesInvaidated = false;
hexo.extend.filter.register('before_generate', function () {
if (imagesInvaidated === false) {
imagesInvaidated = true;
return invalidateImages();
}
});
// Inject image cache manifest into page metadata. Process images before if needed.
hexo.extend.filter.register('before_post_render', function (data) {
if (imagesInvaidated === false) {
imagesInvaidated = true;
return invalidateImages().then(() => injectMetadata(data));
} else {
return injectMetadata(data);
}
});
hexo.extend.filter.register('after_generate', function () {
imagesInvaidated = false;
});
// Exclude source images from output
if (hexo.config.images.excludeSourceImages) {
hexo.extend.filter.register('after_generate', require('./lib/cleanupSourceImagesFiler')(hexo));
}
// Inlcude processed images into final output
hexo.extend.generator.register('images', require('./lib/imagesGenerator')(hexo));
// Helper to resolve image by name from the current post context
hexo.extend.helper.register('resolve_image', require('./lib/resolveImageHelper')(hexo));
// Picture tag
hexo.extend.tag.register('picture', require('./lib/picture')(hexo), { ends: true });
}