vuepress-plugin-twikoo 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/Comment.vue +4 -35
  2. package/package.json +1 -1
package/Comment.vue CHANGED
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div id="tcomment"></div>
2
+ <div id="twikoo"></div>
3
3
  </template>
4
4
 
5
5
  <script>
@@ -39,19 +39,12 @@ export default {
39
39
  return;
40
40
  }
41
41
 
42
- // 第一步:带重试查找 #tcomment 容器(解决 DOM 渲染慢的问题)
43
- const tcommentEl = await this.findElementWithRetry('#tcomment', 20, 100);
44
- if (!tcommentEl) {
45
- console.error('多次重试后仍未找到 #tcomment 容器,Twikoo 初始化失败');
46
- return;
47
- }
48
-
49
42
  // 异步加载 Twikoo 并初始化
50
43
  const twikoo = await import('twikoo');
51
44
  // 初始化后返回 Promise,确保 DOM 生成完成
52
45
  await twikoo.init({
53
46
  ...TWIKOO_OPTIONS,
54
- el: TWIKOO_OPTIONS.el || '#tcomment'
47
+ el: TWIKOO_OPTIONS.el || '#twikoo'
55
48
  });
56
49
 
57
50
  this.moveContainerWithRetry();
@@ -68,7 +61,7 @@ export default {
68
61
  const targetContainer = document.querySelector(TWIKOO_CONTAINER);
69
62
  if (!targetContainer) return; // 目标容器不存在则返回
70
63
 
71
- const commentContainer = document.querySelector(TWIKOO_OPTIONS.el);
64
+ const commentContainer = document.querySelector(TWIKOO_OPTIONS.el || '#twikoo');
72
65
  if (commentContainer) {
73
66
  targetContainer.appendChild(commentContainer);
74
67
  return true; // 移动成功,返回 true
@@ -86,7 +79,7 @@ export default {
86
79
 
87
80
  // 移动成功 或 达到最大重试次数,终止重试
88
81
  if (success || retries >= maxRetries) {
89
- if (!success) console.warn('Twikoo 容器移动失败:未找到 .tk-comments 元素');
82
+ if (!success) console.warn('Twikoo 容器移动失败:未找到 Twikoo 评论容器元素');
90
83
  return;
91
84
  }
92
85
 
@@ -97,30 +90,6 @@ export default {
97
90
  retry();
98
91
  },
99
92
 
100
- // 新增:通用的「带重试查找 DOM 元素」函数(可复用)
101
- findElementWithRetry(selector, maxRetries = 20, interval = 100) {
102
- return new Promise((resolve) => {
103
- let retries = 0;
104
-
105
- const checkElement = () => {
106
- const el = document.querySelector(selector);
107
- retries++;
108
-
109
- // 找到元素 或 达到最大重试次数,终止并返回结果
110
- if (el || retries >= maxRetries) {
111
- resolve(el);
112
- return;
113
- }
114
-
115
- // 未找到则继续重试
116
- setTimeout(checkElement, interval);
117
- };
118
-
119
- // 立即执行第一次检查
120
- checkElement();
121
- });
122
- },
123
-
124
93
  }
125
94
  };
126
95
  </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vuepress-plugin-twikoo",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Twikoo comment plugin for vuepress 1.x",
5
5
  "main": "index.js",
6
6
  "scripts": {