From 8d1a071ab343d5ea2e8a499f3e99ee5724e64d45 Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Mon, 10 Sep 2018 08:00:08 +0100 Subject: [PATCH] Add option to set value for limiting title length (#671) Related to #663 --- config.js | 1 + docs/en/install/README.md | 2 ++ docs/install/README.md | 6 ++++-- middleware/template.js | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/config.js b/config.js index fb5cf4508..92f819fad 100644 --- a/config.js +++ b/config.js @@ -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: { diff --git a/docs/en/install/README.md b/docs/en/install/README.md index d1d61e7c0..9ce0fd568 100644 --- a/docs/en/install/README.md +++ b/docs/en/install/README.md @@ -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 address(invalid when `CACHE_TYPE` is set to memory), default to `redis://localhost:6379/` `REDIS_PASSWORD`: Redis password(invalid when `CACHE_TYPE` is set to memory) diff --git a/docs/install/README.md b/docs/install/README.md index 3e51e55f4..e74197186 100644 --- a/docs/install/README.md +++ b/docs/install/README.md @@ -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/` diff --git a/middleware/template.js b/middleware/template.js index 283e8b5a2..e4d665776 100644 --- a/middleware/template.js +++ b/middleware/template.js @@ -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; }