Skip to content

Commit 073287c

Browse files
committed
fix comment bug
1 parent a5eeac8 commit 073287c

File tree

6 files changed

+103
-38
lines changed

6 files changed

+103
-38
lines changed

docs/.vuepress/config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const container = require('markdown-it-container')
44
module.exports = {
55
dest: 'vuepress',
66
title: "Finen",
7-
ga: "UA-131334453-1",
87
description: 'Stay Hungry! Stay Foolish!',
98
head: [
109
['link', { rel: 'icon', href: `/logo.png` }],
@@ -32,6 +31,9 @@ module.exports = {
3231
serviceWorker: true,
3332
updatePopup: true
3433
}],
34+
['@vuepress/google-analytics', {
35+
ga: 'UA-131334453-1'
36+
}],
3537
],
3638
themeConfig: {
3739
repo: 'hirCodd',

docs/.vuepress/enhanceApp.js

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,63 @@
1+
// function renderValine(router) {
2+
// // 重新渲染 评论区
3+
// router.afterEach((to, from) => {
4+
// let $page = document.querySelector('.page')
5+
// let vcomments = document.getElementById('vcomments')
6+
// if(!vcomments){
7+
// vcomments = document.createElement('div')
8+
// vcomments.id = 'vcomments'
9+
// // vcomments.style.margin = '1em 4em 0 4em'
10+
// vcomments.style.maxWidth = '740px'
11+
// vcomments.style.display = 'block'
12+
// vcomments.style.padding = '10px'
13+
// vcomments.style.marginLeft = 'auto'
14+
// vcomments.style.marginRight = 'auto'
15+
// }
16+
// if ($page && !vcomments && $page.frontmatter.comments){
17+
// $page.appendChild(vcomments)
18+
// console.log("ss")
19+
// }else{
20+
// // 获取不到vuepress的page加载完成时的钩子,只能采用笨方法
21+
// setTimeout(()=>{
22+
// $page = document.querySelector('.page')
23+
// $page.appendChild(vcomments)
24+
// valine()
25+
// }, 500)
26+
// }
27+
// valine()
28+
// })
29+
// }
30+
// function valine() {
31+
// const Valine = require('valine')
32+
// const leancloudStorage = require('leancloud-storage')
33+
// // require window
34+
// if (typeof window !== 'undefined') {
35+
// window.AV = leancloudStorage
36+
// }
37+
// // 初始化valine
38+
// new Valine({
39+
// el: '#vcomments' ,
40+
// appId: 'piM1Wm7mzq4fsj7RfCCJ7slE-gzGzoHsz',
41+
// appKey: 'vdSq43byXijVSfd0Y5qY0vf8',
42+
// notify:false, // 邮件提醒
43+
// verify:false, // 验证码
44+
// avatar:'mm',
45+
// placeholder: '说点什么吧',
46+
// path: window.location.pathname // 虽然默认就是这个,但是不加会导致不重新加载评论
47+
// });
48+
// }
49+
50+
151
export default ({
2-
Vue, // VuePress 正在使用的 Vue 构造函数
3-
options, // 附加到根实例的一些选项
4-
router, // 当前应用的路由实例
5-
siteData // 站点元数据
6-
}) => {
7-
// ...做一些其他的应用级别的优化
8-
}
52+
Vue, // VuePress 正在使用的 Vue 构造函数
53+
options, // 附加到根实例的一些选项
54+
router, // 当前应用的路由实例
55+
siteData // 站点元数据
56+
}) => {
57+
// try {
58+
// // 生成静态页时在node中执行,没有document对象
59+
// document && renderValine(router)
60+
// } catch (e) {
61+
// console.error(e.message)
62+
// }
63+
}

docs/.vuepress/theme/components/Comments.vue

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<template>
22

33
<div class="vcomment" v-if="data.comments === true">
4-
<!-- <div class="vcomment"> -->
54
<div id="vcomments"></div>
65
</div>
76
</template>
@@ -15,52 +14,49 @@ export default {
1514
},
1615
},
1716
mounted: function(){
18-
const Valine = require('valine');
19-
window.AV = require('leancloud-storage')
20-
const valine = new Valine({
21-
el: '#vcomments',
22-
appId: 'piM1Wm7mzq4fsj7RfCCJ7slE-gzGzoHsz',
23-
appKey: 'vdSq43byXijVSfd0Y5qY0vf8',
24-
notify: false,
25-
verify: false,
26-
avatar: 'monsterid',
27-
placeholder: '欢迎留言与我分享您的想法...',
28-
})
29-
// this.$router.afterEach((to, from) => {
30-
31-
// })
17+
this.createValine()
18+
},
19+
20+
methods: {
21+
createValine() {
22+
const Valine = require('valine');
23+
window.AV = require('leancloud-storage')
24+
const valine = new Valine({
25+
el: '#vcomments',
26+
appId: 'piM1Wm7mzq4fsj7RfCCJ7slE-gzGzoHsz',
27+
appKey: 'vdSq43byXijVSfd0Y5qY0vf8',
28+
notify: false,
29+
verify: false,
30+
avatar: 'monsterid',
31+
path: window.location.pathname,
32+
placeholder: '欢迎留言与我分享您的想法...',
33+
});
34+
this.valineRefresh = false
35+
}
3236
},
3337
watch: {
3438
'$route' (to, from) {
3539
if(to.path !== from.path){
36-
// location.assign(location)
37-
// 因为不是很懂vue,所以刷新使用这个来写。哈哈哈,不知道如何组件内刷新。有了解的请联系我:hefengen@hotmail.com
38-
this.$router.go(0)
39-
// console.log('我在这里要刷新一下')
40-
}else{
41-
40+
setTimeout(() => {
41+
//重新刷新valine
42+
this.createValine()
43+
}, 300)
4244
}
4345
4446
/**
4547
* TODO:
4648
* 1. 使用其他方法更新评论组件 或者使用其他较为好用的评论组件
4749
* 2. 添加categories and tag
48-
* 3. 跟换其他主题
50+
* 3. 更换其他主题
4951
*/
5052
}
51-
},
52-
beforeUpdate: function(){
53-
},
54-
updated: function(){
55-
},
56-
destroyed: function (){
5753
}
5854
}
5955
</script>
6056

6157
<style lang="stylus" rel="stylesheet/stylus">
6258
#vcomments {
63-
width 68%
59+
max-width 740px
6460
padding 10px
6561
display block;
6662
margin-left auto;

docs/.vuepress/theme/components/Page.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
</div>
5959

6060
<slot name="bottom"/>
61-
<comments v-bind:is="viewComments"></comments>
61+
<Comments v-bind:is="viewComments"></Comments>
6262
</main>
6363
</template>
6464

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
{
2+
"scripts": {
3+
"dev": "yarn vuepress dev docs",
4+
"build": "yarn vuepress build docs"
5+
},
26
"dependencies": {
37
"@vuepress/plugin-back-to-top": "^1.0.0-alpha.0",
48
"@vuepress/plugin-pwa": "^1.0.0-alpha.0",
59
"eslint": "^5.12.1",
610
"leancloud-storage": "^3.11.1",
711
"valine": "^1.3.4",
812
"vuepress": "^1.0.0-alpha.32"
13+
},
14+
"devDependencies": {
15+
"@vuepress/plugin-google-analytics": "^1.0.0-alpha.0"
916
}
1017
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,11 @@
877877
dependencies:
878878
lodash.debounce "^4.0.8"
879879

880+
"@vuepress/plugin-google-analytics@^1.0.0-alpha.0":
881+
version "1.0.0-alpha.0"
882+
resolved "http://registry.npm.taobao.org/@vuepress/plugin-google-analytics/download/@vuepress/plugin-google-analytics-1.0.0-alpha.0.tgz#97acb3a512dca9b2b6e4014fa2d58da38e2a01b9"
883+
integrity sha1-l6yzpRLcqbK25AFPotWNo44qAbk=
884+
880885
"@vuepress/plugin-last-updated@^1.0.0-alpha.32":
881886
version "1.0.0-alpha.32"
882887
resolved "http://registry.npm.taobao.org/@vuepress/plugin-last-updated/download/@vuepress/plugin-last-updated-1.0.0-alpha.32.tgz#39da3be9e3976b062a09e36f835c8719220db825"

0 commit comments

Comments
 (0)