前言

友链朋友圈是一个可以聚合友链博客文章的功能,可以让我们及时了解到博友们的最新动态。然而原版的友链朋友圈因为功能复杂,部署较为麻烦,且前端文件体积较大,加载速度较慢。

本文将介绍如何部署轻量化友链朋友圈 Friend-Circle-Lite,它具有以下特点:

  • 轻量化:前端文件仅5.5KB
  • 无数据库:使用JSON直接存储文章信息,减少数据库操作
  • 部署简单:仅需简单的GitHub Actions配置即可使用
  • 功能齐全:实现了友链文章展示、随机文章、暗色适配等核心功能

预览页面: 朋友圈 | Yeppioo

基本原理

鱼塘朋友圈(Friend-Circle-Lite)的工作原理如下:

  1. 通过GitHub Actions定时爬取所有友链的文章
  2. 将爬取结果保存为JSON文件并提交到仓库
  3. 通过静态网站部署服务(如Vercel)部署前端页面
  4. 前端页面从JSON文件中获取文章数据并展示

这种设计使得整个系统非常轻量,无需服务器和数据库,完全依靠GitHub Actions和静态网站服务即可实现。

部署步骤

准备友链JSON文件

首先,我们需要准备友链数据的JSON文件。如果你使用的是Butterfly主题,可以通过以下方式生成:

安装依赖

1
npm install yamljs --save

在博客根目录创建link.cjs文件,写入以下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const YML = require('yamljs')
const fs = require('fs')

const blacklist = ["友站名称1", "友站名称2", "友站名称3"]; // 由于某种原因,不想订阅的列表

let friends = [],
data_f = YML.parse(fs.readFileSync('source/_data/link.yml').toString().replace(/(?<=rss:)\s*\n/g, ' ""\n'));

data_f.forEach((entry, index) => {
let lastIndex = 999;
if (index < lastIndex) {
const filteredLinkList = entry.link_list.filter(linkItem => !blacklist.includes(linkItem.name));
friends = friends.concat(filteredLinkList);
}
});

// 根据规定的格式构建 JSON 数据
const friendData = {
friends: friends.map(item => {
return [item.name, item.link, item.avatar];
})
};

// 将 JSON 对象转换为字符串
const friendJSON = JSON.stringify(friendData, null, 2);

// 写入 friend.json 文件
fs.writeFileSync('./source/friend.json', friendJSON);

console.log('friend.json 文件已生成。');

然后在终端执行:

1
node link.js

这将在source目录下生成friend.json文件,文件格式如下:

1
2
3
4
5
6
7
8
9
10
{
"friends": [
[
"博主名称",
"https://blog.example.com/",
"https://blog.example.com/avatar.jpg"
],
...
]
}

执行hexo ghexo d后,这个文件将会被部署到你的网站,可以通过https://你的网站/friend.json访问。

如果使用GitHub Actions自动部署博客,可以在部署脚本中添加生成friend.json的步骤:

1
2
3
4
- name: Generate friend.json
run: |
npm install yamljs
node link.js

配置GitHub Actions

Fork仓库

首先,Fork Friend-Circle-Lite 仓库到你的GitHub账号下。

配置Secrets

如果不需要邮件通知功能以下可不做

在Fork的仓库中,依次进入 Settings -> Secrets -> Actions,添加以下Secret:

  • SMTP_PWD: SMTP服务器的密码,用于发送邮件通知(如果需要邮件通知功能)

配置Action权限

在仓库的Settings -> Actions -> General页面底部,选择Read and write permissions选项并保存,确保GitHub Actions有读写权限。

修改配置文件

编辑Friend-Circle-Lite仓库中的config.yaml文件,主要配置以下部分:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 爬虫相关配置
spider_settings:
enable: true
json_url: "https://你的网站/friend.json" # 填写你的friend.json地址
article_count: 5 # 每个作者保留的文章数量
merge_result:
enable: false # 是否合并多个数据源

# 邮箱issue订阅功能(可选)
rss_subscribe:
enable: true # 是否启用邮箱订阅
github_username: your-username # 你的GitHub用户名
github_repo: Friend-Circle-Lite # 仓库名称
your_blog_url: https://your-blog.com/ # 你的博客地址

# SMTP配置(如果需要邮件通知)
smtp:
email: your-email@example.com
server: smtp.example.com
port: 587
use_tls: true

前端部署

有两种方式部署前端:

静态网站服务部署

将仓库的page分支部署到Vercel、Zeabur或Cloudflare Pages等静态网站服务。

以Vercel为例:

  1. 在Vercel中导入Fork的仓库
  2. 将构建分支设置为page分支
vercel-1 vercel-2

嵌入到博客页面

在博客中创建一个页面(如source/fcircle/index.md),内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
---
title: 友链朋友圈
date: 2024-11-10
type: "fcircle"
comments: true
---

<div id="friend-circle-lite-root"></div>
<script>
if (typeof UserConfig === 'undefined') {
var UserConfig = {
// 填写你的fc Lite地址
private_api_url: 'https://fc.liushen.fun/',
// 点击加载更多时,一次最多加载几篇文章,默认20
page_turning_number: 24,
// 头像加载失败时,默认头像地址
error_img: 'https://pic.imgdb.cn/item/6695daa4d9c307b7e953ee3d.jpg',
}
}
</script>
<link rel="stylesheet" href="https://fastly.jsdelivr.net/gh/willow-god/Friend-Circle-Lite/main/fclite.min.css">
<script src="https://fastly.jsdelivr.net/gh/willow-god/Friend-Circle-Lite/main/fclite.min.js"></script>

运行测试

完成配置后,你可以手动运行GitHub Actions来测试爬取功能:

  1. 在仓库的Actions标签页中找到Friend Circle Lite工作流
  2. 点击Run workflow手动触发
  3. 检查运行结果,查看是否成功爬取文章并生成all.json文件

如果一切正常,访问你部署的前端页面或博客中嵌入的友链朋友圈页面,应该能看到友链文章展示。

自用样式

以下是站长自用样式,你可以根据需要自行修改。

引入后替换markdown页面的CSS和JS即可。

1
2
<link rel="stylesheet" href="fclite.css">
<script src="fclite.js"></script>

fclite.css

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
:root {
--text-color-light: #000000;
--text-color-dark: #f7f7fa;
--background-color-light: #f4f4f9;
--background-color-dark: #181818;
--container-bg-color-light: white;
--container-bg-color-dark: #1d1e22;
--hover-color: #3498db;
--author-color-light: gray;
--author-color-dark: #b3b3b3;
--modal-bg-blur: 25px;
--shadow-color-light: rgba(0, 0, 0, 0.1);
--shadow-color-dark: rgba(255, 255, 255, 0.1);
--border-color-light: #e3e8f7;
--border-color-dark: #42444a;
}

[data-theme="light"] {
--text-color: var(--text-color-light);
--background-color: var(--background-color-light);
--tag-bg-color: #bfbfbf;
--container-bg-color: var(--container-bg-color-light);
--author-color: var(--author-color-light);
--shadow-color: var(--shadow-color-light);
--border-color: var(--border-color-light);
--modal-bg-color: rgba(255, 255, 255, 0.5);
--modal-content-bg-color: rgba(239, 250, 255, 0.5);
--load-more-btn-bg-color: var(--container-bg-color);
}

[data-theme="dark"] {
--text-color: var(--text-color-dark);
--background-color: var(--background-color-dark);
--tag-bg-color: #474747;
--container-bg-color: var(--container-bg-color-dark);
--author-color: var(--author-color-dark);
--shadow-color: var(--shadow-color-dark);
--border-color: var(--border-color-dark);
--modal-bg-color: rgba(0, 0, 0, 0.3);
--modal-content-bg-color: rgba(20, 20, 20, 0.5);
--load-more-btn-bg-color: var(--container-bg-color);
}

#friend-circle-lite-root {
width: 100%;
}

#random-article {
display: block;
position: relative;
width: 100%;
margin: 8px 0;
}

.random-container {
position: relative;
margin: 20px;
width: 90%;
margin-bottom: 6px;
}

/* .random-container:hover .random-title {
font-size: 28px;
} */

.random-author {
font-size: 14px;
color: var(--author-color);
margin-top: 15px;
}

.random-container-title {
display: none;
}

.random-title {
margin-bottom: 5px;
font-size: 16px;
transition: font-size 0.3s ease-in-out;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: block;
}

.random-button-container {
position: absolute;
bottom: 20px;
right: 20px;
border: none;
border-radius: 20px;
cursor: pointer;
font-size: 14px;
transition: background-color 0.3s ease-in-out;
}

.random-button-container a {
margin-right: 10px;
color: #aaa !important;
text-decoration: none !important;
}

.random-link-button {
padding: 10px 20px;
border: none;
border-radius: 20px;
background-color: var(--hover-color);
color: #fff;
cursor: pointer;
font-size: 14px;
transition: background-color 0.3s ease-in-out;
}

.modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: var(--modal-bg-color);
backdrop-filter: blur(var(--modal-bg-blur));
-webkit-backdrop-filter: blur(var(--modal-bg-blur));
z-index: 999;
opacity: 0;
visibility: hidden;
transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
}

.modal-open {
opacity: 1;
visibility: visible;
}

.modal-content {
opacity: 0;
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) translateY(-50px);
width: 350px;
background-color: var(--modal-content-bg-color);
padding: 20px;
border: 1px solid var(--border-color);
z-index: 1000;
max-height: 90%;
overflow: hidden;
border-radius: 20px;
transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out;
}

.modal.modal-open .modal-content {
transform: translate(-50%, -50%) translateY(0);
opacity: 1;
}

.modal-content:hover #modal-bg {
transform: scale(1.1);
}

@media screen and (max-width: 440px) {
.modal-content {
width: 80%;
}
}

#modal-bg {
position: absolute;
filter: blur(5px);
opacity: 0.2;
z-index: 0;
border-radius: 125px 125px 12px 125px !important;
margin: 0 !important;
width: 250px;
height: 250px;
right: -20px;
bottom: -20px;
transition: transform 0.6s ease !important;
}

#modal-author-avatar {
display: block;
margin: 5px auto !important;
border-radius: 50% !important;
width: 110px;
height: 110px;
}

#modal-author-name-link {
display: block;
text-align: center;
font-size: 15px;
margin: 15px 0;
color: var(--hover-color);
text-decoration: none;
}

#modal-author-name-link:hover {
text-decoration: underline;
}

.modal-content hr {
margin: 20px 0;
}

#modal-articles-container {
position: relative;
z-index: 1;
border-top: var(--hover-color) double 2px;
margin-top: 20px;
padding-top: 10px;
}

.modal-article {
display: flex;
flex-wrap: wrap;
margin-bottom: 10px;
padding-bottom: 10px;
border-bottom: var(--hover-color) dashed 1px;
}

.modal-article .modal-article-title {
color: var(--text-color);
font-size: 18px;
line-height: 1.2;
cursor: pointer;
max-height: 2.5em;
width: 100%;
margin-bottom: 5px;
text-decoration: none;
display: -webkit-box;
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}

.modal-article .modal-article-title:hover {
color: var(--hover-color);
text-decoration: underline;
}

.modal-article .modal-article-date {
font-size: 12px;
width: 100%;
color: var(--author-color);
padding: 5px;
cursor: default;
text-align: right;
}

.articles-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
gap: 14px;
top: 8px;
width: 100%;
position: relative;
}

.card {
background-color: var(--container-bg-color);
border-radius: 10px;
padding: 10px;
border: 1px solid var(--border-color);
position: relative;
overflow: hidden;
display: flex;
flex-direction: column;
justify-content: space-between;
height: 98px;
transition: border 0.3s;
}

/* #random-article:hover, */
.card:hover {
border: 1px solid var(--hover-color);
}

.card-title {
z-index: 1;
font-size: 17px;
color: var(--font-color) !important;
font-weight: 520;
cursor: pointer;
margin-bottom: 10px;
line-height: 1.5;
max-height: 4.5em;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 3;
line-clamp: 3;
-webkit-box-orient: vertical;
transition: color 0.3s;
}

.card-title:hover {
color: #49b1f5 !important;
text-decoration: underline;
}

img.card-bg.no-lightbox {
display: none !important;
}

.card-title {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
line-clamp: 2;
line-height: 20px;
max-height: 100px;
}

.card-author,
.card-date {
font-size: 12px;
color: var(--author-color);
padding: 5px;
line-height: 15px;
}

.card-author:hover {
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.card-author {
cursor: pointer;
background-color: var(--background-color);
border: 1px solid var(--border-color);
border-radius: 15px;
display: flex;
padding-right: 10px;
width: fit-content;
align-items: center;
transition: box-shadow 0.2s;
}

#friend-circle-lite-root .card-author img {
border-radius: 50%;
width: 15px;
height: 15px;
margin: 0 2px !important;
object-fit: cover;
}

.card-date {
position: absolute;
z-index: 1;
bottom: 10px;
cursor: default;
right: 10px;
display: flex;
align-items: center;
}

#friend-circle-lite-root .card-bg {
cursor: default;
z-index: 0;
border-radius: 50% !important;
margin: 0 !important;
position: absolute;
bottom: -20px;
right: -16px;
width: 140px;
height: 140px;
opacity: 0.4;
transition: transform 0.6s ease, bottom 0.3s ease, right 0.3s ease;
}

#friend-circle-lite-root .card:hover .card-bg {
transform: scale(1.1);
bottom: -10px;
right: -8px;
}

#load-more-btn {
color: var(--font-color);
font-size: 15px;
background-color: var(--container-bg-color);
cursor: pointer;
width: 200px;
border-radius: 10px;
border: 1px solid var(--border-color);
padding: 3px;
transition: all 0.3s;
margin: 20px auto;
display: block;
}

#load-more-btn:hover {
color: #fff;
}

#stats-container {
font-size: 13px;
text-align: right;
margin-top: 20px;
}

#stats-container>* {
margin-bottom: 3px;
}

#stats-container a {
color: var(--author-color);
text-decoration: none;
}

/*# sourceMappingURL=/sm/8a7b3319c1fa5f2b20a1aa3af06889643bf41f81ac58bb7137136950dcdbeb11.map */
#random-article {
margin-top: 27px;
}

.random-author {
position: relative;
margin-top: -27px;
color: var(--author-color);
font-size: 13px;
}

.random-container-title {
margin: 0;
}

.random-title {
position: relative;
top: -17px;
left: -6px;
}

#refresh-random-article {
margin-left: 5px;
color: var(--author-color);
transition: color 0.3s;
}

#refresh-random-article:hover {
color: var(--hover-color);
}

#load-more-btn {
max-width: 812px;
width: 40% !important;
transition: 0.3s;
height: 30px;
line-height: 2;
-webkit-tap-highlight-color: transparent;
font-family: customFont;
overflow-wrap: break-word;
scrollbar-width: thin;
box-sizing: border-box;
width: 40%;
max-width: 810px;
height: 30px;
margin: auto;
margin-top: 2rem;
border-radius: 12px;
font-weight: bolder;
text-align: center;
display: flex;
flex-direction: column;
justify-content: space-around;
cursor: pointer;
transition: 1s;
align-items: center;
}

#load-more-btn:hover {
width: 95% !important;
background: #49b1f5;
/* width: 60%; */
}

.random-section-title {
font-size: 20px;
font-weight: 700;
margin-bottom: 10px;
color: var(--font-color);
margin-top: 20px;
margin-left: 10px;
}

.random-article-container {
display: flex;
position: relative;
width: 100%;
margin: 8px 0;
background-color: var(--container-bg-color);
border-radius: 10px;
border: 1px solid var(--border-color);
transition: border 0.3s;
}

.random-article-container:hover {
border: 1px solid var(--hover-color);
}

fclite.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
function initialize_fc_lite() {
UserConfig = { private_api_url: UserConfig?.private_api_url || "", page_turning_number: UserConfig?.page_turning_number || 20, error_img: UserConfig?.error_img || "https://fastly.jsdelivr.net/gh/willow-god/Friend-Circle-Lite@latest/static/favicon.ico" };
const e = document.getElementById("friend-circle-lite-root");
if (!e) return;
e.innerHTML = "";
var newElement = document.createElement("i");
newElement.className = "fas fa-angle-double-down";
const n = document.createElement("div");
(n.id = "random-article"), e.appendChild(n);
const t = document.createElement("div");
(t.className = "articles-container"), (t.id = "articles-container"), e.appendChild(t);
const i = document.createElement("button");
(i.id = "load-more-btn"), (i.appendChild(newElement)), e.appendChild(i);
const a = document.createElement("div");
(a.id = "stats-container"), e.appendChild(a);
let r = 0,
o = [];
function d() {
const e = "friend-circle-lite-cache",
n = "friend-circle-lite-cache-time",
t = localStorage.getItem(n),
a = new Date().getTime();
if (t && a - t < 6e5) {
const n = JSON.parse(localStorage.getItem(e));
if (n) return void l(n);
}
fetch(`${UserConfig.private_api_url}all.json`)
.then((e) => e.json())
.then((t) => {
localStorage.setItem(e, JSON.stringify(t)), localStorage.setItem(n, a.toString()), l(t);
})
.finally(() => {
i.appendChild(newElement)
});
}
function l(n) {
o = n.article_data;
const d = n.statistical_data;
(a.innerHTML = `\n <div>Powered by: <a href="https://github.com/willow-god/Friend-Circle-Lite" target="_blank">FriendCircleLite</a><br></div>\n <div>Designed By: <a href="https://yeppioo.vip/" target="_blank">Yeppioo</a><br></div>\n <div>订阅:${d.friends_num} 活跃:${d.active_num} 总文章数:${d.article_num}<br></div>\n <div>更新时间:${d.last_updated_time}</div>\n `), c();
o.slice(r, r + UserConfig.page_turning_number).forEach((n) => {
const i = document.createElement("div");
i.className = "card";
const a = document.createElement("a");
(a.className = "card-title"), (a.innerText = n.title), i.appendChild(a), (a.onclick = () => window.open(n.link, "_blank"));
const r = document.createElement("div");
r.className = "card-author";
const d = document.createElement("img");
(d.className = "no-lightbox"),
(d.src = n.avatar || UserConfig.error_img),
(d.onerror = () => (d.src = UserConfig.error_img)),
r.appendChild(d),
r.appendChild(document.createTextNode(n.author)),
i.appendChild(r),
(r.onclick = () => {
!(function (n, t, i) {
if (!document.getElementById("fclite-modal")) {
const n = document.createElement("div");
(n.id = "modal"), (n.className = "modal"), (n.innerHTML = '\n <div class="modal-content">\n <img id="modal-author-avatar" src="" alt="">\n <a id="modal-author-name-link"></a>\n <div id="modal-articles-container"></div>\n <img id="modal-bg" src="" alt="">\n </div>\n '), e.appendChild(n);
}
const a = document.getElementById("modal"),
r = document.getElementById("modal-articles-container"),
d = document.getElementById("modal-author-avatar"),
l = document.getElementById("modal-author-name-link"),
c = document.getElementById("modal-bg");
(r.innerHTML = ""), (d.src = t || UserConfig.error_img), (d.onerror = () => (d.src = UserConfig.error_img)), (c.src = t || UserConfig.error_img), (c.onerror = () => (c.src = UserConfig.error_img)), (l.innerText = n), (l.href = new URL(i).origin);
const s = o.filter((e) => e.author === n);
s.slice(0, 4).forEach((e) => {
const n = document.createElement("div");
n.className = "modal-article";
const t = document.createElement("a");
(t.className = "modal-article-title"), (t.innerText = e.title), (t.href = e.link), (t.target = "_blank"), n.appendChild(t);
const i = document.createElement("div");
(i.className = "modal-article-date"), (i.innerText = "📅" + e.created.substring(0, 10)), n.appendChild(i), r.appendChild(n);
}),
(a.style.display = "block"),
setTimeout(() => {
a.classList.add("modal-open");
}, 10);
})(n.author, n.avatar, n.link);
});
const l = document.createElement("div");
(l.className = "card-date"), (l.innerText = "🗓️" + n.created.substring(0, 10)), i.appendChild(l);
const c = document.createElement("img");
(c.className = "card-bg no-lightbox"), (c.src = n.avatar || UserConfig.error_img), (c.onerror = () => (c.src = UserConfig.error_img)), i.appendChild(c), t.appendChild(i);
}),
(r += UserConfig.page_turning_number),
r >= o.length && (i.style.display = "none");
}
function c() {
const e = o[Math.floor(Math.random() * o.length)];
n.innerHTML = `
<p class="random-section-title">🎣 随机钓鱼 <a href="#" id="refresh-random-article"><i class="fa-solid fa-arrow-rotate-right"></i></a></p>
<div class="random-article-container">
<div class="random-container">
<a target="_blank" href="${e.link}" class="random-title">${e.title}</a>
<div class="random-author">作者: ${e.author}</div>
</div>
</div>`;
document.getElementById("refresh-random-article").addEventListener("click", function (e) {
e.preventDefault(), c();
});
}
d(),
i.addEventListener("click", d),
(window.onclick = function (n) {
const t = document.getElementById("modal");
n.target === t &&
(function () {
const n = document.getElementById("modal");
n.classList.remove("modal-open"),
n.addEventListener(
"transitionend",
() => {
(n.style.display = "none"), e.removeChild(n);
},
{ once: !0 }
);
})();
});
}
function whenDOMReady() {
initialize_fc_lite();
}
whenDOMReady(), document.addEventListener("pjax:complete", initialize_fc_lite);
//# sourceMappingURL=/sm/e243e0b6036d5f901c776acc4d38a86765c31647dbd80766f36329f4505bf6a6.map



扩展功能

提供了获取所有文章和随机文章的两个函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const yeppioo = {
getRandomFishArticle: function () {
// 获取鱼塘文章缓存
const cacheKey = "friend-circle-lite-cache";
const cacheTimeKey = "friend-circle-lite-cache-time";
const cachedData = localStorage.getItem(cacheKey);
const cachedTime = localStorage.getItem(cacheTimeKey);
const currentTime = new Date().getTime();

// 检查缓存是否有效(10分钟内)
if (cachedTime && currentTime - cachedTime < 600000 && cachedData) {
try {
const articleData = JSON.parse(cachedData).article_data;
if (articleData && articleData.length > 0) {
// 随机选择一篇文章
const randomArticle = articleData[Math.floor(Math.random() * articleData.length)];
return {
success: true,
data: randomArticle
};
}
} catch (error) {
console.error("解析鱼塘缓存数据失败", error);
return {
success: false,
message: "解析鱼塘缓存数据失败"
};
}
}

// 如果缓存无效或没有数据,尝试获取数据
return this.fetchFishData().then(result => {
if (result.success && result.data.article_data && result.data.article_data.length > 0) {
const articleData = result.data.article_data;
const randomArticle = articleData[Math.floor(Math.random() * articleData.length)];
return {
success: true,
data: randomArticle
};
} else {
return {
success: false,
message: "获取鱼塘数据失败"
};
}
});
},
getAllFishArticles: function () {
// 获取鱼塘所有文章数据
const cacheKey = "friend-circle-lite-cache";
const cacheTimeKey = "friend-circle-lite-cache-time";
const cachedData = localStorage.getItem(cacheKey);
const cachedTime = localStorage.getItem(cacheTimeKey);
const currentTime = new Date().getTime();

if (cachedTime && currentTime - cachedTime < 600000 && cachedData) {
try {
const parsedData = JSON.parse(cachedData);
return {
success: true,
data: parsedData.article_data || [],
stats: parsedData.statistical_data || {}
};
} catch (error) {
console.error("解析鱼塘缓存数据失败", error);
return {
success: false,
message: "解析鱼塘缓存数据失败"
};
}
}

// 如果缓存无效或没有数据,尝试获取数据
return this.fetchFishData().then(result => {
if (result.success) {
return {
success: true,
data: result.data.article_data || [],
stats: result.data.statistical_data || {}
};
} else {
return {
success: false,
message: "获取鱼塘数据失败"
};
}
});
},
fetchFishData: function () {
if (typeof UserConfig === 'undefined') {
var UserConfig = {
// 填写你的fc Lite地址
private_api_url: 'https://fcircle.api.yeppioo.vip/',
// 点击加载更多时,一次最多加载几篇文章,默认20
page_turning_number: 24,
// 头像加载失败时,默认头像地址
error_img: '/static/img/erravatar.png',
}
}
// 确保UserConfig已定义
if (typeof UserConfig === 'undefined' || !UserConfig.private_api_url) {
console.error("UserConfig未定义或API地址为空");
return Promise.resolve({
success: false,
message: "UserConfig未定义或API地址为空"
});
}

const cacheKey = "friend-circle-lite-cache";
const cacheTimeKey = "friend-circle-lite-cache-time";
const currentTime = new Date().getTime();

return fetch(`${UserConfig.private_api_url}all.json`)
.then(response => {
if (!response.ok) {
throw new Error("网络请求失败");
}
return response.json();
})
.then(data => {
// 保存到缓存
localStorage.setItem(cacheKey, JSON.stringify(data));
localStorage.setItem(cacheTimeKey, currentTime.toString());

return {
success: true,
data: data
};
})
.catch(error => {
console.error("获取鱼塘数据失败", error);
return {
success: false,
message: error.message || "获取鱼塘数据失败"
};
});
}
}


总结

鱼塘朋友圈(Friend-Circle-Lite)是一个轻量级的友链朋友圈解决方案,相比原版友链朋友圈,它部署更简单、加载更快、资源占用更少。通过本文的指导,你应该能够轻松地在自己的博客上部署和配置友链朋友圈功能。

希望这个工具能够帮助你更好地与博友互动,及时了解到博友们的最新动态!如有任何问题,欢迎在评论区留言或前往GitHub仓库提交Issue。