Skip to content

Commit 1ed917b

Browse files
committed
'可以正式使用了✨''
1 parent 111337c commit 1ed917b

15 files changed

+85
-41
lines changed

README.md

+22-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# hexo-history
22

3-
文章历史对比, 显示每次更新差异的一个 hexo 插件, 关于如何开发的详细文章可见[]()
3+
文章历史对比, 显示每次更新差异的一个 hexo 插件, 关于如何开发的详细文章可见 [hexo history 插件开发](https://luckyray-fan.github.io/2020/02/19/hexo-history/)
44

5-
## 使用方法
5+
## 展示
66

7-
- 本地执行测试, 更改 info-provider 即可
7+
![](http://img.luckyray.cn/hexo-history.gif)
8+
9+
## 本地执行测试
10+
11+
- 本地执行测试, 更改 info-provider 内的 info 对象即可
812

913
| 参数名 | 含义 |
1014
| ----------- | ---------------------------------- |
@@ -13,10 +17,21 @@
1317
| anchorClass | 用于挂载和解析的文章节点 |
1418
| baseUrl | 使用 iframe 渲染时设定的 base 标签 |
1519

16-
- 正式使用, 设置 config, 名称为 hexoHistory, 参照下图操作即可
20+
- 执行 npm run s, 即可使用 webpack server 热加载
21+
- 执行 npm run build, 即可构建开发版本
22+
- 在当前文件夹下测试, 复制一个 index.html 过来, 当然要记得配置 info-provider
23+
- hexo 实地测试, 把构建好的覆盖到 hexo node_modules 的 hexo-history 文件夹下, 当然在此之前先 npm install hexo-history, 然后 hexo clean(删除目录), hexo g(generate 的缩写), hexo s 即可
24+
25+
## 正式使用
26+
27+
设置 config, 名称为 hexoHistory, 参照下图操作即可
28+
29+
![](https://luckyray-fan.github.io/image/hexo-history-1.png)
30+
31+
> 拥有改变按钮位置的功能但**并未测试**, 可以配置 pos 字段, 当然你也可以在 theme 的 css 文件中强势覆盖
1732
1833
## 后续改进
1934

20-
- icon 引入 bug
21-
- diff 算法实现
22-
- hexo 只选择 post 进行处理
35+
- [x] icon 引入 bug
36+
- [ ] diff 算法实现
37+
- [ ] hexo 只选择 post 进行处理

index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
<link rel="dns-prefetch" href="https://cdn.staticfile.org">
1919
<link rel="dns-prefetch" href="https://cdn.bootcss.com">
2020
<link rel="dns-prefetch" href="https://creativecommons.org">
21-
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>
21+
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
22+
<script>window.hexoHistoryConfig = {"repo":"luckyray-fan/luckyray-fan.github.io","token":"1d5107f3e8a6dd270b60bb70ffce79485b387e53","theme":"melody"}</script>
2223
<style>
2324

2425

index.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ hexo.extend.generator.register('hexo-history-file', () => {
1212
return [
1313
{ entry: './hexo-history-main.js', out: '/hexo-history-main.js' },
1414
{
15-
entry: './143146fa24554ae2c5ac0a3982abb952.woff2',
16-
out: '/143146fa24554ae2c5ac0a3982abb952.woff2'
15+
entry: './ionicons.woff2',
16+
out: '/ionicons.woff2'
1717
}
1818
].map((i) => buildGenerator(require.resolve(i.entry), i.out));
1919
});
2020
//添加上script标签
2121
hexo.extend.filter.register('after_render:html', (htmlContent) => {
22-
const scriptToInject = `<script>window.hexoHistoryConfig = JSON.parse(${JSON.stringify(
23-
config
24-
)});</script> `; //把配置注册为全局变量好了
22+
const scriptToInject = `<script>window.hexoHistoryConfig = ${JSON.stringify(config)}</script> `; //把配置注册为全局变量好了
2523
let vueInject = `<script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>`;
2624
const contentToInject = `${vueInject} ${scriptToInject}<script src="/hexo-history-main.js"></script>`;
2725
let newHtmlContent = htmlContent;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hexo-history",
3-
"version": "1.1.4",
3+
"version": "1.1.9",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/luckyray-fan/hexo-history.git"
@@ -9,7 +9,7 @@
99
"main": "index.js",
1010
"files": [
1111
"/hexo-history-main.js",
12-
"143146fa24554ae2c5ac0a3982abb952.woff2"
12+
"ionicons.woff2"
1313
],
1414
"scripts": {
1515
"start": "webpack --watch",

src/dombuild.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class dombuild {
2525
arr = typeof arr === 'string' ? [arr] : arr;
2626
arr.forEach((i) => {
2727
let tem = parser(i);
28-
window.tem = tem;
28+
// window.tem = tem;
2929
tem = this.findNode(tem, anchorClass);
3030
tem = tem.filter(
3131
(i) => i !== ' ' //去除无意义文本节点

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// import Vue from 'vue';
1+
import Vue from 'vue';
22
import app from './index.vue';
33
Vue.config.productionTip = false; //防止生成生产提示
44
import 'iview/dist/styles/iview.css';

src/index.vue

+35-20
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
Badge
4141
} from "iview";
4242
import skeleton from "./components/skeleton.vue";
43-
// import Vue from "vue";
43+
import Vue from "vue";
4444
4545
Vue.component("skeleton", skeleton);
4646
Vue.component("Alert", Alert);
@@ -63,7 +63,7 @@ export default {
6363
},
6464
methods: {
6565
async render(name) {
66-
if (this.cur === name) {
66+
if (this.cur === name || name === undefined) {
6767
return;
6868
}
6969
if (name === "addCommit") {
@@ -81,28 +81,29 @@ export default {
8181
temNode = await this.domCompare.getDomFragment(
8282
this.items[+this.cur].content
8383
);
84-
temNode = document.importNode(temNode, true); //dom 上事件的复制等等
84+
temNode = document.importNode(temNode, true).children; //dom 上事件的复制等等
85+
}
86+
removeChildren(this.dom);
87+
if (name !== 0) {
88+
this.dom.append(saveInfo.infoAlert);
89+
}
90+
for (let i = 0; i < temNode.length; i++) {
91+
this.dom.append(temNode[i]);
8592
}
86-
this.dom.innerHTML = "";
87-
this.dom.append(saveInfo.infoAlert);
88-
this.dom.append(temNode);
89-
// for (let i = 0; i < newNode.children.length; i++) {
90-
// this.dom.append(newNode.children[i]);
91-
// }
92-
// this.domCompare.getFragment(+name + 1); //把它换成整数, 防止传入字符串
9393
}
9494
},
9595
async mounted() {
9696
if (window.hexoHistoryConfig) {
9797
let pos = window.hexoHistoryConfig.pos;
98-
if(!pos) return;
99-
let style = this.$el.style;
100-
({
101-
left: style.left,
102-
right: style.right,
103-
top: style.top,
104-
bottom: style.bottom
105-
} = pos);
98+
if (pos) {
99+
let style = this.$el.style;
100+
({
101+
left: style.left,
102+
right: style.right,
103+
top: style.top,
104+
bottom: style.bottom
105+
} = pos);
106+
}
106107
}
107108
this.items = await getCommits();
108109
this.complete = true; //防止连续点多次继续加载
@@ -132,15 +133,15 @@ export default {
132133
});
133134
//存储
134135
saveInfo.skeleton = new skeletonTem().$mount().$el;
135-
saveInfo.origin = this.dom; // element.children 是 live 的
136+
saveInfo.origin = cloneDeep(this.dom); // element.children 是 live 的
136137
saveInfo.infoAlert = new infoAlert().$mount().$el;
137138
138139
this.domCompare = new dombuild();
139140
this.domCompare.setArr([
140141
this.dom.innerHTML,
141142
...this.items.map(i => i.content)
142143
]);
143-
window.test = this.domCompare.astArr[0];
144+
// window.test = this.domCompare.astArr[0];
144145
},
145146
data() {
146147
return {
@@ -155,6 +156,20 @@ export default {
155156
},
156157
props: ["dom"]
157158
};
159+
function removeChildren(node) {
160+
let child = node.lastElementChild;
161+
while (child) {
162+
node.removeChild(child);
163+
child = node.lastElementChild;
164+
}
165+
}
166+
function cloneDeep(node) {
167+
let frag = [];
168+
for (let i = 0; i < node.children.length; i++) {
169+
frag.push(node.children[i]);
170+
}
171+
return frag;
172+
}
158173
</script>
159174
<style scoped>
160175
.ivu-select-dropdown ul {

src/info-provider.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ let themeToClass = {
1212
melody: 'article-container',
1313
next: 'post-body'
1414
};
15-
Info.path = location.pathname;
1615
if (window.hexoHistoryConfig) {
17-
({ repo: gitInfo.repo, token: gitInfo.token } = window.hexoHistoryConfig.gitInfo);
16+
Info.path = location.pathname;
17+
({ repo: Info.repo, token: Info.token } = window.hexoHistoryConfig);
1818
if (window.hexoHistoryConfig.theme) {
1919
Info.anchorClass = themeToClass[window.hexoHistoryConfig.theme.toLowerCase()];
2020
}

src/test.js

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ console.dir(c);
8787
* - 文章内容: 如何本地测试与使用(readme), 如何开发的
8888
* - bug fix
8989
* - 请求没有按照顺序返回
90+
* - 可以保存节点1
9091
* - 兼容next主题
9192
* - **换主题的解决方案**
9293
* - 挂载点问题解决

webpack.config.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ module.exports = {
3131
},
3232
{
3333
test: /\.(svg|ttf|eot|woff)\??.*$/,
34-
loader: 'file-loader'
34+
use: [
35+
{
36+
options: {
37+
name: '/[name].[ext]' //没必要上hash
38+
},
39+
loader: 'file-loader'
40+
}
41+
]
3542
}
3643
]
3744
},

webpack.prod.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ module.exports = {
2929
},
3030
{
3131
test: /\.(svg|ttf|eot|woff)\??.*$/,
32-
loader: 'file-loader'
32+
use: [
33+
{
34+
options: {
35+
name: '/[name].[ext]' //没必要上hash
36+
},
37+
loader: 'file-loader'
38+
}
39+
]
3340
}
3441
]
3542
},

0 commit comments

Comments
 (0)