Skip to content

Commit c1a5813

Browse files
committed
(杂项)新增修复第三方包bug的补丁
1 parent 8d30142 commit c1a5813

File tree

5 files changed

+162
-1
lines changed

5 files changed

+162
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@
3535
"vuepress": "^1.0.2",
3636
"vuepress-plugin-comment": "^0.7.0-beta.1",
3737
"vuepress-plugin-flowchart": "^1.4.2",
38-
"vuepress-theme-teadocs": "^1.3.6"
38+
"vuepress-theme-teadocs": "^1.3.7"
3939
}
4040
}

patch/file/Comment.vue

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<template>
2+
<div></div>
3+
</template>
4+
5+
<script>
6+
import {
7+
provider,
8+
renderConfig,
9+
loadScript,
10+
} from './util'
11+
12+
const commentDomID = 'vuepress-plugin-comment'
13+
let timer = null
14+
15+
export default {
16+
mounted () {
17+
timer = setTimeout(() => {
18+
const frontmatter = {
19+
to: {},
20+
from: {},
21+
...this.$frontmatter
22+
}
23+
clear() && needComment(frontmatter) && renderComment(frontmatter)
24+
}, 1000)
25+
26+
this.$router.afterEach((to, from) => {
27+
if (to && from && to.path === from.path) {
28+
return
29+
}
30+
const frontmatter = {
31+
to,
32+
from,
33+
...this.$frontmatter
34+
}
35+
clear()
36+
this.$nextTick(() => {
37+
needComment(frontmatter) && renderComment(frontmatter)
38+
})
39+
})
40+
}
41+
}
42+
43+
/**
44+
* Clear last page comment dom
45+
*/
46+
function clear (frontmatter) {
47+
switch (COMMENT_CHOOSEN) {
48+
case 'gitalk':
49+
return provider.gitalk.clear(commentDomID)
50+
case 'valine':
51+
let el = COMMENT_OPTIONS.el || commentDomID
52+
if (el.startsWith('#')) {
53+
el = el.slice(1)
54+
}
55+
console.log(el)
56+
return provider.valine.clear(el)
57+
default: return false
58+
}
59+
}
60+
61+
/**
62+
* Check if current page needs render comment
63+
*/
64+
function needComment (frontmatter) {
65+
return frontmatter.comment !== false && frontmatter.comments !== false
66+
}
67+
68+
/**
69+
* Render comment dom and append it to container
70+
*/
71+
function renderComment (frontmatter) {
72+
clearTimeout(timer)
73+
74+
const parentDOM = document.querySelector(COMMENT_CONTAINER)
75+
if (!parentDOM) {
76+
timer = setTimeout(() => renderComment(frontmatter), 200)
77+
return
78+
}
79+
80+
switch (COMMENT_CHOOSEN) {
81+
case 'gitalk':
82+
return provider.gitalk.render(frontmatter, commentDomID)
83+
case 'valine':
84+
let el = COMMENT_OPTIONS.el || commentDomID
85+
if (el.startsWith('#')) {
86+
el = el.slice(1)
87+
}
88+
console.log(el)
89+
return provider.valine.render(frontmatter, el)
90+
default: return false
91+
}
92+
}
93+
</script>

patch/file/Valine.Pure.min.js

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

patch/file/Valine.min.js

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

patch/index.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const modules = 'node_modules';
5+
const vuepress_plugin_comment = 'vuepress-plugin-comment';
6+
const valine = 'valine/dist';
7+
const vuepress = 'vuepress';
8+
9+
const maps = [
10+
{
11+
sourceFile: path.resolve(path.join('./file', 'Comment.vue')),
12+
targetFile: path.resolve(path.join('../', modules, vuepress_plugin_comment, 'Comment.vue')),
13+
targetDir: path.resolve(path.join('../', modules, vuepress_plugin_comment))
14+
},
15+
{
16+
sourceFile: path.resolve(path.join('./file', 'Valine.min.js')),
17+
targetFile: path.resolve(path.join('../', modules, valine, 'Valine.min.js')),
18+
targetDir: path.resolve(path.join('../', modules, valine))
19+
},
20+
{
21+
sourceFile: path.resolve(path.join('./file', 'Valine.Pure.min.js')),
22+
targetFile: path.resolve(path.join('../', modules, valine, 'Valine.Pure.min.js')),
23+
targetDir: path.resolve(path.join('../', modules, valine))
24+
}
25+
];
26+
27+
// 修复留言板的一些bug
28+
for (const item of maps) {
29+
console.log('targetFile', item.targetFile);
30+
if (fs.existsSync(item.targetFile)) {
31+
fs.unlinkSync(item.targetFile);
32+
}
33+
const sourceContent = fs.readFileSync(item.sourceFile);
34+
fs.writeFileSync(item.targetFile, sourceContent);
35+
}
36+
37+
// 替换 cli 文件
38+
const cliPath = path.resolve(path.join('../', modules, vuepress, 'cli.js'));
39+
console.log('cliPath', cliPath);
40+
let sourceContent = fs.readFileSync(cliPath, 'utf-8');
41+
let tempArray = sourceContent.split('\n');
42+
tempArray[0] = `#!/usr/bin/env node --max_old_space_size=4906`;
43+
sourceContent = tempArray.join('\n');
44+
fs.writeFileSync(cliPath, sourceContent);

0 commit comments

Comments
 (0)