-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (24 loc) · 843 Bytes
/
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
var fs = require('hexo-fs');
var path = require('path');
var ejs = require('ejs');
hexo.extend.tag.register('autogallery', function(args) {
var layout = args[0]
var relativeDir = args[1];
var dir = path.join(hexo.source_dir, relativeDir);
var themePath = path.join(hexo.theme_dir, 'layout', '_partial', layout + '.ejs')
if (hexo.env.debug) {
console.log('[Autogallery] Running autogallery on ' + dir + ', using layout ' + themePath);
}
try {
var files = fs.listDirSync(dir);
var template = fs.readFileSync(themePath)
var photos = files.map(f => relativeDir + '/' + f)
return ejs.render(template, {
photos: photos,
config: hexo.config
})
} catch (e) {
console.error(e);
return '<h3>Could not render autogallery at ' + relativeDir + ' using ' + layout + ' layout</h3>'
}
});