-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (37 loc) · 1.47 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
'use strict'
const pug = require('pug')
const path = require('path')
const urlFor = require('hexo-util').url_for.bind(hexo)
const util = require('hexo-util')
hexo.extend.generator.register('games', function (locals) {
const config = hexo.config.games || hexo.theme.config.games
const errorimg = hexo.theme.config.error_img
if (!(config && config.enable)) return
const data = {
name: config.name,
errorimg: config.errorimg ? urlFor(config.errorimg) : errorimg.post_page,
description: config.description,
tips: config.tip,
top_background: config.top_background ? urlFor(config.top_background) : "https://www.loliapi.com/acg",
buttonText: config.buttonText ? config.buttonText : "Steam",
buttonLink: config.buttonLink ? urlFor(config.buttonLink) : "https://steamcommunity.com/",
good_games: config.good_games,
custom_css: config.css ? urlFor(config.css) : "https://jsd.onmicrosoft.cn/npm/hexo-butterfly-games/lib/default.css"
}
const css_text = `<link rel="stylesheet" href="${data.custom_css}">`
const content = pug.renderFile(path.join(__dirname, './lib/html.pug'), data)
const pathPre = config.path || 'games'
let pageDate = {
content: content
}
// 注入样式资源
hexo.extend.injector.register('head_end', css_text, "default");
if (config.front_matter) {
pageDate = Object.assign(pageDate, config.front_matter)
}
return {
path: pathPre + '/index.html',
data: pageDate,
layout: ['page', 'post']
}
})