Skip to content

Commit 42410d7

Browse files
committed
init
0 parents  commit 42410d7

12 files changed

+4118
-0
lines changed

.gitignore

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
/dist
14+
15+
# misc
16+
.DS_Store
17+
.env.local
18+
.env.development.local
19+
.env.test.local
20+
.env.production.local
21+
22+
npm-debug.log*
23+
yarn-debug.log*
24+
yarn-error.log*
25+

README.md

Whitespace-only changes.

index.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const fs = require('hexo-fs');
2+
3+
const scriptUrl = '/post-history/main.js';
4+
var config = hexo.config.history;
5+
function buildGenerator(sourcePath, distPath) {
6+
return {
7+
data: () => fs.createReadStream(sourcePath),
8+
path: distPath
9+
};
10+
}
11+
//将打包好后的main复制到public中
12+
hexo.extend.generator.register('test', () => {
13+
return buildGenerator(require.resolve('./dist/main.js'), scriptUrl);
14+
});
15+
//添加上script标签
16+
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>`;
19+
let newHtmlContent = htmlContent;
20+
if (/([\n\r\s\t]*<\/body>)/i.test(htmlContent)) {
21+
const lastIndex = htmlContent.lastIndexOf('</body>');
22+
newHtmlContent = `${htmlContent.substring(
23+
0,
24+
lastIndex
25+
)}${contentToInject}${htmlContent.substring(lastIndex, htmlContent.length)}`;
26+
}
27+
return newHtmlContent;
28+
});

0 commit comments

Comments
 (0)