Skip to content

Commit 8ca92c9

Browse files
committed
feat: limit title length
1 parent 1a4120a commit 8ca92c9

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/adapters/baidu.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Baidu implements Adapter {
4646
if (data.error_code) {
4747
return this.parseError(data.error_code);
4848
}
49-
49+
5050
const { trans_result:result } = data;
5151
result.forEach(item => {
5252
const pronounce = this.isChinese ? item.dst : this.word;
@@ -76,6 +76,15 @@ class Baidu implements Adapter {
7676

7777
private addResult( title: string, subtitle: string, arg: string = "", pronounce: string = ""): Result[] {
7878
const quicklookurl = "https://fanyi.baidu.com/#auto/auto/" + this.word;
79+
80+
const maxLength = this.detectChinese(title) ? 27 : 60;
81+
82+
if (title.length > maxLength) {
83+
const copy = title;
84+
title = copy.slice(0, maxLength);
85+
subtitle = copy.slice(maxLength);
86+
}
87+
7988
this.results.push({ title, subtitle, arg, pronounce, quicklookurl });
8089
return this.results;
8190
}

src/adapters/youdao.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ class Youdao implements Adapter {
126126

127127
private addResult( title: string, subtitle: string, arg: string = "", pronounce: string = ""): Result[] {
128128
const quicklookurl = "https://www.youdao.com/w/" + this.word;
129+
130+
const maxLength = this.detectChinese(title) ? 27 : 60;
131+
132+
if (title.length > maxLength) {
133+
const copy = title;
134+
title = copy.slice(0, maxLength);
135+
subtitle = copy.slice(maxLength);
136+
}
137+
129138
this.results.push({ title, subtitle, arg, pronounce, quicklookurl });
130139
return this.results;
131140
}

0 commit comments

Comments
 (0)