Add option to set value for limiting title length (#671)

Related to #663
This commit is contained in:
Henry Wang 2018-09-10 08:00:08 +01:00 committed by DIYgod
parent 94434c10be
commit 8d1a071ab3
4 changed files with 8 additions and 3 deletions

View File

@ -11,6 +11,7 @@ module.exports = {
// 是否显示 Debug 信息,取值 boolean 'false' 'key' ,取值为 'false' false 时永远不显示,取值为 'key' 时带上 ?debug=key 显示
debugInfo: process.env.DEBUG_INFO || true,
sentry: process.env.SENTRY || '', // 使用 sentry 进行错误追踪,这里是 sentry 提供的 DSN 链接
titleLengthLimit: process.env.TITLE_LENGTH_LIMIT || 100,
redis: {
url: process.env.REDIS_URL || 'redis://localhost:6379/',
options: {

View File

@ -355,6 +355,8 @@ Use environment variables is recommended to avoid conflicts during upgrade.
`LISTEN_INADDR_ANY`: open up for external access, default to `1`
`TITLE_LENGTH_LIMIT`: limit the length of feed title generated in bytes, an English alphabet counts as 1 byte, the rest such as Chinese, Japanese, Korean or Arabic counts as 2 bytes by design, default to `100`
`REDIS_URL`: Redis target addressinvalid when `CACHE_TYPE` is set to memory, default to `redis://localhost:6379/`
`REDIS_PASSWORD`: Redis passwordinvalid when `CACHE_TYPE` is set to memory)

View File

@ -355,9 +355,11 @@ gcloud app deploy
`CACHE_TYPE`: 缓存类型, 可为 `memory``redis`, 设为空可以禁止缓存, 默认为 `memory`
`CACHE_EXPIRE`: 缓存过期时间, 单位为秒, 默认 300
`CACHE_EXPIRE`: 缓存过期时间, 单位为秒, 默认 `300`
`LISTEN_INADDR_ANY`: 是否允许公网连接, 默认 1
`LISTEN_INADDR_ANY`: 是否允许公网连接, 默认 `1`
`TITLE_LENGTH_LIMIT`: 限制输出标题的字节长度, 一个英文字符的长度为 1 字节, 部分语言如中文, 日文, 韩文或阿拉伯文等, 统一算作 2 字节, 默认 `100`
`REDIS_URL`: Redis 连接地址memory 缓存类型时无效), 默认为 `redis://localhost:6379/`

View File

@ -33,7 +33,7 @@ module.exports = async (ctx, next) => {
ctx.state.data.item.forEach((item) => {
for (let length = 0, i = 0; i < item.title.length; i++) {
length += Buffer.from(item.title[i]).length !== 1 ? 2 : 1;
if (length > 100) {
if (length > config.titleLengthLimit) {
item.title = `${item.title.slice(0, i)}...`;
break;
}