移除内置:下决心移除内置,Memos 自定义,每个人使用习惯都不一样。

即刻短文

找到 layout > includes > page > says.pug,替换成以下代码:

layout/includes/page/says.pug
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
include ../widgets/page/banner
if theme.says.enable
#bber
section.timeline.page-1
ul.list.waterfall
case theme.says.style
when 1
script.
!async function () {
let aplayerRegex = /{aplayer,(.*?),(.*?)}/g;
let linkRegex = /(?<!!)\[([^\]]*)]\(([^)]*)\)/g;
let bilibiliRegex = /{bilibili,(.*?)}/g;
let playerRegex = /{player,(.*?)}/g;
let imageRegex = /!\[(.*?)]\((.*?)\)/g;
let contentRegex = /#.*?\s([^{\n]*)/g;

document.querySelector('.waterfall').innerHTML = '<i class="solitude st-loading-line"></i>'

await fetch("!{url_for(theme.says.link)}")
.then(res => res.json())
.then(data => {
let list = data.slice(0, !{theme.says.strip});
let aplayer = null;
let video = null;
let imageBox = null;

document.querySelector('.waterfall').innerHTML = list.map(item => {
aplayer = item.content.match(aplayerRegex);
aplayer = aplayer ? `<div class="bber-music"><meting-js server="${aplayer[0].replace(aplayerRegex, '$1')}" type="song" id="${aplayer[0].replace(aplayerRegex, '$2')}" mutex="true" preload="none" theme="var(--efu-main)" data-lrctype="0"></meting-js></div>` : null;
video = item.content.match(playerRegex);
video = video ? `<div class="bber-video"><video src="${video[0].replace(playerRegex, '$1')}" controls="controls" style="object-fit: cover;"></video></div>` : item.content.match(bilibiliRegex);
video = item.content.match(bilibiliRegex) ? `<div class="bber-video"><iframe src="//player.bilibili.com/player.html?autoplay=0&bvid=${video[0].replace(bilibiliRegex, '$1')}" scrolling="no" bozrder="0" frameborder="no" framespacing="0" allowfullscreen="true"></iframe></div>` : video;
imageBox = item.content.match(imageRegex);
imageBox = imageBox ? `<div class="bber-content-img">${imageBox.map(img => `<img src="${img.replace(imageRegex, '$2')}" alt="${img.replace(imageRegex, '$1')}" />`).join('')}</div>` : '';
let time = new Date(item.createdTs * 1000).toString().replace('Z', '08:00');
let content = item.content.match(contentRegex).map(item => item.replace(contentRegex, '$1'));
let link = item.content.match(linkRegex);
link = link ? `<a class="bber-content-link" href='${link[0].replace(linkRegex, '$2')}' title="${link[0].replace(linkRegex, '$1')}" target="_blank"><i class="solitude st-link-m-line"></i>链接</a>` : '';
return `<li class="item">
<div id="bber-content">
<p class="datacont">${content}</p>
${imageBox || ''}
</div>
${video || ''}
${aplayer || ''}
<hr>
<div class="bber-bottom">
<div class="bber-info">
<div class="bber-info-time">
<i class="solitude st-calendar-todo-fill"></i>
<time class="datetime" datetime="${time}"></time>
</div>
${link}
</div>
${content ? `<a class="bber-reply goComment" onclick="sco.toTalk('${content}')"><i class="solitude st-chat-fill" style="font-size: 1rem;"></i></a>` : ''}
</div>
</li>`;
}).join('');
}).catch(error => console.log(error));
}();
when 2
script.
!async function () {
let aplayerRegex = /{aplayer,(.*?),(.*?)}/g;
let bilibiliRegex = /{bilibili,(.*?)}/g;
let playerRegex = /{player,(.*?)}/g;
let imageRegex = /!\[(.*?)]\((.*?)\)/g;
let contentRegex = /#.*?\s([^{\n]*)/g;

const waterfall = document.querySelector('.waterfall')

waterfall.innerHTML = '<li class="item"><i class="solitude st-loading-line"></i></li>'

await fetch("!{url_for(theme.says.link)}")
.then(res => res.json())
.then(data => {
let list = data.slice(0, !{theme.says.strip})
let aplayer = null;
let video = null;
let imageBox = null;

waterfall.innerHTML = list.map(item => {
aplayer = item.content.match(aplayerRegex);
aplayer = aplayer ? `<div class="bber-music"><meting-js server="${aplayer[0].replace(aplayerRegex, '$1')}" type="song" id="${aplayer[0].replace(aplayerRegex, '$2')}" mutex="true" preload="none" theme="var(--efu-main)" data-lrctype="0"></meting-js></div>` : null;
video = item.content.match(playerRegex);
video = video ? `<div class="bber-video"><video src="${video[0].replace(playerRegex, '$1')}" controls="controls" style="object-fit: cover;"></video></div>` : item.content.match(bilibiliRegex);
video = item.content.match(bilibiliRegex) ? `<div class="bber-video"><iframe src="//player.bilibili.com/player.html?autoplay=0&bvid=${video[0].replace(bilibiliRegex, '$1')}" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"></iframe></div>` : video;
imageBox = item.content.match(imageRegex);
imageBox = imageBox ? `<div class="bber-content-img">${imageBox.map(img => `<img src="${img.replace(imageRegex, '$2')}" alt="${img.replace(imageRegex, '$1')}" />`).join('')}</div>` : '';
let time = new Date(item.createdTs * 1000).toString().replace('Z', '08:00');
let content = item.content.match(contentRegex).map(item => item.replace(contentRegex, '$1'));
return `<li class="item">
<div class="meta">
<img class="no-lightbox nolazyload avatar" src="!{theme.aside.card.author.img}">
<div class="info">
<span class="bber_nick">#{config.author}</span>
<time class="datetime bber_date" datetime="${time}"></time>
</div>
${content ? `<a class="bber-reply goComment" onclick="sco.toTalk('${content}')"><i class="solitude st-chat-fill" style="font-size: 1rem;"></i></a>` : ''}
</div>
<div id="bber-content">
<p class="datacont">${content}</p>
${imageBox || ''}
</div>
${video || ''}
${aplayer || ''}
</li>`
}).join('');
}).catch(error => console.log(error));
}();
#bber-tips
if theme.says.strip === -1
| - 已展开所有短文 -
else
| - 只展示最近 #{theme.says.strip} 条短文 -

修改 layout > includes > inject > body.pug

预计在 109 行的位置。

1
2
3
4
5
6
7
8
9
10
if page.type === 'says' && theme.says.enable
script.
- GLOBAL_CONFIG.lightbox && utils.lightbox(document.querySelectorAll(".bber-content-img img"));
- sco.changeTimeFormat(document.querySelectorAll('.bber-info-time time'))
setTimeout(() => {
sco.refreshWaterFall();
GLOBAL_CONFIG.lazyload.enable && utils.lazyloadImg();
GLOBAL_CONFIG.lightbox && utils.lightbox(document.querySelectorAll(".bber-content-img img"));
sco.changeTimeFormat(document.querySelectorAll('.info time'));
}, 500)

首页即刻短文条

找到 layout > includes > widgets > home > bbTimeList.pug,替换成以下代码:

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
.bbTimeList.container#bbTimeList(class=is_home_first_page() ? '' : 'more-page')
i.bber-logo.solitude.st-bblogo(onclick=`pjax.loadUrl('/essay/')`)
.swiper-container.swiper-no-swiping.swiper-container-initialized.swiper-container-vertical.swiper-container-pointer-events#bbtalk(tabindex="-1" onclick=`pjax.loadUrl('/essay/')`)
.swiper-wrapper#bber-talk
script.
async function getSays() {
const talk = document.querySelector('#bber-talk')
if (talk === null) return
talk.innerHTML = '<div class="li-style swiper-slide"><i class="solitude st-loading-line"></i></div>'
await fetch('!{theme.says.link}')
.then(response => response.json())
.then(data => {
let aplayerRegex = /{aplayer,(.*?),(.*?)}/g;
let bilibiliRegex = /{bilibili,(.*?)}/g;
let playerRegex = /{player,(.*?)}/g;
let linkRegex = /(?<!\!)\[([^\]]*)\]\(([^\)]*)\)/g;
let imageRegex = /!\[(.*?)]\((.*?)\)/g;
let contentRegex = /#.*?\s([^{\n]*)/g
const list = data.slice(0, 10)
document.querySelector('#bber-talk').innerHTML = list.map(item => {
let content = item.content.match(contentRegex, '$1').map(item => item.replace(contentRegex, '$1'));
let imageBox = item.content.match(imageRegex) ? '<i class="solitude st-image-fill"></i>' : '';
let aplayer = item.content.match(aplayerRegex) ? '<i class="solitude st-disc-fill"></i>' : '';
let video = item.content.match(playerRegex) ? '<i class="solitude st-video-fill"></i>' : item.content.match(bilibiliRegex) ? '<i class="solitude st-bilibili-line"></i>' : '';
let link = item.content.match(linkRegex) ? `<i class="solitude st-link"></i>` : '';
return `<div class="li-style swiper-slide">${content + aplayer + video + imageBox + link}</div>`
}).join(' ')
setTimeout(() => {
sco.initbbtalk()
}, 500)
})
.catch(error => console.error('bbtime | ', error));
}
document.addEventListener('DOMContentLoaded', getSays)
document.addEventListener('pjax:complete', getSays)
i.bber-gotobb.solitude.st-right-btn-fill(title=_p('home.bbtime.text') onclick=`pjax.loadUrl('/essay/')`)

配置文件

找到 says,添加:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 即刻短文
# talk now
# 前置要求:需配置即刻短文页面
# Pre-requirements: talk now page needs to be configured
says:
enable: false
# 主页的即刻轮播条
# Talk carousel bar on the homepage
home_mini: false
# 1:张洪heo样式 / 2:Leonus样式
# 1: Zhang Hong heo style / 2: Leonus style
style: 1
# 即刻短文仅展示前n条
# Talk short text only shows the first n
strip: 30
+ link: # 你的 memos 部署地址,例如: https://example.com/api/v1/memo?creatorId=1&tag=says

creatorId: 设置 > 成员 > 成员列表 > 你的 ID
tag: 写即刻短文的标签

在 Memos 写即刻

#says 是确认短文的标签,可以自己改
格式:

1
2
3
4
5
#says testtest
[link](url)
![image](url)
{aplayer,netease,id}
{bilibili,bvid}

文字不要留空格,不要回车,一行写下去。

进阶

有能力可以自己修改,使用正则表达式获取内容然后替换。

1
2
3
4
5
6
let aplayerRegex = /{aplayer,(.*?),(.*?)}/g;
let linkRegex = /(?<!\!)\[([^\]]*)\]\(([^\)]*)\)/g;
let bilibiliRegex = /{bilibili,(.*?)}/g;
let playerRegex = /{player,(.*?)}/g;
let imageRegex = /!\[(.*?)]\((.*?)\)/g;
let contentRegex = /#.*?\s([^{\n]*)/g;