|
1 | 1 | const fs = require('hexo-fs');
|
2 | 2 |
|
3 |
| -const scriptUrl = '/post-history/main.js'; |
4 |
| -var config = hexo.config.history; |
| 3 | +var config = hexo.config.history || {}; |
5 | 4 | function buildGenerator(sourcePath, distPath) {
|
6 | 5 | return {
|
7 | 6 | data: () => fs.createReadStream(sourcePath),
|
8 | 7 | path: distPath
|
9 | 8 | };
|
10 | 9 | }
|
11 | 10 | //将打包好后的main复制到public中
|
12 |
| -hexo.extend.generator.register('test', () => { |
13 |
| - return buildGenerator(require.resolve('./dist/main.js'), scriptUrl); |
| 11 | +hexo.extend.generator.register('hexo-history-file', () => { |
| 12 | + return [ |
| 13 | + { entry: './hexo-history-main.js', out: '/hexo-history-main.js' }, |
| 14 | + { |
| 15 | + entry: './143146fa24554ae2c5ac0a3982abb952.woff2', |
| 16 | + out: '/143146fa24554ae2c5ac0a3982abb952.woff2' |
| 17 | + } |
| 18 | + ].map((i) => buildGenerator(require.resolve(i.entry), i.out)); |
14 | 19 | });
|
15 | 20 | //添加上script标签
|
16 | 21 | hexo.extend.filter.register('after_render:html', (htmlContent) => {
|
17 |
| - const scriptToInject = `hexoHistory.init(${JSON.stringify(config)});`; |
18 |
| - const contentToInject = `<script src="${scriptUrl}"></script><script>${scriptToInject}</script>`; |
| 22 | + const scriptToInject = `HexoHistory(${JSON.stringify(config)});`; //把配置注册为全局变量好了 |
| 23 | + let vueInject = `<script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>`; |
| 24 | + const contentToInject = `${vueInject}<script src="/hexo-history-main.js"></script><script>${scriptToInject}</script>`; |
19 | 25 | let newHtmlContent = htmlContent;
|
20 | 26 | if (/([\n\r\s\t]*<\/body>)/i.test(htmlContent)) {
|
21 | 27 | const lastIndex = htmlContent.lastIndexOf('</body>');
|
|
0 commit comments