@sns-parse/core 0.4.0-alpha.5 → 0.4.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -104,8 +104,8 @@ function engineConfigContributions() {
104
104
  fields: [
105
105
  {
106
106
  key: 'unifiedMessageFormat', type: 'string', role: 'textarea',
107
- default: '标题:${标题}\n作者:${作者}\n简介:${简介}\n翻译(${翻译提供方},${原文语言}):${翻译}\n音乐标题:${音乐标题}\n音乐作者:${音乐作者}\n点赞:${点赞数}\n收藏:${收藏数}\n转发:${转发数}\n播放:${播放数}\n评论:${评论数}\n图片数量:${图片数量}',
108
- description: '消息文字模板,可用变量:${标题} ${作者} ${简介} ${翻译} ${翻译提供方} ${原文语言} ${视频时长} ${点赞数} ${收藏数} ${转发数} ${播放数} ${评论数} ${发布时间} ${图片数量} ${作者ID} ${音乐标题} ${音乐作者}(空行自动隐藏)',
107
+ default: '标题:${标题}\n作者:${作者}\n简介:${简介}\n正文:${正文}\n翻译(${翻译提供方},${原文语言}):${翻译}\n音乐标题:${音乐标题}\n音乐作者:${音乐作者}\n点赞:${点赞数}\n收藏:${收藏数}\n转发:${转发数}\n播放:${播放数}\n评论:${评论数}\n图片数量:${图片数量}',
108
+ description: '消息文字模板,可用变量:${标题} ${作者} ${简介} ${正文}(纯文字作品正文,启用后该类作品不再显示为简介) ${翻译} ${翻译提供方} ${原文语言} ${视频时长} ${点赞数} ${收藏数} ${转发数} ${播放数} ${评论数} ${发布时间} ${图片数量} ${作者ID} ${音乐标题} ${音乐作者}(空行自动隐藏)',
109
109
  },
110
110
  ],
111
111
  }),
@@ -168,14 +168,15 @@ function deepFindLongestText(node) {
168
168
  }
169
169
  return best;
170
170
  }
171
- /** 清理描述中的 t.co 短链(Twitter 自动附加的截断 URL,无实际内容价值) */
171
+ /** 清理描述中的 t.co 短链(Twitter 自动附加的截断 URL,无实际内容价值)。
172
+ * 注意保留段落换行:仅折叠水平空白,≥3 连续换行压成空行一档。 */
172
173
  function cleanDesc(text) {
173
174
  if (!text)
174
175
  return text;
175
- // 移除末尾的 t.co URL(含可能的空格前导)
176
- let cleaned = text.replace(/\s*https?:\/\/t\.co\/[A-Za-z0-9]+(?:\?[^\s]*)?\s*$/g, '').trim();
177
- // 移除中间出现的 t.co URL(较少见,但推文内嵌的缩短链)
178
- cleaned = cleaned.replace(/\s*https?:\/\/t\.co\/[A-Za-z0-9]+/g, ' ').replace(/\s{2,}/g, ' ').trim();
176
+ // 去掉全部 t.co URL(文末自动附加 + 文中内嵌)
177
+ let cleaned = text.replace(/https?:\/\/t\.co\/[A-Za-z0-9]+(?:\?[^\s]*)?/g, '');
178
+ // 仅折叠空格/制表(不动换行);去掉行首尾空格;连续空行压成一个空行
179
+ cleaned = cleaned.replace(/[^\S\n]+/g, ' ').replace(/ *\n */g, '\n').replace(/\n{3,}/g, '\n\n').trim();
179
180
  return cleaned || text;
180
181
  }
181
182
  function baseParsed() {
@@ -28,10 +28,15 @@ function formatPublishTime(ms) {
28
28
  }
29
29
  function generateFormattedText(p, format, index, total) {
30
30
  const imageCount = p.images.length || p.live_photo.length;
31
+ // 纯文字作品(type=text):正文即内容。模板含 ${正文} 时启用新语义——
32
+ // 正文=desc、简介置空(自动隐藏),避免把正文标成「简介」;旧模板保持原行为。
33
+ const plainTextWork = p.type === 'text' && !!p.desc;
34
+ const wantsBody = plainTextWork && format.includes('${正文}');
31
35
  const vars = {
32
36
  '标题': p.title,
33
37
  '作者': p.author,
34
- '简介': p.desc,
38
+ '简介': wantsBody ? '' : p.desc,
39
+ '正文': plainTextWork ? p.desc : '',
35
40
  '视频时长': p.duration > 0 ? formatDuration(p.duration) : '',
36
41
  '点赞数': String(p.like),
37
42
  '收藏数': String(p.collect),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sns-parse/core",
3
- "version": "0.4.0-alpha.5+upstream.1.6.7",
3
+ "version": "0.4.0-alpha.6+upstream.1.6.7",
4
4
  "description": "sns-parse 核心:契约、宿主抽象、配置 DSL 与解析引擎(fetcher/parser/翻译/X 原生解析/合并/GIF/TLS 指纹客户端)",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",