@jackwener/opencli 1.4.1 → 1.5.1

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.
Files changed (369) hide show
  1. package/.github/workflows/build-extension.yml +2 -6
  2. package/.github/workflows/ci.yml +21 -1
  3. package/README.md +35 -6
  4. package/README.zh-CN.md +12 -5
  5. package/SKILL.md +2 -0
  6. package/dist/browser/cdp.d.ts +2 -1
  7. package/dist/browser/cdp.js +5 -0
  8. package/dist/browser/discover.d.ts +4 -1
  9. package/dist/browser/discover.js +6 -2
  10. package/dist/browser/errors.d.ts +2 -2
  11. package/dist/browser/errors.js +4 -12
  12. package/dist/browser/mcp.d.ts +2 -1
  13. package/dist/browser/page.d.ts +3 -0
  14. package/dist/browser/page.js +24 -1
  15. package/dist/build-manifest.d.ts +2 -0
  16. package/dist/build-manifest.js +39 -14
  17. package/dist/build-manifest.test.js +21 -0
  18. package/dist/capabilityRouting.d.ts +2 -0
  19. package/dist/capabilityRouting.js +2 -1
  20. package/dist/cli-manifest.json +1567 -108
  21. package/dist/cli.js +68 -6
  22. package/dist/clis/36kr/article.d.ts +1 -0
  23. package/dist/clis/36kr/article.js +62 -0
  24. package/dist/clis/36kr/hot.d.ts +3 -0
  25. package/dist/clis/36kr/hot.js +80 -0
  26. package/dist/clis/36kr/hot.test.d.ts +1 -0
  27. package/dist/clis/36kr/hot.test.js +15 -0
  28. package/dist/clis/36kr/news.d.ts +1 -0
  29. package/dist/clis/36kr/news.js +51 -0
  30. package/dist/clis/36kr/news.test.d.ts +1 -0
  31. package/dist/clis/36kr/news.test.js +85 -0
  32. package/dist/clis/36kr/search.d.ts +1 -0
  33. package/dist/clis/36kr/search.js +72 -0
  34. package/dist/clis/bilibili/comments.d.ts +5 -0
  35. package/dist/clis/bilibili/comments.js +40 -0
  36. package/dist/clis/bilibili/comments.test.d.ts +1 -0
  37. package/dist/clis/bilibili/comments.test.js +82 -0
  38. package/dist/clis/bluesky/feeds.yaml +29 -0
  39. package/dist/clis/bluesky/followers.yaml +33 -0
  40. package/dist/clis/bluesky/following.yaml +33 -0
  41. package/dist/clis/bluesky/profile.yaml +27 -0
  42. package/dist/clis/bluesky/search.yaml +34 -0
  43. package/dist/clis/bluesky/starter-packs.yaml +34 -0
  44. package/dist/clis/bluesky/thread.yaml +32 -0
  45. package/dist/clis/bluesky/trending.yaml +27 -0
  46. package/dist/clis/bluesky/user.yaml +34 -0
  47. package/dist/clis/chatgpt/ask.js +29 -14
  48. package/dist/clis/chatgpt/ax.d.ts +6 -0
  49. package/dist/clis/chatgpt/ax.js +172 -1
  50. package/dist/clis/chatgpt/model.d.ts +1 -0
  51. package/dist/clis/chatgpt/model.js +24 -0
  52. package/dist/clis/chatgpt/send.js +12 -3
  53. package/dist/clis/douban/download.d.ts +1 -0
  54. package/dist/clis/douban/download.js +67 -0
  55. package/dist/clis/douban/download.test.d.ts +1 -0
  56. package/dist/clis/douban/download.test.js +170 -0
  57. package/dist/clis/douban/photos.d.ts +1 -0
  58. package/dist/clis/douban/photos.js +34 -0
  59. package/dist/clis/douban/utils.d.ts +25 -0
  60. package/dist/clis/douban/utils.js +190 -1
  61. package/dist/clis/douban/utils.test.d.ts +1 -0
  62. package/dist/clis/douban/utils.test.js +64 -0
  63. package/dist/clis/imdb/person.d.ts +1 -0
  64. package/dist/clis/imdb/person.js +203 -0
  65. package/dist/clis/imdb/reviews.d.ts +1 -0
  66. package/dist/clis/imdb/reviews.js +88 -0
  67. package/dist/clis/imdb/search.d.ts +1 -0
  68. package/dist/clis/imdb/search.js +161 -0
  69. package/dist/clis/imdb/title.d.ts +1 -0
  70. package/dist/clis/imdb/title.js +93 -0
  71. package/dist/clis/imdb/top.d.ts +1 -0
  72. package/dist/clis/imdb/top.js +53 -0
  73. package/dist/clis/imdb/trending.d.ts +1 -0
  74. package/dist/clis/imdb/trending.js +52 -0
  75. package/dist/clis/imdb/utils.d.ts +46 -0
  76. package/dist/clis/imdb/utils.js +285 -0
  77. package/dist/clis/imdb/utils.test.d.ts +1 -0
  78. package/dist/clis/imdb/utils.test.js +88 -0
  79. package/dist/clis/jd/item.d.ts +4 -0
  80. package/dist/clis/jd/item.js +16 -15
  81. package/dist/clis/jd/item.test.js +16 -1
  82. package/dist/clis/linux-do/categories.yaml +38 -9
  83. package/dist/clis/linux-do/category.d.ts +1 -0
  84. package/dist/clis/linux-do/category.js +36 -0
  85. package/dist/clis/linux-do/feed.d.ts +45 -0
  86. package/dist/clis/linux-do/feed.js +397 -0
  87. package/dist/clis/linux-do/feed.test.d.ts +1 -0
  88. package/dist/clis/linux-do/feed.test.js +118 -0
  89. package/dist/clis/linux-do/hot.d.ts +1 -0
  90. package/dist/clis/linux-do/hot.js +25 -0
  91. package/dist/clis/linux-do/latest.d.ts +1 -0
  92. package/dist/clis/linux-do/latest.js +18 -0
  93. package/dist/clis/linux-do/tags.yaml +41 -0
  94. package/dist/clis/linux-do/topic.yaml +41 -3
  95. package/dist/clis/linux-do/user-posts.yaml +67 -0
  96. package/dist/clis/linux-do/user-topics.yaml +54 -0
  97. package/dist/clis/paperreview/commands.test.d.ts +3 -0
  98. package/dist/clis/paperreview/commands.test.js +243 -0
  99. package/dist/clis/paperreview/feedback.d.ts +1 -0
  100. package/dist/clis/paperreview/feedback.js +52 -0
  101. package/dist/clis/paperreview/review.d.ts +1 -0
  102. package/dist/clis/paperreview/review.js +37 -0
  103. package/dist/clis/paperreview/submit.d.ts +1 -0
  104. package/dist/clis/paperreview/submit.js +85 -0
  105. package/dist/clis/paperreview/utils.d.ts +46 -0
  106. package/dist/clis/paperreview/utils.js +197 -0
  107. package/dist/clis/paperreview/utils.test.d.ts +1 -0
  108. package/dist/clis/paperreview/utils.test.js +49 -0
  109. package/dist/clis/producthunt/browse.d.ts +1 -0
  110. package/dist/clis/producthunt/browse.js +99 -0
  111. package/dist/clis/producthunt/hot.d.ts +1 -0
  112. package/dist/clis/producthunt/hot.js +110 -0
  113. package/dist/clis/producthunt/posts.d.ts +1 -0
  114. package/dist/clis/producthunt/posts.js +28 -0
  115. package/dist/clis/producthunt/today.d.ts +1 -0
  116. package/dist/clis/producthunt/today.js +35 -0
  117. package/dist/clis/producthunt/utils.d.ts +29 -0
  118. package/dist/clis/producthunt/utils.js +99 -0
  119. package/dist/clis/producthunt/utils.test.d.ts +1 -0
  120. package/dist/clis/producthunt/utils.test.js +64 -0
  121. package/dist/clis/twitter/article.js +4 -28
  122. package/dist/clis/twitter/likes.d.ts +24 -0
  123. package/dist/clis/twitter/likes.js +217 -0
  124. package/dist/clis/twitter/likes.test.d.ts +1 -0
  125. package/dist/clis/twitter/likes.test.js +85 -0
  126. package/dist/clis/twitter/profile.js +4 -28
  127. package/dist/clis/twitter/search.js +2 -1
  128. package/dist/clis/twitter/search.test.js +2 -0
  129. package/dist/clis/twitter/shared.d.ts +6 -0
  130. package/dist/clis/twitter/shared.js +35 -0
  131. package/dist/clis/twitter/timeline.js +2 -13
  132. package/dist/clis/twitter/trending.js +29 -61
  133. package/dist/clis/v2ex/hot.yaml +17 -3
  134. package/dist/clis/weixin/download.d.ts +17 -0
  135. package/dist/clis/weixin/download.js +88 -20
  136. package/dist/clis/weread/book.js +2 -2
  137. package/dist/clis/weread/commands.test.d.ts +3 -0
  138. package/dist/clis/weread/commands.test.js +43 -0
  139. package/dist/clis/weread/highlights.js +2 -2
  140. package/dist/clis/weread/notebooks.js +2 -2
  141. package/dist/clis/weread/notes.js +3 -3
  142. package/dist/clis/weread/shelf.js +2 -2
  143. package/dist/clis/weread/utils.d.ts +4 -4
  144. package/dist/clis/weread/utils.js +32 -14
  145. package/dist/clis/weread/utils.test.js +1 -28
  146. package/dist/clis/xiaohongshu/comments.d.ts +5 -0
  147. package/dist/clis/xiaohongshu/comments.js +74 -0
  148. package/dist/clis/xiaohongshu/comments.test.d.ts +1 -0
  149. package/dist/clis/xiaohongshu/comments.test.js +79 -0
  150. package/dist/clis/xiaohongshu/publish.js +179 -47
  151. package/dist/clis/xiaohongshu/publish.test.d.ts +1 -0
  152. package/dist/clis/xiaohongshu/publish.test.js +131 -0
  153. package/dist/clis/xiaohongshu/search.d.ts +8 -1
  154. package/dist/clis/xiaohongshu/search.js +20 -1
  155. package/dist/clis/xiaohongshu/search.test.d.ts +1 -1
  156. package/dist/clis/xiaohongshu/search.test.js +32 -1
  157. package/dist/commanderAdapter.d.ts +1 -0
  158. package/dist/commanderAdapter.js +176 -29
  159. package/dist/commanderAdapter.test.d.ts +1 -0
  160. package/dist/commanderAdapter.test.js +62 -0
  161. package/dist/daemon.js +17 -1
  162. package/dist/discovery.js +48 -42
  163. package/dist/doctor.d.ts +2 -2
  164. package/dist/doctor.js +11 -4
  165. package/dist/download/index.js +63 -51
  166. package/dist/download/index.test.js +17 -4
  167. package/dist/engine.test.js +42 -0
  168. package/dist/errors.d.ts +4 -2
  169. package/dist/errors.js +17 -34
  170. package/dist/execution.d.ts +1 -3
  171. package/dist/execution.js +66 -8
  172. package/dist/execution.test.d.ts +1 -0
  173. package/dist/execution.test.js +40 -0
  174. package/dist/external.js +6 -1
  175. package/dist/hooks.js +2 -0
  176. package/dist/main.js +6 -0
  177. package/dist/output.js +5 -1
  178. package/dist/pipeline/executor.js +3 -4
  179. package/dist/plugin-manifest.d.ts +70 -0
  180. package/dist/plugin-manifest.js +160 -0
  181. package/dist/plugin-manifest.test.d.ts +4 -0
  182. package/dist/plugin-manifest.test.js +179 -0
  183. package/dist/plugin-scaffold.d.ts +28 -0
  184. package/dist/plugin-scaffold.js +142 -0
  185. package/dist/plugin-scaffold.test.d.ts +4 -0
  186. package/dist/plugin-scaffold.test.js +83 -0
  187. package/dist/plugin.d.ts +82 -11
  188. package/dist/plugin.js +870 -84
  189. package/dist/plugin.test.js +1032 -17
  190. package/dist/registry.d.ts +4 -0
  191. package/dist/registry.js +2 -0
  192. package/dist/runtime-detect.d.ts +21 -0
  193. package/dist/runtime-detect.js +32 -0
  194. package/dist/runtime-detect.test.d.ts +1 -0
  195. package/dist/runtime-detect.test.js +27 -0
  196. package/dist/runtime.d.ts +1 -0
  197. package/dist/runtime.js +2 -2
  198. package/dist/serialization.d.ts +2 -0
  199. package/dist/serialization.js +6 -0
  200. package/dist/types.d.ts +3 -0
  201. package/dist/update-check.d.ts +22 -0
  202. package/dist/update-check.js +112 -0
  203. package/dist/weixin-download.test.d.ts +1 -0
  204. package/dist/weixin-download.test.js +30 -0
  205. package/dist/weread-private-api-regression.test.d.ts +1 -0
  206. package/dist/weread-private-api-regression.test.js +122 -0
  207. package/dist/yaml-schema.d.ts +3 -0
  208. package/dist/yaml-schema.js +18 -1
  209. package/docs/.vitepress/config.mts +4 -0
  210. package/docs/adapters/browser/36kr.md +47 -0
  211. package/docs/adapters/browser/bluesky.md +53 -0
  212. package/docs/adapters/browser/douban.md +14 -0
  213. package/docs/adapters/browser/imdb.md +47 -0
  214. package/docs/adapters/browser/jd.md +2 -2
  215. package/docs/adapters/browser/linux-do.md +181 -20
  216. package/docs/adapters/browser/paperreview.md +43 -0
  217. package/docs/adapters/browser/producthunt.md +49 -0
  218. package/docs/adapters/desktop/chatgpt.md +5 -0
  219. package/docs/adapters/index.md +6 -2
  220. package/docs/advanced/download.md +4 -0
  221. package/docs/advanced/rate-limiter-plugin.md +99 -0
  222. package/docs/guide/electron-app-cli.md +200 -0
  223. package/docs/guide/getting-started.md +1 -0
  224. package/docs/guide/plugins.md +97 -0
  225. package/docs/zh/guide/electron-app-cli.md +188 -0
  226. package/docs/zh/guide/getting-started.md +1 -0
  227. package/docs/zh/guide/plugins.md +65 -0
  228. package/extension/package.json +1 -0
  229. package/extension/scripts/package-release.mjs +179 -0
  230. package/extension/src/background.ts +2 -0
  231. package/package.json +4 -1
  232. package/scripts/postinstall.js +10 -0
  233. package/src/browser/cdp.ts +8 -1
  234. package/src/browser/discover.ts +8 -3
  235. package/src/browser/errors.ts +13 -14
  236. package/src/browser/mcp.ts +2 -1
  237. package/src/browser/page.ts +24 -1
  238. package/src/build-manifest.test.ts +23 -0
  239. package/src/build-manifest.ts +40 -15
  240. package/src/capabilityRouting.ts +2 -1
  241. package/src/cli.ts +69 -6
  242. package/src/clis/36kr/article.ts +69 -0
  243. package/src/clis/36kr/hot.test.ts +19 -0
  244. package/src/clis/36kr/hot.ts +100 -0
  245. package/src/clis/36kr/news.test.ts +90 -0
  246. package/src/clis/36kr/news.ts +54 -0
  247. package/src/clis/36kr/search.ts +78 -0
  248. package/src/clis/bilibili/comments.test.ts +102 -0
  249. package/src/clis/bilibili/comments.ts +44 -0
  250. package/src/clis/bluesky/feeds.yaml +29 -0
  251. package/src/clis/bluesky/followers.yaml +33 -0
  252. package/src/clis/bluesky/following.yaml +33 -0
  253. package/src/clis/bluesky/profile.yaml +27 -0
  254. package/src/clis/bluesky/search.yaml +34 -0
  255. package/src/clis/bluesky/starter-packs.yaml +34 -0
  256. package/src/clis/bluesky/thread.yaml +32 -0
  257. package/src/clis/bluesky/trending.yaml +27 -0
  258. package/src/clis/bluesky/user.yaml +34 -0
  259. package/src/clis/chatgpt/ask.ts +28 -14
  260. package/src/clis/chatgpt/ax.ts +180 -1
  261. package/src/clis/chatgpt/model.ts +27 -0
  262. package/src/clis/chatgpt/send.ts +16 -6
  263. package/src/clis/douban/download.test.ts +196 -0
  264. package/src/clis/douban/download.ts +78 -0
  265. package/src/clis/douban/photos.ts +36 -0
  266. package/src/clis/douban/utils.test.ts +97 -0
  267. package/src/clis/douban/utils.ts +232 -1
  268. package/src/clis/imdb/person.ts +232 -0
  269. package/src/clis/imdb/reviews.ts +111 -0
  270. package/src/clis/imdb/search.ts +179 -0
  271. package/src/clis/imdb/title.ts +121 -0
  272. package/src/clis/imdb/top.ts +67 -0
  273. package/src/clis/imdb/trending.ts +66 -0
  274. package/src/clis/imdb/utils.test.ts +117 -0
  275. package/src/clis/imdb/utils.ts +305 -0
  276. package/src/clis/jd/item.test.ts +18 -1
  277. package/src/clis/jd/item.ts +18 -15
  278. package/src/clis/linux-do/categories.yaml +38 -9
  279. package/src/clis/linux-do/category.ts +37 -0
  280. package/src/clis/linux-do/feed.test.ts +132 -0
  281. package/src/clis/linux-do/feed.ts +501 -0
  282. package/src/clis/linux-do/hot.ts +26 -0
  283. package/src/clis/linux-do/latest.ts +19 -0
  284. package/src/clis/linux-do/tags.yaml +41 -0
  285. package/src/clis/linux-do/topic.yaml +41 -3
  286. package/src/clis/linux-do/user-posts.yaml +67 -0
  287. package/src/clis/linux-do/user-topics.yaml +54 -0
  288. package/src/clis/paperreview/commands.test.ts +283 -0
  289. package/src/clis/paperreview/feedback.ts +64 -0
  290. package/src/clis/paperreview/review.ts +47 -0
  291. package/src/clis/paperreview/submit.ts +119 -0
  292. package/src/clis/paperreview/utils.test.ts +68 -0
  293. package/src/clis/paperreview/utils.ts +276 -0
  294. package/src/clis/producthunt/browse.ts +109 -0
  295. package/src/clis/producthunt/hot.ts +127 -0
  296. package/src/clis/producthunt/posts.ts +29 -0
  297. package/src/clis/producthunt/today.ts +37 -0
  298. package/src/clis/producthunt/utils.test.ts +72 -0
  299. package/src/clis/producthunt/utils.ts +122 -0
  300. package/src/clis/twitter/article.ts +5 -28
  301. package/src/clis/twitter/likes.test.ts +91 -0
  302. package/src/clis/twitter/likes.ts +256 -0
  303. package/src/clis/twitter/profile.ts +5 -28
  304. package/src/clis/twitter/search.test.ts +2 -0
  305. package/src/clis/twitter/search.ts +3 -1
  306. package/src/clis/twitter/shared.ts +45 -0
  307. package/src/clis/twitter/timeline.ts +2 -13
  308. package/src/clis/twitter/trending.ts +29 -77
  309. package/src/clis/v2ex/hot.yaml +17 -3
  310. package/src/clis/weixin/download.ts +114 -20
  311. package/src/clis/weread/book.ts +2 -2
  312. package/src/clis/weread/commands.test.ts +57 -0
  313. package/src/clis/weread/highlights.ts +2 -2
  314. package/src/clis/weread/notebooks.ts +2 -2
  315. package/src/clis/weread/notes.ts +3 -3
  316. package/src/clis/weread/shelf.ts +2 -2
  317. package/src/clis/weread/utils.test.ts +1 -32
  318. package/src/clis/weread/utils.ts +41 -16
  319. package/src/clis/xiaohongshu/comments.test.ts +96 -0
  320. package/src/clis/xiaohongshu/comments.ts +81 -0
  321. package/src/clis/xiaohongshu/publish.test.ts +151 -0
  322. package/src/clis/xiaohongshu/publish.ts +206 -54
  323. package/src/clis/xiaohongshu/search.test.ts +39 -1
  324. package/src/clis/xiaohongshu/search.ts +19 -1
  325. package/src/commanderAdapter.test.ts +78 -0
  326. package/src/commanderAdapter.ts +188 -24
  327. package/src/daemon.ts +19 -1
  328. package/src/discovery.ts +49 -48
  329. package/src/doctor.ts +15 -5
  330. package/src/download/index.test.ts +14 -4
  331. package/src/download/index.ts +67 -55
  332. package/src/engine.test.ts +38 -0
  333. package/src/errors.ts +26 -63
  334. package/src/execution.test.ts +47 -0
  335. package/src/execution.ts +67 -9
  336. package/src/external.ts +6 -1
  337. package/src/hooks.ts +1 -0
  338. package/src/main.ts +7 -0
  339. package/src/output.ts +3 -1
  340. package/src/pipeline/executor.ts +4 -6
  341. package/src/plugin-manifest.test.ts +223 -0
  342. package/src/plugin-manifest.ts +206 -0
  343. package/src/plugin-scaffold.test.ts +98 -0
  344. package/src/plugin-scaffold.ts +170 -0
  345. package/src/plugin.test.ts +1104 -17
  346. package/src/plugin.ts +1101 -86
  347. package/src/registry.ts +6 -1
  348. package/src/runtime-detect.test.ts +30 -0
  349. package/src/runtime-detect.ts +36 -0
  350. package/src/runtime.ts +3 -3
  351. package/src/serialization.ts +4 -0
  352. package/src/types.ts +3 -0
  353. package/src/update-check.ts +114 -0
  354. package/src/weixin-download.test.ts +64 -0
  355. package/src/weread-private-api-regression.test.ts +150 -0
  356. package/src/yaml-schema.ts +20 -0
  357. package/tests/e2e/browser-auth.test.ts +13 -9
  358. package/tests/e2e/browser-public-extended.test.ts +1 -1
  359. package/tests/e2e/browser-public.test.ts +62 -4
  360. package/tests/e2e/helpers.ts +2 -1
  361. package/tests/e2e/public-commands.test.ts +37 -3
  362. package/tests/smoke/api-health.test.ts +1 -1
  363. package/vitest.config.ts +10 -0
  364. package/dist/clis/linux-do/category.yaml +0 -51
  365. package/dist/clis/linux-do/hot.yaml +0 -50
  366. package/dist/clis/linux-do/latest.yaml +0 -40
  367. package/src/clis/linux-do/category.yaml +0 -51
  368. package/src/clis/linux-do/hot.yaml +0 -50
  369. package/src/clis/linux-do/latest.yaml +0 -40
@@ -0,0 +1,501 @@
1
+ /**
2
+ * linux.do unified feed — route latest/hot/top topics by site, tag, or category.
3
+ *
4
+ * Usage:
5
+ * linux-do feed # latest topics
6
+ * linux-do feed --view top --period daily # top topics (daily)
7
+ * linux-do feed --tag ChatGPT # latest topics by tag
8
+ * linux-do feed --tag 3 --view hot # hot topics by tag id
9
+ * linux-do feed --category 开发调优 # latest top-level category topics
10
+ * linux-do feed --category 94 --tag 4 --view top --period monthly
11
+ */
12
+ import * as fs from 'node:fs';
13
+ import * as os from 'node:os';
14
+ import * as path from 'node:path';
15
+ import { ArgumentError, AuthRequiredError, CommandExecutionError } from '../../errors.js';
16
+ import { cli, Strategy, type Arg, type CommandArgs } from '../../registry.js';
17
+ import type { IPage } from '../../types.js';
18
+
19
+ const LINUX_DO_HOME = 'https://linux.do';
20
+ const LINUX_DO_METADATA_TTL_MS = 24 * 60 * 60 * 1000;
21
+ let liveTagsPromise: Promise<LinuxDoTagRecord[]> | null = null;
22
+ let liveCategoriesPromise: Promise<ResolvedLinuxDoCategory[]> | null = null;
23
+ let testTagOverride: LinuxDoTagRecord[] | null = null;
24
+ let testCategoryOverride: ResolvedLinuxDoCategory[] | null = null;
25
+ let testCacheDirOverride: string | null = null;
26
+
27
+ type FeedView = 'latest' | 'hot' | 'top';
28
+
29
+ interface LinuxDoTagRecord {
30
+ id: number;
31
+ slug: string;
32
+ name: string;
33
+ }
34
+
35
+ interface LinuxDoCategoryRecord {
36
+ id: number;
37
+ name: string;
38
+ description: string;
39
+ slug: string;
40
+ parentCategoryId: number | null;
41
+ }
42
+
43
+ interface ResolvedLinuxDoCategory extends LinuxDoCategoryRecord {
44
+ parent: LinuxDoCategoryRecord | null;
45
+ }
46
+
47
+ interface FeedRequest {
48
+ url: string;
49
+ }
50
+
51
+ interface TopicListItem {
52
+ title: string;
53
+ replies: number;
54
+ created: string;
55
+ likes: number;
56
+ views: number;
57
+ url: string;
58
+ }
59
+
60
+ interface FetchJsonResult {
61
+ ok: boolean;
62
+ status?: number;
63
+ data?: unknown;
64
+ error?: string;
65
+ }
66
+
67
+ interface FetchJsonOptions {
68
+ skipNavigate?: boolean;
69
+ }
70
+
71
+ interface RawLinuxDoTag {
72
+ id: number;
73
+ slug?: string | null;
74
+ name?: string | null;
75
+ }
76
+
77
+ interface RawLinuxDoCategory {
78
+ id: number;
79
+ name?: string | null;
80
+ description?: string | null;
81
+ description_text?: string | null;
82
+ slug?: string | null;
83
+ subcategory_ids?: number[] | null;
84
+ }
85
+
86
+ interface MetadataCacheEnvelope<T> {
87
+ fetchedAt: string;
88
+ data: T;
89
+ }
90
+
91
+ /**
92
+ * 统一清洗名称和 slug,避免大小写与多空格影响匹配。
93
+ */
94
+ function normalizeLookupValue(value: string): string {
95
+ return value.trim().replace(/\s+/g, ' ').toLowerCase();
96
+ }
97
+
98
+ function getHomeDir(): string {
99
+ return process.env.HOME || process.env.USERPROFILE || os.homedir();
100
+ }
101
+
102
+ function getLinuxDoCacheDir(): string {
103
+ return testCacheDirOverride ?? path.join(getHomeDir(), '.opencli', 'cache', 'linux-do');
104
+ }
105
+
106
+ function getMetadataCachePath(name: 'tags' | 'categories'): string {
107
+ return path.join(getLinuxDoCacheDir(), `${name}.json`);
108
+ }
109
+
110
+ async function readMetadataCache<T>(name: 'tags' | 'categories'): Promise<{ data: T; fresh: boolean } | null> {
111
+ try {
112
+ const raw = await fs.promises.readFile(getMetadataCachePath(name), 'utf-8');
113
+ const parsed = JSON.parse(raw) as MetadataCacheEnvelope<T>;
114
+ if (!parsed || !Array.isArray(parsed.data) || typeof parsed.fetchedAt !== 'string') return null;
115
+ const fetchedAt = new Date(parsed.fetchedAt).getTime();
116
+ const fresh = Number.isFinite(fetchedAt) && (Date.now() - fetchedAt) < LINUX_DO_METADATA_TTL_MS;
117
+ return { data: parsed.data, fresh };
118
+ } catch {
119
+ return null;
120
+ }
121
+ }
122
+
123
+ async function writeMetadataCache<T>(name: 'tags' | 'categories', data: T): Promise<void> {
124
+ try {
125
+ const cacheDir = getLinuxDoCacheDir();
126
+ await fs.promises.mkdir(cacheDir, { recursive: true });
127
+ const payload: MetadataCacheEnvelope<T> = {
128
+ fetchedAt: new Date().toISOString(),
129
+ data,
130
+ };
131
+ await fs.promises.writeFile(getMetadataCachePath(name), JSON.stringify(payload, null, 2) + '\n');
132
+ } catch {
133
+ // Cache write failures should never block command execution.
134
+ }
135
+ }
136
+
137
+ async function ensureLinuxDoHome(page: IPage | null): Promise<void> {
138
+ if (!page) throw new CommandExecutionError('Browser page required');
139
+ await page.goto(LINUX_DO_HOME);
140
+ await page.wait(2);
141
+ }
142
+
143
+ async function fetchLinuxDoJson(page: IPage | null, apiPath: string, options: FetchJsonOptions = {}): Promise<any> {
144
+ if (!options.skipNavigate) {
145
+ await ensureLinuxDoHome(page);
146
+ }
147
+ if (!page) throw new CommandExecutionError('Browser page required');
148
+
149
+ const escapedPath = JSON.stringify(apiPath);
150
+ const result = await page.evaluate(`(async () => {
151
+ try {
152
+ const res = await fetch(${escapedPath}, { credentials: 'include' });
153
+ let data = null;
154
+ try { data = await res.json(); } catch {}
155
+ return {
156
+ ok: res.ok,
157
+ status: res.status,
158
+ data,
159
+ error: data === null ? 'Response is not valid JSON' : '',
160
+ };
161
+ } catch (error) {
162
+ return {
163
+ ok: false,
164
+ error: error instanceof Error ? error.message : String(error),
165
+ };
166
+ }
167
+ })()`) as FetchJsonResult | null;
168
+
169
+ if (!result) {
170
+ throw new CommandExecutionError('linux.do returned an empty browser response');
171
+ }
172
+
173
+ if (result.status === 401 || result.status === 403) {
174
+ throw new AuthRequiredError('linux.do', 'linux.do requires an active signed-in browser session');
175
+ }
176
+
177
+ if (!result.ok) {
178
+ throw new CommandExecutionError(
179
+ result.error || `linux.do request failed: HTTP ${result.status ?? 'unknown'}`,
180
+ );
181
+ }
182
+
183
+ if (result.error) {
184
+ throw new CommandExecutionError(result.error, 'Please verify your linux.do session is still valid');
185
+ }
186
+
187
+ return result.data;
188
+ }
189
+
190
+ function findMatchingTag(records: LinuxDoTagRecord[], value: string): LinuxDoTagRecord | null {
191
+ const raw = value.trim();
192
+ const normalized = normalizeLookupValue(value);
193
+ return /^\d+$/.test(raw)
194
+ ? records.find((item) => item.id === Number(raw)) ?? null
195
+ : records.find((item) => normalizeLookupValue(item.name) === normalized)
196
+ ?? records.find((item) => normalizeLookupValue(item.slug) === normalized)
197
+ ?? null;
198
+ }
199
+
200
+ function findMatchingCategory(records: ResolvedLinuxDoCategory[], value: string): ResolvedLinuxDoCategory | null {
201
+ const raw = value.trim();
202
+ const normalized = normalizeLookupValue(value);
203
+ return /^\d+$/.test(raw)
204
+ ? records.find((item) => item.id === Number(raw)) ?? null
205
+ : records.find((item) => categoryLookupKeys(item).includes(normalized))
206
+ ?? null;
207
+ }
208
+
209
+ function categoryLookupKeys(category: ResolvedLinuxDoCategory): string[] {
210
+ const keys = [category.name, category.slug];
211
+ if (category.parent) {
212
+ keys.push(
213
+ `${category.parent.name} / ${category.name}`,
214
+ `${category.parent.name}/${category.name}`,
215
+ `${category.parent.name}, ${category.name}`,
216
+ );
217
+ }
218
+ return keys.map(normalizeLookupValue);
219
+ }
220
+
221
+ function toCategoryRecord(raw: RawLinuxDoCategory, parent: LinuxDoCategoryRecord | null): ResolvedLinuxDoCategory {
222
+ return {
223
+ id: raw.id,
224
+ name: raw.name ?? '',
225
+ description: raw.description_text ?? raw.description ?? '',
226
+ slug: raw.slug ?? '',
227
+ parentCategoryId: parent?.id ?? null,
228
+ parent,
229
+ };
230
+ }
231
+
232
+ async function fetchLiveTags(page: IPage | null): Promise<LinuxDoTagRecord[]> {
233
+ if (testTagOverride) return testTagOverride;
234
+ if (!liveTagsPromise) {
235
+ liveTagsPromise = (async () => {
236
+ const cached = await readMetadataCache<LinuxDoTagRecord[]>('tags');
237
+ if (cached?.fresh) return cached.data;
238
+
239
+ try {
240
+ const data = await fetchLinuxDoJson(page, '/tags.json', { skipNavigate: true });
241
+ const tags = (Array.isArray(data?.tags) ? data.tags : [])
242
+ .filter((tag: unknown): tag is RawLinuxDoTag => !!tag && typeof (tag as RawLinuxDoTag).id === 'number')
243
+ .map((tag: RawLinuxDoTag) => ({
244
+ id: tag.id,
245
+ slug: tag.slug ?? `${tag.id}-tag`,
246
+ name: tag.name ?? String(tag.id),
247
+ }));
248
+ await writeMetadataCache('tags', tags);
249
+ return tags;
250
+ } catch (error) {
251
+ if (cached) return cached.data;
252
+ liveTagsPromise = null;
253
+ throw error;
254
+ }
255
+ })().catch((error) => {
256
+ liveTagsPromise = null;
257
+ throw error;
258
+ });
259
+ }
260
+ return liveTagsPromise;
261
+ }
262
+
263
+ async function fetchLiveCategories(page: IPage | null): Promise<ResolvedLinuxDoCategory[]> {
264
+ if (testCategoryOverride) return testCategoryOverride;
265
+ if (!liveCategoriesPromise) {
266
+ liveCategoriesPromise = (async () => {
267
+ const cached = await readMetadataCache<ResolvedLinuxDoCategory[]>('categories');
268
+ if (cached?.fresh) return cached.data;
269
+
270
+ try {
271
+ const data = await fetchLinuxDoJson(page, '/categories.json', { skipNavigate: true });
272
+ const topCategories: RawLinuxDoCategory[] = Array.isArray(data?.category_list?.categories)
273
+ ? data.category_list.categories
274
+ : [];
275
+
276
+ const resolvedTop = topCategories.map((category: RawLinuxDoCategory) => toCategoryRecord(category, null));
277
+ const parentById = new Map<number, LinuxDoCategoryRecord>(resolvedTop.map((item) => [item.id, item]));
278
+
279
+ const subcategoryGroups = await Promise.allSettled(
280
+ topCategories
281
+ .filter((category: RawLinuxDoCategory) => Array.isArray(category.subcategory_ids) && category.subcategory_ids.length > 0)
282
+ .map(async (category: RawLinuxDoCategory) => {
283
+ const subData = await fetchLinuxDoJson(page, `/categories.json?parent_category_id=${category.id}`, { skipNavigate: true });
284
+ const subCategories: RawLinuxDoCategory[] = Array.isArray(subData?.category_list?.categories)
285
+ ? subData.category_list.categories
286
+ : [];
287
+ const parent = parentById.get(category.id) ?? null;
288
+ return subCategories.map((subCategory: RawLinuxDoCategory) => toCategoryRecord(subCategory, parent));
289
+ }),
290
+ );
291
+
292
+ const categories = [
293
+ ...resolvedTop,
294
+ ...subcategoryGroups.flatMap((result) => result.status === 'fulfilled' ? result.value : []),
295
+ ];
296
+ await writeMetadataCache('categories', categories);
297
+ return categories;
298
+ } catch (error) {
299
+ if (cached) return cached.data;
300
+ throw error;
301
+ }
302
+ })().catch((error) => {
303
+ liveCategoriesPromise = null;
304
+ throw error;
305
+ });
306
+ }
307
+ return liveCategoriesPromise;
308
+ }
309
+
310
+ function toLocalTime(utcStr: string): string {
311
+ if (!utcStr) return '';
312
+ const d = new Date(utcStr);
313
+ if (isNaN(d.getTime())) return utcStr;
314
+ return d.toLocaleString();
315
+ }
316
+
317
+ function normalizeReplyCount(postsCount: unknown): number {
318
+ const count = typeof postsCount === 'number' ? postsCount : 1;
319
+ return Math.max(0, count - 1);
320
+ }
321
+
322
+ function topicListRichFromJson(data: any, limit: number): TopicListItem[] {
323
+ const topics: any[] = data?.topic_list?.topics ?? [];
324
+ return topics.slice(0, limit).map((t: any) => ({
325
+ title: t.fancy_title ?? t.title ?? '',
326
+ replies: normalizeReplyCount(t.posts_count),
327
+ created: toLocalTime(t.created_at),
328
+ likes: t.like_count ?? 0,
329
+ views: t.views ?? 0,
330
+ url: `https://linux.do/t/topic/${t.id}`,
331
+ }));
332
+ }
333
+
334
+ /**
335
+ * 解析标签,支持 id、name、slug 三种输入。
336
+ */
337
+ async function resolveTag(page: IPage | null, value: string): Promise<LinuxDoTagRecord> {
338
+ const liveTag = findMatchingTag(await fetchLiveTags(page), value);
339
+ if (liveTag) return liveTag;
340
+
341
+ throw new ArgumentError(`Unknown tag: ${value}`, 'Use "opencli linux-do tags" to list available tags');
342
+ }
343
+
344
+ /**
345
+ * 解析分类,并补齐父分类信息。
346
+ */
347
+ async function resolveCategory(page: IPage | null, value: string): Promise<ResolvedLinuxDoCategory> {
348
+ const liveCategory = findMatchingCategory(await fetchLiveCategories(page), value);
349
+ if (liveCategory) return liveCategory;
350
+
351
+ throw new ArgumentError(`Unknown category: ${value}`, 'Use "opencli linux-do categories" to list available categories');
352
+ }
353
+
354
+ /**
355
+ * 将命令参数转换为最终请求地址
356
+ */
357
+ async function resolveFeedRequest(page: IPage | null, kwargs: Record<string, any>): Promise<FeedRequest> {
358
+ const view = (kwargs.view || 'latest') as FeedView;
359
+ const period = (kwargs.period || 'weekly') as string;
360
+
361
+ if (kwargs.period && view !== 'top') {
362
+ throw new ArgumentError('--period is only valid with --view top');
363
+ }
364
+
365
+ const params = new URLSearchParams();
366
+ if (kwargs.order && kwargs.order !== 'default') params.set('order', kwargs.order as string);
367
+ if (kwargs.ascending) params.set('ascending', 'true');
368
+ if (kwargs.limit) params.set('per_page', String(kwargs.limit));
369
+ const tagValue = typeof kwargs.tag === 'string' ? kwargs.tag.trim() : '';
370
+ const categoryValue = typeof kwargs.category === 'string' ? kwargs.category.trim() : '';
371
+
372
+ if (!tagValue && !categoryValue) {
373
+ const query = new URLSearchParams(params);
374
+ if (view === 'top') query.set('period', period);
375
+ const jsonSuffix = query.toString() ? `?${query.toString()}` : '';
376
+ return {
377
+ url: `${view === 'latest' ? '/latest.json' : view === 'hot' ? '/hot.json' : '/top.json'}${jsonSuffix}`,
378
+ };
379
+ }
380
+
381
+ const tag = tagValue ? await resolveTag(page, tagValue) : null;
382
+ const category = categoryValue ? await resolveCategory(page, categoryValue) : null;
383
+
384
+ const categorySegments = category
385
+ ? (category.parent
386
+ ? [category.parent.slug, category.slug, String(category.id)]
387
+ : [category.slug, String(category.id)])
388
+ .map(encodeURIComponent)
389
+ .join('/')
390
+ : '';
391
+
392
+ const tagSegment = tag ? `${encodeURIComponent(tag.slug || `${tag.id}-tag`)}/${tag.id}` : '';
393
+
394
+ const basePath = category && tag
395
+ ? `/tags/c/${categorySegments}/${tagSegment}`
396
+ : category
397
+ ? `/c/${categorySegments}`
398
+ : `/tag/${tagSegment}`;
399
+
400
+ const query = new URLSearchParams(params);
401
+ if (view === 'top') query.set('period', period);
402
+ const jsonSuffix = query.toString() ? `?${query.toString()}` : '';
403
+ return {
404
+ url: `${basePath}${view === 'latest' ? '.json' : `/l/${view}.json`}${jsonSuffix}`,
405
+ };
406
+ }
407
+
408
+ export const LINUX_DO_FEED_ARGS: Arg[] = [
409
+ {
410
+ name: 'view',
411
+ type: 'str',
412
+ default: 'latest',
413
+ help: 'View type',
414
+ choices: ['latest', 'hot', 'top'],
415
+ },
416
+ {
417
+ name: 'tag',
418
+ type: 'str',
419
+ help: 'Tag name, slug, or id',
420
+ },
421
+ {
422
+ name: 'category',
423
+ type: 'str',
424
+ help: 'Category name, slug, id, or parent/name path',
425
+ },
426
+ { name: 'limit', type: 'int', default: 20, help: 'Number of items (per_page)' },
427
+ {
428
+ name: 'order',
429
+ type: 'str',
430
+ default: 'default',
431
+ help: 'Sort order',
432
+ choices: [
433
+ 'default',
434
+ 'created',
435
+ 'activity',
436
+ 'views',
437
+ 'posts',
438
+ 'category',
439
+ 'likes',
440
+ 'op_likes',
441
+ 'posters',
442
+ ],
443
+ },
444
+ { name: 'ascending', type: 'boolean', default: false, help: 'Sort ascending (default: desc)' },
445
+ {
446
+ name: 'period',
447
+ type: 'str',
448
+ help: 'Time period (only for --view top)',
449
+ choices: ['all', 'daily', 'weekly', 'monthly', 'quarterly', 'yearly'],
450
+ },
451
+ ];
452
+
453
+ export async function executeLinuxDoFeed(page: IPage | null, kwargs: CommandArgs): Promise<TopicListItem[]> {
454
+ const limit = (kwargs.limit || 20) as number;
455
+ await ensureLinuxDoHome(page);
456
+ const request = await resolveFeedRequest(page, kwargs);
457
+ const data = await fetchLinuxDoJson(page, request.url, { skipNavigate: true });
458
+ return topicListRichFromJson(data, limit);
459
+ }
460
+
461
+ export function buildLinuxDoCompatFooter(replacement: string): string {
462
+ return `Deprecated compatibility command. Prefer: ${replacement}`;
463
+ }
464
+
465
+ cli({
466
+ site: 'linux-do',
467
+ name: 'feed',
468
+ description: 'linux.do 话题列表(需登录;支持全站、标签、分类)',
469
+ domain: 'linux.do',
470
+ strategy: Strategy.COOKIE,
471
+ browser: true,
472
+ columns: ['title', 'replies', 'created', 'likes', 'views', 'url'],
473
+ args: LINUX_DO_FEED_ARGS,
474
+ func: executeLinuxDoFeed,
475
+ });
476
+
477
+ export const __test__ = {
478
+ resetMetadataCaches(): void {
479
+ liveTagsPromise = null;
480
+ liveCategoriesPromise = null;
481
+ testTagOverride = null;
482
+ testCategoryOverride = null;
483
+ testCacheDirOverride = null;
484
+ },
485
+ setLiveMetadataForTests({
486
+ tags,
487
+ categories,
488
+ }: {
489
+ tags?: LinuxDoTagRecord[] | null;
490
+ categories?: ResolvedLinuxDoCategory[] | null;
491
+ }): void {
492
+ liveTagsPromise = null;
493
+ liveCategoriesPromise = null;
494
+ testTagOverride = tags ?? null;
495
+ testCategoryOverride = categories ?? null;
496
+ },
497
+ setCacheDirForTests(dir: string | null): void {
498
+ testCacheDirOverride = dir;
499
+ },
500
+ resolveFeedRequest,
501
+ };
@@ -0,0 +1,26 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+ import { buildLinuxDoCompatFooter, executeLinuxDoFeed } from './feed.js';
3
+
4
+ cli({
5
+ site: 'linux-do',
6
+ name: 'hot',
7
+ description: 'linux.do 热门话题',
8
+ domain: 'linux.do',
9
+ strategy: Strategy.COOKIE,
10
+ browser: true,
11
+ columns: ['title', 'replies', 'created', 'likes', 'views', 'url'],
12
+ deprecated: 'opencli linux-do hot is kept for backward compatibility.',
13
+ replacedBy: 'opencli linux-do feed --view top --period <period>',
14
+ args: [
15
+ { name: 'limit', type: 'int', default: 20, help: 'Number of items (per_page)' },
16
+ {
17
+ name: 'period',
18
+ type: 'str',
19
+ default: 'weekly',
20
+ help: 'Time period',
21
+ choices: ['all', 'daily', 'weekly', 'monthly', 'quarterly', 'yearly'],
22
+ },
23
+ ],
24
+ func: async (page, kwargs) => executeLinuxDoFeed(page, { ...kwargs, view: 'top' }),
25
+ footerExtra: () => buildLinuxDoCompatFooter('opencli linux-do feed --view top --period <period>'),
26
+ });
@@ -0,0 +1,19 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+ import { buildLinuxDoCompatFooter, executeLinuxDoFeed } from './feed.js';
3
+
4
+ cli({
5
+ site: 'linux-do',
6
+ name: 'latest',
7
+ description: 'linux.do 最新话题',
8
+ domain: 'linux.do',
9
+ strategy: Strategy.COOKIE,
10
+ browser: true,
11
+ columns: ['title', 'replies', 'created', 'likes', 'views', 'url'],
12
+ deprecated: 'opencli linux-do latest is kept for backward compatibility.',
13
+ replacedBy: 'opencli linux-do feed --view latest',
14
+ args: [
15
+ { name: 'limit', type: 'int', default: 20, help: 'Number of items (per_page)' },
16
+ ],
17
+ func: async (page, kwargs) => executeLinuxDoFeed(page, { ...kwargs, view: 'latest' }),
18
+ footerExtra: () => buildLinuxDoCompatFooter('opencli linux-do feed --view latest'),
19
+ });
@@ -0,0 +1,41 @@
1
+ site: linux-do
2
+ name: tags
3
+ description: linux.do 标签列表
4
+ domain: linux.do
5
+ strategy: cookie
6
+ browser: true
7
+
8
+ args:
9
+ limit:
10
+ type: int
11
+ default: 30
12
+ description: Number of tags
13
+
14
+ pipeline:
15
+ - navigate: https://linux.do
16
+
17
+ - evaluate: |
18
+ (async () => {
19
+ const res = await fetch('/tags.json', { credentials: 'include' });
20
+ if (!res.ok) throw new Error('HTTP ' + res.status + ' - 请先登录 linux.do');
21
+ let data;
22
+ try { data = await res.json(); } catch { throw new Error('响应不是有效 JSON - 请先登录 linux.do'); }
23
+ let tags = data?.tags || [];
24
+ tags.sort((a, b) => (b.count || 0) - (a.count || 0));
25
+ return tags.slice(0, ${{ args.limit }}).map(t => ({
26
+ id: t.id,
27
+ name: t.name || t.id,
28
+ slug: t.slug,
29
+ count: t.count || 0,
30
+ }));
31
+ })()
32
+
33
+ - map:
34
+ rank: ${{ index + 1 }}
35
+ name: ${{ item.name }}
36
+ count: ${{ item.count }}
37
+ slug: ${{ item.slug }}
38
+ id: ${{ item.id }}
39
+ url: https://linux.do/tag/${{ item.slug }}
40
+
41
+ columns: [rank, name, count, url]
@@ -2,6 +2,7 @@ site: linux-do
2
2
  name: topic
3
3
  description: linux.do 帖子详情和回复(首页)
4
4
  domain: linux.do
5
+ strategy: cookie
5
6
  browser: true
6
7
 
7
8
  args:
@@ -10,23 +11,60 @@ args:
10
11
  type: int
11
12
  required: true
12
13
  description: Topic ID
14
+ limit:
15
+ type: int
16
+ default: 20
17
+ description: Number of posts
18
+ main_only:
19
+ type: bool
20
+ default: false
21
+ description: Only return the main post body without truncation
13
22
 
14
23
  pipeline:
15
24
  - navigate: https://linux.do
16
25
 
17
26
  - evaluate: |
18
27
  (async () => {
28
+ const mainOnly = ${{ args.main_only }};
29
+ const toLocalTime = (utcStr) => {
30
+ if (!utcStr) return '';
31
+ const date = new Date(utcStr);
32
+ return Number.isNaN(date.getTime()) ? utcStr : date.toLocaleString();
33
+ };
19
34
  const res = await fetch('/t/${{ args.id }}.json', { credentials: 'include' });
20
35
  if (!res.ok) throw new Error('HTTP ' + res.status + ' - 请先登录 linux.do');
21
36
  let data;
22
37
  try { data = await res.json(); } catch { throw new Error('响应不是有效 JSON - 请先登录 linux.do'); }
23
- const strip = (html) => (html || '').replace(/<br\s*\/?>/gi, ' ').replace(/<\/(p|div|li|blockquote|h[1-6])>/gi, ' ').replace(/<[^>]+>/g, '').replace(/&nbsp;/g, ' ').replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&#(?:(\d+)|x([0-9a-fA-F]+));/g, (_, dec, hex) => { try { return String.fromCodePoint(dec !== undefined ? Number(dec) : parseInt(hex, 16)); } catch { return ''; } }).replace(/\s+/g, ' ').trim();
38
+ const strip = (html) => (html || '')
39
+ .replace(/<br\s*\/?>/gi, ' ')
40
+ .replace(/<\/(p|div|li|blockquote|h[1-6])>/gi, ' ')
41
+ .replace(/<[^>]+>/g, '')
42
+ .replace(/&nbsp;/g, ' ')
43
+ .replace(/&amp;/g, '&')
44
+ .replace(/&lt;/g, '<')
45
+ .replace(/&gt;/g, '>')
46
+ .replace(/&quot;/g, '"')
47
+ .replace(/&#(?:(\d+)|x([0-9a-fA-F]+));/g, (_, dec, hex) => {
48
+ try { return String.fromCodePoint(dec !== undefined ? Number(dec) : parseInt(hex, 16)); } catch { return ''; }
49
+ })
50
+ .replace(/\s+/g, ' ')
51
+ .trim();
24
52
  const posts = data?.post_stream?.posts || [];
25
- return posts.map(p => ({
53
+ if (mainOnly) {
54
+ const mainPost = posts.find(p => p.post_number === 1);
55
+ if (!mainPost) return [];
56
+ return [{
57
+ author: mainPost.username || '',
58
+ content: mainPost.cooked || '',
59
+ likes: mainPost.like_count || 0,
60
+ created_at: toLocalTime(mainPost.created_at),
61
+ }];
62
+ }
63
+ return posts.slice(0, ${{ args.limit }}).map(p => ({
26
64
  author: p.username,
27
65
  content: strip(p.cooked).slice(0, 200),
28
66
  likes: p.like_count,
29
- created_at: p.created_at,
67
+ created_at: toLocalTime(p.created_at),
30
68
  }));
31
69
  })()
32
70