forked from Lete114/hexo-artitalk-static
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (36 loc) · 1.38 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 { join } = require('path')
const ejs = require('ejs')
const YAML = require('yaml')
const { readFileSync } = require('hexo-fs')
const { getAbsolutePath, formatDate, getArtitalkFilePath, autoInjectTime, plugins } = require('./utils')
const logo = 'data:image/svg+xml;base64,' + Buffer.from(readFileSync(join(__dirname, 'logo.min.svg'))).toString('base64')
const defaultConfig = {
enable: true,
title: 'Artitalk',
path: 'artitalk/index.html',
pageSize: 5,
plugins: [],
imports: { before: [], after: [] }
}
hexo.extend.generator.register('artitalk', async (locals) => {
const { enable, title, path, pageSize, avatar, plugins: plugins_path, template, imports } = Object.assign({}, defaultConfig, hexo.config.artitalk)
if (!enable) return
const atFilePath = getArtitalkFilePath(hexo.source_dir)
const atContent = readFileSync(atFilePath).toString()
autoInjectTime(atFilePath, atContent)
const atData = YAML.parse(atContent) || locals.data.artitalk || []
plugins(hexo.base_dir, plugins_path, atData)
const data = {
formatDate,
data: { logo, pageSize, avatar, imports },
artitalk: atData
}
const filename = getAbsolutePath(hexo.base_dir, template) || join(__dirname, 'main.ejs')
const content = await ejs.renderFile(filename, data)
return {
path,
data: { type: 'artitalk', content, title },
comments: false,
layout: ['artitalk', 'page']
}
})