xiaoshuo commited on
Commit
d92239a
·
1 Parent(s): 7258810

热榜 AI 阅读版:输出榜单原文给 AI 直接创作

Browse files
fanqie/mount.js CHANGED
@@ -90,14 +90,15 @@ module.exports = function mountFanqie(app, passwordOk, express) {
90
  res.setHeader('Content-Disposition', `attachment; filename="batch-${String(number).padStart(3, '0')}.jsonl"`)
91
  res.type('application/x-ndjson').send(data)
92
  }))
93
- // 热榜灵感包「AI 阅读版」:纯文本,给能上网的 AI 直接读。浏览器外的 AI 发不了请求头,所以允许 ?key=访问密码。
94
- app.get('/fanqie/feed/rank.md', async (req, res) => {
95
  const ok = passwordOk(req) || passwordOk({ headers: { 'x-app-password': String(req.query.key || '') } })
96
  if (!ok) return res.status(401).type('text/plain; charset=utf-8').send('需要访问密码:在链接后加 ?key=访问密码')
97
  try {
98
- const r = await require('./rank.js').feed({ date: String(req.query.date || ''), scope: String(req.query.scope || 'all'), brief: req.query.brief === '1' })
 
99
  res.setHeader('Cache-Control', 'no-cache')
100
- res.type('text/markdown; charset=utf-8').send(r.text)
101
  } catch (e) { res.status(500).type('text/plain; charset=utf-8').send(e.message || String(e)) }
102
  })
103
  app.use('/fanqie', express.static(DIST, { index: false, maxAge: '1h' }))
 
90
  res.setHeader('Content-Disposition', `attachment; filename="batch-${String(number).padStart(3, '0')}.jsonl"`)
91
  res.type('application/x-ndjson').send(data)
92
  }))
93
+ // 热榜「AI 阅读版」(榜单原文):纯文本,给能上网的 AI 直接读。浏览器外的 AI 发不了请求头,所以允许 ?key=访问密码。
94
+ app.get(['/fanqie/feed/rank.md', '/fanqie/feed/rank.json'], async (req, res) => {
95
  const ok = passwordOk(req) || passwordOk({ headers: { 'x-app-password': String(req.query.key || '') } })
96
  if (!ok) return res.status(401).type('text/plain; charset=utf-8').send('需要访问密码:在链接后加 ?key=访问密码')
97
  try {
98
+ const q = req.query, json = req.path.endsWith('.json')
99
+ const r = await require('./rank.js').feed({ date: String(q.date || ''), scope: String(q.scope || 'all'), mold: String(q.mold || 'both'), top: q.top, abs: q.abs ?? null, task: String(q.task || ''), idea: String(q.idea || ''), format: json ? 'json' : 'md' })
100
  res.setHeader('Cache-Control', 'no-cache')
101
+ res.type(json ? 'application/json; charset=utf-8' : 'text/markdown; charset=utf-8').send(r.text)
102
  } catch (e) { res.status(500).type('text/plain; charset=utf-8').send(e.message || String(e)) }
103
  })
104
  app.use('/fanqie', express.static(DIST, { index: false, maxAge: '1h' }))
fanqie/rank.js CHANGED
@@ -447,93 +447,64 @@ function parseResult(text) {
447
  try { return JSON.parse(body) } catch { const e = new Error('没能读出总纲:请确认粘贴的是 AI 输出的完整 JSON'); e.status = 400; throw e }
448
  }
449
 
450
- /* ---------------- 灵感卡(AI 阅读榜单后撰写)+ AI 阅读版文本 ---------------- */
451
- // fanqie_rank/inspire/index.json { dates: [] }
452
- // fanqie_rank/inspire/YYYY-MM-DD.json { date, by, at, overview: { '1': {...}, '0': {...} }, cards: { '<g>_<cid>': card } }
453
- async function inspireIndex() { return await getJ(P + 'inspire/index.json', { dates: [] }) || { dates: [] } }
454
- async function inspireFor(date) {
455
- const k = 'insp:' + (date || 'latest')
456
- if (CACHE.has(k)) return CACHE.get(k)
457
- const idx = await inspireIndex()
458
- const dates = [...(idx.dates || [])].sort().reverse()
459
- const d = date ? (dates.find(x => x <= date) || dates[dates.length - 1]) : dates[0]
460
- const doc = d ? await getJ(`${P}inspire/${d}.json`, null) : null
461
- CACHE.set(k, doc)
462
- return doc
463
  }
464
- const L = v => (Array.isArray(v) ? v : []).filter(Boolean)
465
- const bullets = (title, arr, fmt = x => String(x)) => { const a = L(arr); return a.length ? [`${title}`, ...a.map(x => `- ${fmt(x)}`), ''] : [] }
466
- function cardLines(card, { brief = false } = {}) {
467
- if (!card) return []
468
- const out = []
469
- if (card.verdict) out.push(`判断:${card.verdict}`, '')
470
- out.push(...bullets('读者在为什么买单:', card.reader_wants))
471
- out.push(...bullets('热门组合:', card.hot_combos, x => `${x.combo}${L(x.examples).length ? `(例:${L(x.examples).join(';')})` : ''}${x.note ? `:${x.note}` : ''}`))
472
- out.push(...bullets('开篇钩子写法:', card.openings))
473
- if (!brief) {
474
- out.push(...bullets('书名公式:', card.title_patterns))
475
- out.push(...bullets('简介写法:', card.blurb_tips))
476
- out.push(...bullets('正在冒头:', card.rising))
477
- out.push(...bullets('已经挤满(慎入):', card.saturated))
478
- }
479
- out.push(...bullets('还没写透的空白:', card.gaps))
480
- if (!brief) out.push(...bullets('灵感种子(原创点子,可直接展开):', card.seeds, x => `《${x.title}》${x.logline}${x.hook ? ` |开篇:${x.hook}` : ''}${x.why ? ` |理由:${x.why}` : ''}`))
481
- out.push(...bullets('避坑:', card.avoid))
482
- return out
483
- }
484
- // scope: all | g1 | g0 | <gender>_<cid>;brief=1 只给写作台用的精简版
485
- async function feed({ date = '', scope = 'all', brief = false } = {}) {
486
  const a = await analysisFor(date)
487
  if (a.empty) return { text: '还没有榜单数据。', date: '', scope }
488
- const insp = await inspireFor(a.date)
489
- const cats = a.cats || []
490
- const one = /^[01]_\d+$/.test(scope) ? cats.find(c => `${c.gender}_${c.cid}` === scope) : null
491
- const gens = one ? [one.gender] : scope === 'g1' ? [1] : scope === 'g0' ? [0] : [1, 0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
492
  const out = []
493
- const title = one ? `${one.g} · ${one.name}` : gens.length === 1 ? GEN[gens[0]] : '全部分类'
494
  if (brief) {
495
- out.push(`【番茄热榜灵感 · ${title}(榜单 ${a.date}${insp ? `,编辑判断 ${insp.date}` : ''})】`)
496
- out.push('以下是番茄小说同类书的读者偏好和写法观察,只借鉴爽点、节奏和钩子写法,书名、人物、情节一律不得照搬。')
497
- if (one) out.push(`数据:占${one.g}阅读榜 ${(one.read_share * 100).toFixed(1)}%、新书榜 ${(one.fresh_share * 100).toFixed(1)}%,新书机会 ${one.chance.toFixed(2)}`)
498
- out.push(...cardLines(insp?.cards?.[scope], { brief: true }))
499
- return { text: out.join('\n').trim(), date: a.date, inspire_date: insp?.date || '', scope }
500
  }
501
- out.push(`# 番茄热榜灵感包(AI 阅读版)· ${title}`)
502
- out.push(`榜单日期:${a.date}${insp ? `|编辑判断(AI 读榜后撰写):${insp.date}` : '|编辑判断:暂无'}`)
503
- out.push('', '## 怎么用', '- 这是番茄小说官网分类榜(阅读榜 = 读者长期买账的老书,新书榜 = 近期风向)的数据和编辑判断,用来给小说创作提供灵感。',
504
- '- 新书机会 = 新书榜份额 ÷ 阅读榜份额,大于 1 说明新书在这个分类更容易冒头。', '- 只借鉴题材趋势、爽点组合和钩子写法;榜上的书名、人物、情节一律不得照搬。', '')
505
- for (const g of gens) {
506
- const mine = cats.filter(c => c.gender === g && (!one || c === one)).sort((x, y) => y.read_share - x.read_share)
507
- if (!one) {
508
- out.push(`## ${GEN[g]}总览`)
509
- const ov = insp?.overview?.[g]
510
- if (ov) { if (ov.summary) out.push(ov.summary); out.push(...bullets('', ov.points).slice(1)) }
511
- out.push('', '| 分类 | 阅读榜份额 | 新书榜份额 | 新书机会 | 新书字数中位 |', '|---|---|---|---|---|')
512
- for (const c of mine) out.push(`| ${c.name} | ${(c.read_share * 100).toFixed(1)}% | ${(c.fresh_share * 100).toFixed(1)}% | ${c.chance.toFixed(2)} | ${Math.round((c.fresh?.words_med || 0) / 1e4)}万 |`)
513
- const hot = (a.tags?.[`${g}_2`]?.list || []).slice(0, 20).map(t => t.k)
514
- const up = (a.rising?.[g] || []).slice(0, 12).map(t => `${t.k}(+${(t.d * 100).toFixed(0)}%)`)
515
- const lab = (a.labels?.[`${g}_1`] || []).slice(0, 20).map(t => t.k)
516
- out.push('', `长期热门标签:${hot.join('、')}`, `新书榜上升标签:${up.join('、')}`, `新书简介常用卖点:${lab.join('、')}`, '')
517
- }
518
- for (const c of mine) {
519
- out.push(`## ${c.g} · ${c.name}`)
520
- out.push(`数据:阅读榜份额 ${(c.read_share * 100).toFixed(1)}%|新书榜份额 ${(c.fresh_share * 100).toFixed(1)}%|新书机会 ${c.chance.toFixed(2)}|阅读榜前20完结 ${Math.round((c.read?.done_share || 0) * 100)}%|字数中位 老书 ${Math.round((c.read?.words_med || 0) / 1e4)}万 / 新书 ${Math.round((c.fresh?.words_med || 0) / 1e4)}万`)
521
- const card = insp?.cards?.[`${c.gender}_${c.cid}`]
522
- if (card) out.push('', ...cardLines(card))
523
- else out.push('(这个分类还没有编辑判断)', '')
524
- if (one) {
525
- const { snap } = await snapshot(a.date)
526
- for (const [mold, name] of [[2, '阅读榜前 15'], [1, '新书榜前 15']]) {
527
- const l = snap?.lists.find(x => x.gender === c.gender && x.cid === c.cid && x.mold === mold)
528
- if (!l) continue
529
- out.push(`${name}:`)
530
- for (const b of l.books.slice(0, 15)) out.push(`${b.pos}.《${b.title}》${Math.round(b.reads / 1e4)}万在读·${Math.round(b.words / 1e4)}万字${b.done ? '·完结' : ''}${b.tags ? `·${b.tags.slice(0, 6).join('/')}` : ''}|${String(b.abs || '').replace(/\s+/g, ' ').slice(0, 90)}`)
531
- out.push('')
532
- }
533
- }
534
  }
 
535
  }
536
- return { text: out.join('\n').replace(/\n{3,}/g, '\n\n').trim() + '\n', date: a.date, inspire_date: insp?.date || '', scope }
 
537
  }
538
 
539
  module.exports = function buildRank(express) {
@@ -569,22 +540,8 @@ module.exports = function buildRank(express) {
569
  await putJ(`${P}ai/${date}.json`, doc)
570
  return doc
571
  }))
572
- // 灵感卡:AI 读完榜单后写入(按分类合并,可分批上传)
573
- router.get('/inspire', wrap(async req => (await inspireFor(String(req.query.date || ''))) || { cards: {}, overview: {} }))
574
- router.put('/inspire/:date', wrap(async req => {
575
- const date = String(req.params.date)
576
- if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) throw bad('日期格式不对')
577
- const b = req.body || {}
578
- const doc = (await getJ(`${P}inspire/${date}.json`, null)) || { date, cards: {}, overview: {} }
579
- for (const c of L(b.cards)) { if (c && /^[01]$/.test(String(c.gender)) && c.cid) doc.cards[`${c.gender}_${c.cid}`] = c }
580
- if (b.overview && typeof b.overview === 'object') Object.assign(doc.overview, b.overview)
581
- Object.assign(doc, { by: String(b.by || doc.by || 'AI'), at: now() })
582
- await putJ(`${P}inspire/${date}.json`, doc)
583
- const idx = await inspireIndex(); if (!idx.dates.includes(date)) { idx.dates.push(date); await putJ(P + 'inspire/index.json', idx) }
584
- for (const k of [...CACHE.keys()]) if (k.startsWith('insp:')) CACHE.delete(k)
585
- return { date, cards: Object.keys(doc.cards).length }
586
- }))
587
- router.get('/feed', wrap(req => feed({ date: String(req.query.date || ''), scope: String(req.query.scope || 'all'), brief: req.query.brief === '1' })))
588
  router.get('/plans', wrap(() => planIndex()))
589
  router.get('/plans/:id', wrap(async req => { const p = await getJ(`${P}plans/${req.params.id}.json`, null); if (!p) { const e = new Error('没有这个规划'); e.status = 404; throw e } return p }))
590
  router.post('/plans', wrap(async req => {
@@ -658,4 +615,4 @@ module.exports = function buildRank(express) {
658
  return router
659
  }
660
  module.exports.feed = feed
661
- module.exports._internal = { inspireFor, scrape, enrich, missingOf, applyBooks, loadState, JOB, analysisFor, snapshot, decode, learn, bookPage, rankList, categories, FONT: () => FONT }
 
447
  try { return JSON.parse(body) } catch { const e = new Error('没能读出总纲:请确认粘贴的是 AI 输出的完整 JSON'); e.status = 400; throw e }
448
  }
449
 
450
+ /* ---------------- AI 阅读版:把榜单原文整理成 AI 好读的文本 / JSON,直接拿去创作 ---------------- */
451
+ const TASKS = {
452
+ idea: '读完以上榜单,找出读者反复买账的题材组合和爽点,以及新书正在冒头、还没写透的方向;然后给出 5 个原创选题,每个写清书名、一句话梗概、金手指或核心设定、第一章怎么抓人。',
453
+ plan: '读完以上榜单,策划一本能在番茄冲榜的原创新书,输出总纲:书名、简介(含【】卖点标签)、核心设定、主要人物、主线、分卷规划,以及前 30 章每章一句话章纲和章末钩子。',
454
+ write: '读完以上榜单,学习这些书的开篇节奏和钩子写法,原创一本新书,直接写出第一章正文(2000–3000 字):开头 300 字内出现冲突,章末留钩子。',
 
 
 
 
 
 
 
 
455
  }
456
+ const wanS = n => (n >= 1e4 ? `${Math.round(n / 1e4)}万` : String(n || 0))
457
+ function catsOf(a) { return (a.cats || []).map(c => ({ k: `${c.gender}_${c.cid}`, gender: c.gender, g: c.g, name: c.name })) }
458
+ // scope: all | g1 | g0 | <gender>_<cid>;mold: both|2|1;top: 每榜前几本;abs: 简介字数(0 不要,-1 完整)
459
+ async function feed({ date = '', scope = 'all', mold = 'both', top = 0, abs = null, task = '', idea = '', format = 'md', brief = false } = {}) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
460
  const a = await analysisFor(date)
461
  if (a.empty) return { text: '还没有榜单数据。', date: '', scope }
462
+ const { snap } = await snapshot(a.date)
463
+ const one = /^[01]_\d+$/.test(scope)
464
+ const gens = one ? [Number(scope[0])] : scope === 'g1' ? [1] : scope === 'g0' ? [0] : [1, 0]
465
+ if (brief) { top = top || 10; abs = abs ?? 100 }
466
+ top = Math.max(1, Math.min(100, Number(top) || (one ? 50 : 20)))
467
+ abs = abs === null || abs === '' ? (one ? -1 : 120) : Number(abs)
468
+ const molds = mold === '2' ? [2] : mold === '1' ? [1] : [2, 1]
469
+ const cats = (a.cats || []).filter(c => gens.includes(c.gender) && (!one || `${c.gender}_${c.cid}` === scope)).sort((x, y) => x.gender === y.gender ? y.read_share - x.read_share : y.gender - x.gender)
470
+ const cut = t => { const v = String(t || '').replace(/\s+/g, ' ').trim(); return abs < 0 ? v : abs === 0 ? '' : v.slice(0, abs) + (v.length > abs ? '…' : '') }
471
+ const bookOf = b => ({ rank: b.pos, title: b.title, author: b.author, reads: b.reads, words: b.words, status: b.done ? '完结' : '连载', tags: b.tags || [], abstract: cut(b.abs) })
472
+ const data = cats.map(c => ({
473
+ channel: c.g, category: c.name, gender: c.gender, cid: c.cid,
474
+ stats: { read_share: +c.read_share.toFixed(4), fresh_share: +c.fresh_share.toFixed(4), new_book_chance: +c.chance.toFixed(2), read_top20_done: +(c.read?.done_share || 0).toFixed(2), read_words_median: c.read?.words_med || 0, fresh_words_median: c.fresh?.words_med || 0 },
475
+ lists: Object.fromEntries(molds.map(m => [m === 2 ? 'reading' : 'new', (snap?.lists.find(l => l.gender === c.gender && l.cid === c.cid && l.mold === m)?.books || []).slice(0, top).map(bookOf)])),
476
+ }))
477
+ const title = one ? `${cats[0]?.g || ''}·${cats[0]?.name || ''}` : gens.length === 1 ? GEN[gens[0]] : '男频+女频'
478
+ const taskText = [TASKS[task] || '', String(idea || '').trim() && `作者的想法/要求:${String(idea).trim()}`].filter(Boolean).join('\n')
479
+ const rule = '借鉴榜单里的题材趋势、爽点组合和钩子写法;书名、人物、设定细节、情节必须原创,不得照搬任何一本书。'
480
+ if (format === 'json') {
481
+ const obj = { source: '番茄小说官网分类榜', date: a.date, scope: title, note: 'reading=阅读榜(在读人数最多的书,代表读者长期买账);new=新书榜(近期新书,代表现在的风向);reads=在读人数;words=字数;new_book_chance=新书榜份额÷阅读榜份额,>1 说明新书在这个分类更容易冒头', rule, task: taskText || undefined, categories: data }
482
+ return { text: JSON.stringify(obj, null, 1), date: a.date, scope, chars: 0 }
483
+ }
484
  const out = []
 
485
  if (brief) {
486
+ const c = data[0]
487
+ if (!c) return { text: '', date: a.date, scope }
488
+ out.push(`【番茄热榜 · ${c.channel}·${c.category}(${a.date})同类书参考】`, rule)
489
+ for (const [k, l] of Object.entries(c.lists)) { out.push(k === 'reading' ? '阅读榜前列:' : '新书榜前列:'); for (const b of l) out.push(`${b.rank}.《${b.title}》${wanS(b.reads)}在读|${b.tags.slice(0, 6).join('/')}|${b.abstract}`) }
490
+ return { text: out.join('\n'), date: a.date, scope }
491
  }
492
+ out.push(`# 番茄小说热榜 · ${title}(${a.date})`, '',
493
+ '说明:数据来自番茄小说官网分类榜。阅读榜 = 在读人数最多的书,代表读者长期买账的东西;新书榜 = 近期新书,代表现在的风向和竞争。',
494
+ '每行格式:排名.《书名》作者|在读人数|字数|完结/连载|官方标签|简介。新书机会 = 新书榜份额 ÷ 阅读榜份额,大于 1 说明新书在这个分类更容易冒头。',
495
+ `创作规则:${rule}`, '')
496
+ if (taskText) out.push('## 你的任务', taskText, '')
497
+ for (const c of data) {
498
+ const s = c.stats
499
+ out.push(`## ${c.channel}·${c.category}`, `占${c.channel}阅读榜在读 ${(s.read_share * 100).toFixed(1)}%,新书榜 ${(s.fresh_share * 100).toFixed(1)}%,新书机会 ${s.new_book_chance};阅读榜前20完结 ${Math.round(s.read_top20_done * 100)}%,字数中位 老书 ${wanS(s.read_words_median)} / 新书 ${wanS(s.fresh_words_median)}`)
500
+ for (const [k, l] of Object.entries(c.lists)) {
501
+ out.push('', `### ${k === 'reading' ? '阅读榜' : '新书榜'}前 ${l.length}`)
502
+ for (const b of l) out.push(`${b.rank}.《${b.title}》${b.author || ''}|${wanS(b.reads)}在读|${wanS(b.words)}字|${b.status}|${b.tags.join('/') || '—'}${b.abstract ? `|${b.abstract}` : ''}`)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
503
  }
504
+ out.push('')
505
  }
506
+ if (taskText) out.push('## 你的任务(再次提醒)', taskText)
507
+ return { text: out.join('\n').trim() + '\n', date: a.date, scope }
508
  }
509
 
510
  module.exports = function buildRank(express) {
 
540
  await putJ(`${P}ai/${date}.json`, doc)
541
  return doc
542
  }))
543
+ router.get('/cats', wrap(async () => { const a = await analysisFor(''); return { date: a.date || '', cats: a.empty ? [] : catsOf(a) } }))
544
+ router.get('/feed', wrap(req => { const q = req.query; return feed({ date: String(q.date || ''), scope: String(q.scope || 'all'), mold: String(q.mold || 'both'), top: q.top, abs: q.abs ?? null, task: String(q.task || ''), idea: String(q.idea || ''), format: String(q.format || 'md'), brief: q.brief === '1' }) }))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
545
  router.get('/plans', wrap(() => planIndex()))
546
  router.get('/plans/:id', wrap(async req => { const p = await getJ(`${P}plans/${req.params.id}.json`, null); if (!p) { const e = new Error('没有这个规划'); e.status = 404; throw e } return p }))
547
  router.post('/plans', wrap(async req => {
 
615
  return router
616
  }
617
  module.exports.feed = feed
618
+ module.exports._internal = { scrape, enrich, missingOf, applyBooks, loadState, JOB, analysisFor, snapshot, decode, learn, bookPage, rankList, categories, FONT: () => FONT }
public/assets/{index-62jZraMF.css → index-DyAFvcZ9.css} RENAMED
The diff for this file is too large to render. See raw diff
 
public/assets/{index-CFb6cFIp.js → index-FUYCcNCM.js} RENAMED
The diff for this file is too large to render. See raw diff
 
public/index.html CHANGED
@@ -8,8 +8,8 @@
8
  <title>小说写作台</title>
9
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='12' fill='%23b8432f'/%3E%3Ctext x='32' y='44' font-size='34' text-anchor='middle' fill='%23fff' font-family='serif'%3E%E6%96%87%3C/text%3E%3C/svg%3E" />
10
  <script>try{var t=localStorage.getItem('xs_theme');if(t==='night')document.documentElement.dataset.theme='night'}catch(e){}</script>
11
- <script type="module" crossorigin src="/assets/index-CFb6cFIp.js"></script>
12
- <link rel="stylesheet" crossorigin href="/assets/index-62jZraMF.css">
13
  </head>
14
  <body>
15
  <div id="root"></div>
 
8
  <title>小说写作台</title>
9
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='12' fill='%23b8432f'/%3E%3Ctext x='32' y='44' font-size='34' text-anchor='middle' fill='%23fff' font-family='serif'%3E%E6%96%87%3C/text%3E%3C/svg%3E" />
10
  <script>try{var t=localStorage.getItem('xs_theme');if(t==='night')document.documentElement.dataset.theme='night'}catch(e){}</script>
11
+ <script type="module" crossorigin src="/assets/index-FUYCcNCM.js"></script>
12
+ <link rel="stylesheet" crossorigin href="/assets/index-DyAFvcZ9.css">
13
  </head>
14
  <body>
15
  <div id="root"></div>
ui-src/src/rooms/Editor.tsx CHANGED
@@ -9,7 +9,7 @@ import { cnNum, copyText, countWords, cx, diffParagraphs, fmtAgo, fmtDate, go, C
9
  import { AutoText, Empty, ErrorNote, Field, ListEditor, Loading, Modal, Spinner, Tabs, useConfirm, useToast, Segmented } from '../ui'
10
  import type { BookCtx } from './Book'
11
  import { toRef } from './Bible'
12
- import { inspireApi } from './RankInspire'
13
 
14
  type Tab = 'chapter' | 'versions' | 'check' | 'refs' | 'ai'
15
  const draftKey = (cid: string) => `xs_draft_${cid}`
@@ -589,10 +589,10 @@ function AiPanel({ ctx, detail, text }: { ctx: BookCtx; detail: Chapter; text: s
589
  const pid = bundle.project.project_id
590
  const [inspOn, setInspOn] = useLocal<boolean>('ai-insp-on', true)
591
  const [inspPick, setInspPick] = useLocal<string>(`ai-insp-${pid}`, '')
592
- const ins = useAsync(() => inspireApi.inspire().catch(() => null), [])
593
- const inspCards = useMemo(() => Object.entries(ins.data?.cards || {}).map(([k, c]: [string, any]) => ({ k, g: String(c.gender) === '1' ? '男频' : '女频', name: c.cname })), [ins.data])
594
  const inspScope = inspPick || guessScope(GENRE[bundle.project.genre] || bundle.project.genre || '', inspCards)
595
- const insp = useAsync(() => (inspOn && inspScope && inspScope !== 'none' ? inspireApi.feed(inspScope, true).then(r => r.text).catch(() => '') : Promise.resolve('')), [inspOn, inspScope])
596
  const inspText = task === 'draft' || task === 'next' || task === 'continue' ? insp.data || '' : ''
597
  const prompt = useMemo(() => buildPrompt(bundle, detail, text, task, extra, inspText), [bundle, detail, text, task, extra, inspText])
598
  return (
@@ -607,12 +607,12 @@ function AiPanel({ ctx, detail, text }: { ctx: BookCtx; detail: Chapter; text: s
607
  <Field label="补充要求(可不填)"><AutoText value={extra} onChange={setExtra} minRows={2} placeholder="例如:节奏再快一点,结尾留一个悬念。" /></Field>
608
  {inspCards.length > 0 && (
609
  <div className="insp-pick">
610
- <label className="row gap"><input type="checkbox" checked={inspOn} onChange={e => setInspOn(e.target.checked)} /><b>附上番茄热榜灵感</b></label>
611
  {inspOn && <select value={inspScope || 'none'} onChange={e => setInspPick(e.target.value)}>
612
  <option value="none">选择本书所在的番茄分类…</option>
613
  {inspCards.map(c => <option key={c.k} value={c.k}>{c.g} · {c.name}</option>)}
614
  </select>}
615
- <div className="muted small-note">{inspOn ? (inspText ? `已附上 ${inspText.length} 字:同类热书的读者偏好、开篇钩子和空白点,AI 只借鉴写法不照搬。` : task === 'draft' || task === 'next' || task === 'continue' ? (inspScope && inspScope !== 'none' ? '正在读取…' : '选好分类后自动附上。') : '润色和审读不附灵感。') : '已关闭。'}</div>
616
  </div>
617
  )}
618
  <div className="prompt-box">
 
9
  import { AutoText, Empty, ErrorNote, Field, ListEditor, Loading, Modal, Spinner, Tabs, useConfirm, useToast, Segmented } from '../ui'
10
  import type { BookCtx } from './Book'
11
  import { toRef } from './Bible'
12
+ import { feedApi } from './RankInspire'
13
 
14
  type Tab = 'chapter' | 'versions' | 'check' | 'refs' | 'ai'
15
  const draftKey = (cid: string) => `xs_draft_${cid}`
 
589
  const pid = bundle.project.project_id
590
  const [inspOn, setInspOn] = useLocal<boolean>('ai-insp-on', true)
591
  const [inspPick, setInspPick] = useLocal<string>(`ai-insp-${pid}`, '')
592
+ const ins = useAsync(() => feedApi.cats().catch(() => null), [])
593
+ const inspCards = useMemo(() => (ins.data?.cats || []).map(c => ({ k: c.k, g: c.g, name: c.name })), [ins.data])
594
  const inspScope = inspPick || guessScope(GENRE[bundle.project.genre] || bundle.project.genre || '', inspCards)
595
+ const insp = useAsync(() => (inspOn && inspScope && inspScope !== 'none' ? feedApi.feed({ scope: inspScope, brief: true }).then(r => r.text).catch(() => '') : Promise.resolve('')), [inspOn, inspScope])
596
  const inspText = task === 'draft' || task === 'next' || task === 'continue' ? insp.data || '' : ''
597
  const prompt = useMemo(() => buildPrompt(bundle, detail, text, task, extra, inspText), [bundle, detail, text, task, extra, inspText])
598
  return (
 
607
  <Field label="补充要求(可不填)"><AutoText value={extra} onChange={setExtra} minRows={2} placeholder="例如:节奏再快一点,结尾留一个悬念。" /></Field>
608
  {inspCards.length > 0 && (
609
  <div className="insp-pick">
610
+ <label className="row gap"><input type="checkbox" checked={inspOn} onChange={e => setInspOn(e.target.checked)} /><b>附上番茄热榜同类书(原文)</b></label>
611
  {inspOn && <select value={inspScope || 'none'} onChange={e => setInspPick(e.target.value)}>
612
  <option value="none">选择本书所在的番茄分类…</option>
613
  {inspCards.map(c => <option key={c.k} value={c.k}>{c.g} · {c.name}</option>)}
614
  </select>}
615
+ <div className="muted small-note">{inspOn ? (inspText ? `已附上 ${inspText.length} 字:同类热榜前 10 本的书名、在读、标签和简介,AI 读完再写,只借鉴不照搬。` : task === 'draft' || task === 'next' || task === 'continue' ? (inspScope && inspScope !== 'none' ? '正在读取…' : '选好分类后自动附上。') : '润色和审读不附榜单。') : '已关闭。'}</div>
616
  </div>
617
  )}
618
  <div className="prompt-box">
ui-src/src/rooms/Rank.tsx CHANGED
@@ -4,7 +4,7 @@ import { get, post, put, del, qs } from '../api'
4
  import { copyText, cx, fmtAgo, fmtNum, go, useAsync, useLocal } from '../lib'
5
  import { Drawer, Empty, ErrorNote, Loading, Segmented, Tabs, Tag, useToast, useConfirm } from '../ui'
6
  import { buildPack } from './rankPack'
7
- import { InspireTab, inspireApi } from './RankInspire'
8
 
9
  const A = '/fanqie/api/rank'
10
  const api = {
@@ -21,7 +21,7 @@ const api = {
21
  delPlan: (id: string) => del<any>(`${A}/plans/${id}`),
22
  toProject: (id: string) => post<any>(`${A}/plans/${id}/project`, {}),
23
  }
24
- type TabId = 'board' | 'analysis' | 'inspire' | 'plan' | 'plans'
25
  const G: Record<string, string> = { '1': '男频', '0': '女频' }
26
  const MOLD: Record<string, string> = { '2': '阅读榜', '1': '新书榜' }
27
  export const pct = (x: number | null | undefined, d = 1) => (x == null ? '—' : `${(x * 100).toFixed(d)}%`)
@@ -30,7 +30,7 @@ export type PlanDraft = { gender: string; cid: string; tags: string[]; idea: str
30
  const EMPTY_DRAFT: PlanDraft = { gender: '1', cid: '', tags: [], idea: '', words: '100', pov: '第三人称', extra: '' }
31
 
32
  export default function RankRoom({ tab, arg }: { tab: string; arg: string }) {
33
- const t = (['board', 'analysis', 'inspire', 'plan', 'plans'].includes(tab) ? tab : 'analysis') as TabId
34
  const ana = useAsync(() => api.analysis(), [])
35
  const [openBook, setOpenBook] = useState('')
36
  const date = ana.data?.date
@@ -47,7 +47,7 @@ export default function RankRoom({ tab, arg }: { tab: string; arg: string }) {
47
  <ScrapeBox date={date} onDone={() => ana.reload()} />
48
  </header>
49
  <Tabs<TabId> value={t} onChange={v => go(`rank/${v}`)} className="room-tabs" items={[
50
- { id: 'analysis', label: '趋势分析' }, { id: 'board', label: '榜单' }, { id: 'inspire', label: 'AI 灵感' }, { id: 'plan', label: '规划总纲' }, { id: 'plans', label: '我的规划' },
51
  ]} />
52
  <div className="room-body">
53
  {ana.loading && !ana.data && <Loading label="正在读取榜单数据…" />}
@@ -55,7 +55,7 @@ export default function RankRoom({ tab, arg }: { tab: string; arg: string }) {
55
  {ana.data?.empty && t !== 'plans' && <Empty icon={<TrendingUp size={22} />} title="还没有榜单数据">点右上角「立即抓取」,大约需要 5–10 分钟。</Empty>}
56
  {ana.data && !ana.data.empty && t === 'analysis' && <AnalysisTab a={ana.data} onBook={setOpenBook} />}
57
  {ana.data && !ana.data.empty && t === 'board' && <BoardTab a={ana.data} arg={arg} onBook={setOpenBook} />}
58
- {ana.data && !ana.data.empty && t === 'inspire' && <InspireTab a={ana.data} arg={arg} />}
59
  {ana.data && !ana.data.empty && t === 'plan' && <PlanTab a={ana.data} />}
60
  {t === 'plans' && <PlansTab arg={arg} />}
61
  </div>
@@ -274,9 +274,7 @@ function PlanTab({ a }: { a: any }) {
274
  for (const [k, l] of [['n', lists.data?.r], ['f', lists.data?.f]] as const) for (const b of l?.books || []) for (const t of b.tags || []) { if (skip.has(t) || t === b.main) continue; const x = m.get(t) || { n: 0, f: 0 }; x[k]++; m.set(t, x) }
275
  return [...m.entries()].map(([k, v]) => ({ k, ...v })).sort((x, y) => y.n + y.f - x.n - x.f).slice(0, 30)
276
  }, [lists.data, cat, draft.gender])
277
- const insp = useAsync(() => inspireApi.inspire().catch(() => null), [])
278
- const card = cat ? insp.data?.cards?.[`${cat.gender}_${cat.cid}`] : null
279
- const pack = useMemo(() => (cat && lists.data ? buildPack(a, cat, lists.data, catTags, draft, card) : ''), [a, cat, lists.data, catTags, draft, card])
280
  const [busy, setBusy] = useState(false)
281
  const submit = async () => {
282
  setBusy(true)
 
4
  import { copyText, cx, fmtAgo, fmtNum, go, useAsync, useLocal } from '../lib'
5
  import { Drawer, Empty, ErrorNote, Loading, Segmented, Tabs, Tag, useToast, useConfirm } from '../ui'
6
  import { buildPack } from './rankPack'
7
+ import { FeedTab } from './RankInspire'
8
 
9
  const A = '/fanqie/api/rank'
10
  const api = {
 
21
  delPlan: (id: string) => del<any>(`${A}/plans/${id}`),
22
  toProject: (id: string) => post<any>(`${A}/plans/${id}/project`, {}),
23
  }
24
+ type TabId = 'board' | 'analysis' | 'feed' | 'plan' | 'plans'
25
  const G: Record<string, string> = { '1': '男频', '0': '女频' }
26
  const MOLD: Record<string, string> = { '2': '阅读榜', '1': '新书榜' }
27
  export const pct = (x: number | null | undefined, d = 1) => (x == null ? '—' : `${(x * 100).toFixed(d)}%`)
 
30
  const EMPTY_DRAFT: PlanDraft = { gender: '1', cid: '', tags: [], idea: '', words: '100', pov: '第三人称', extra: '' }
31
 
32
  export default function RankRoom({ tab, arg }: { tab: string; arg: string }) {
33
+ const t = (['board', 'analysis', 'feed', 'plan', 'plans'].includes(tab) ? tab : 'analysis') as TabId
34
  const ana = useAsync(() => api.analysis(), [])
35
  const [openBook, setOpenBook] = useState('')
36
  const date = ana.data?.date
 
47
  <ScrapeBox date={date} onDone={() => ana.reload()} />
48
  </header>
49
  <Tabs<TabId> value={t} onChange={v => go(`rank/${v}`)} className="room-tabs" items={[
50
+ { id: 'analysis', label: '趋势分析' }, { id: 'board', label: '榜单' }, { id: 'feed', label: 'AI 阅读版' }, { id: 'plan', label: '规划总纲' }, { id: 'plans', label: '我的规划' },
51
  ]} />
52
  <div className="room-body">
53
  {ana.loading && !ana.data && <Loading label="正在读取榜单数据…" />}
 
55
  {ana.data?.empty && t !== 'plans' && <Empty icon={<TrendingUp size={22} />} title="还没有榜单数据">点右上角「立即抓取」,大约需要 5–10 分钟。</Empty>}
56
  {ana.data && !ana.data.empty && t === 'analysis' && <AnalysisTab a={ana.data} onBook={setOpenBook} />}
57
  {ana.data && !ana.data.empty && t === 'board' && <BoardTab a={ana.data} arg={arg} onBook={setOpenBook} />}
58
+ {ana.data && !ana.data.empty && t === 'feed' && <FeedTab a={ana.data} arg={arg} />}
59
  {ana.data && !ana.data.empty && t === 'plan' && <PlanTab a={ana.data} />}
60
  {t === 'plans' && <PlansTab arg={arg} />}
61
  </div>
 
274
  for (const [k, l] of [['n', lists.data?.r], ['f', lists.data?.f]] as const) for (const b of l?.books || []) for (const t of b.tags || []) { if (skip.has(t) || t === b.main) continue; const x = m.get(t) || { n: 0, f: 0 }; x[k]++; m.set(t, x) }
275
  return [...m.entries()].map(([k, v]) => ({ k, ...v })).sort((x, y) => y.n + y.f - x.n - x.f).slice(0, 30)
276
  }, [lists.data, cat, draft.gender])
277
+ const pack = useMemo(() => (cat && lists.data ? buildPack(a, cat, lists.data, catTags, draft) : ''), [a, cat, lists.data, catTags, draft])
 
 
278
  const [busy, setBusy] = useState(false)
279
  const submit = async () => {
280
  setBusy(true)
ui-src/src/rooms/RankInspire.tsx CHANGED
@@ -1,154 +1,108 @@
1
  import React, { useMemo, useState } from 'react'
2
- import { Bot, Copy, Download, Link2, Lightbulb, Sparkles, Wand2 } from 'lucide-react'
3
  import { get, getPassword, qs } from '../api'
4
- import { copyText, cx, go, useAsync } from '../lib'
5
- import { ErrorNote, Loading, Segmented, Tag, useToast } from '../ui'
6
 
 
7
  const A = '/fanqie/api/rank'
8
- export const inspireApi = {
9
- inspire: () => get<any>(`${A}/inspire`),
10
- feed: (scope: string, brief = false) => get<{ text: string; date: string; inspire_date: string }>(`${A}/feed${qs({ scope, brief: brief ? '1' : '' })}`),
 
11
  }
12
- const pct = (x: number) => `${(x * 100).toFixed(1)}%`
13
- const arr = (v: any) => (Array.isArray(v) ? v.filter(Boolean) : [])
14
 
15
- function saveFile(name: string, text: string) {
16
- const url = URL.createObjectURL(new Blob([text], { type: 'text/markdown;charset=utf-8' }))
 
 
 
 
 
 
17
  const a = document.createElement('a'); a.href = url; a.download = name; a.click()
18
  setTimeout(() => URL.revokeObjectURL(url), 1000)
19
  }
20
 
21
- export function InspireTab({ a, arg }: { a: any; arg: string }) {
22
  const toast = useToast()
23
- const ins = useAsync(() => inspireApi.inspire(), [])
24
- const scope = /^[01]_\d+$/.test(arg) || arg === 'g1' || arg === 'g0' ? arg : 'g1'
25
- const g = scope.startsWith('g') ? scope.slice(1) : scope.split('_')[0]
26
  const cats = useMemo(() => (a.cats || []).filter((c: any) => String(c.gender) === g).sort((x: any, y: any) => y.read_share - x.read_share), [a, g])
27
  const cat = cats.find((c: any) => `${c.gender}_${c.cid}` === scope)
28
- const cards = ins.data?.cards || {}
29
- const card = cat ? cards[scope] : null
30
- const feed = useAsync(() => inspireApi.feed(scope), [scope, ins.data?.at])
31
- const [showText, setShowText] = useState(false)
32
- const set = (s: string) => go(`rank/inspire/${s}`)
33
- const label = cat ? `${cat.g}·${cat.name}` : g === '1' ? '男频全部' : '女频全部'
34
- const link = `${location.origin}/fanqie/feed/rank.md${qs({ scope, key: getPassword() })}`
35
- const n = Object.keys(cards).length
36
-
37
- const toPlan = (seed: any) => {
38
- const d = { gender: g, cid: cat?.cid || '', tags: [], idea: `${seed.title ? `《${seed.title}》` : ''}${seed.logline || ''}${seed.hook ? `\n开篇:${seed.hook}` : ''}`, words: '100', pov: '第三人称', extra: '' }
39
- try { localStorage.setItem('rk-draft', JSON.stringify(d)) } catch {}
40
- go('rank/plan'); toast('已把这个点子带到「规划总纲」', 'ok')
41
- }
 
42
 
43
  return (
44
  <div className="rk-insp">
45
  <div className="rk-insp-intro">
46
  <Bot size={18} />
47
  <div>
48
- <b>给 AI 读的灵感包</b>
49
  <div className="muted small-note">
50
- 每个分类都由 AI 读完阅读榜和新书榜前 40 本后,写出读者在为什么买单、热门组合、开篇钩子、书名套路、还没写透的空白,以及原创点子。
51
- 右边是整理好的「AI 阅读版」文字,可以复制给任何 AI;写作台的「AI 提示词」也会自动附上本书所在分类的精简版。
52
- {ins.data?.date && <> 编辑判断日期:{ins.data.date},已覆盖 {n} 个分类。</>}
53
  </div>
54
  </div>
55
  </div>
 
56
  <div className="row gap rk-bar">
57
- <Segmented value={g} onChange={v => set(`g${v}`)} items={[{ id: '1', label: '男频' }, { id: '0', label: '女频' }]} />
58
  </div>
59
- <div className="chips-row">
60
  <button className={cx('chip', scope === `g${g}` && 'on')} onClick={() => set(`g${g}`)}>整个频道</button>
61
- {cats.map((c: any) => <button key={c.cid} className={cx('chip', `${c.gender}_${c.cid}` === scope && 'on')} onClick={() => set(`${c.gender}_${c.cid}`)}>{c.name}{cards[`${c.gender}_${c.cid}`] ? '' : ' ·待写'}</button>)}
62
- </div>
63
- {ins.loading && !ins.data && <Loading />}
64
- {ins.error && <ErrorNote error={ins.error} onRetry={ins.reload} />}
65
 
66
  <div className="rk-insp-grid">
67
  <div className="rk-insp-main">
68
- {!cat && <div className="rk-insp-cats">{cats.map((c: any) => {
69
- const k = `${c.gender}_${c.cid}`, x = cards[k]
70
- return (
71
- <button key={k} className="rk-insp-cat" onClick={() => set(k)}>
72
- <div className="row between"><b>{c.name}</b><span className={cx('small-note', c.chance >= 1 ? 'ok' : 'muted')}>新书机会 {c.chance.toFixed(2)}</span></div>
73
- <div className="small-note muted">阅读榜 {pct(c.read_share)} · 新书榜 {pct(c.fresh_share)}</div>
74
- <div className="rk-insp-verdict">{x?.verdict || <span className="muted">AI 还没写这个分类的灵感卡</span>}</div>
75
- </button>
76
- )
77
- })}</div>}
78
- {cat && !card && <div className="rk-ai empty"><Sparkles size={15} /><div><b>{cat.name}</b><div className="muted small-note">这个分类的灵感卡还没写好,AI 读完榜单后会出现在这里。</div></div></div>}
79
- {cat && card && <CardView card={card} cat={cat} onPlan={toPlan} />}
 
 
 
 
80
  </div>
81
 
82
  <aside className="rk-insp-side">
83
  <section className="sheet">
84
- <h2 className="sheet-title serif"><Bot size={16} />AI 阅读版 · {label}</h2>
85
- <p className="sheet-note">纯文字,包含数据、编辑判断和{cat ? '榜单前 15 本' : '各分类灵感卡'}。直接复制给 AI,或者下载成文件发给它。</p>
86
- {feed.loading && <Loading />}
87
- {feed.error && <ErrorNote error={feed.error} onRetry={feed.reload} />}
88
- {feed.data && <>
89
- <div className="muted small-note">约 {feed.data.text.length.toLocaleString()} 字</div>
90
- <div className="col gap-s rk-insp-btns">
91
- <button className="btn primary block" onClick={async () => { await copyText(feed.data!.text); toast('已复制,粘贴给 AI 即可', 'ok') }}><Copy size={14} />复制全文</button>
92
- <button className="btn ghost block" onClick={() => saveFile(`番茄热榜灵感-${label}-${feed.data!.date}.md`, feed.data!.text)}><Download size={14} />下载 .md</button>
93
- {cat && <button className="btn ghost block" onClick={async () => { const r = await inspireApi.feed(scope, true); await copyText(r.text); toast('已复制精简版(写作台用的就是这一份)', 'ok') }}><Wand2 size={14} />复制精简版</button>}
94
- <button className="btn ghost block" onClick={async () => { await copyText(link); toast('链接已复制。能上网的 AI 打开它就能读到全文', 'ok') }}><Link2 size={14} />复制给 AI 的链接</button>
95
- </div>
96
- <div className="muted small-note">链接里带着访问密码,只发给你信任的 AI 工具。</div>
97
- <button className="link-btn small-note" onClick={() => setShowText(s => !s)}>{showText ? '收起预览' : '预览全文'}</button>
98
- {showText && <pre className="pre rk-insp-pre">{feed.data.text}</pre>}
99
- </>}
100
  </section>
101
  </aside>
102
  </div>
103
  </div>
104
  )
105
  }
106
-
107
- function Block({ title, items, render }: { title: string; items: any; render?: (x: any, i: number) => React.ReactNode }) {
108
- const list = arr(items)
109
- if (!list.length) return null
110
- return (
111
- <div className="rk-insp-block">
112
- <h4>{title}</h4>
113
- <ul>{list.map((x: any, i: number) => <li key={i}>{render ? render(x, i) : String(x)}</li>)}</ul>
114
- </div>
115
- )
116
- }
117
-
118
- function CardView({ card, cat, onPlan }: { card: any; cat: any; onPlan: (s: any) => void }) {
119
- return (
120
- <div className="rk-insp-card">
121
- <div className="rk-ai">
122
- <div className="eyebrow"><Sparkles size={14} />{cat.g} · {cat.name}</div>
123
- <div className="small-note muted">阅读榜 {pct(cat.read_share)} · 新书榜 {pct(cat.fresh_share)} · 新书机会 {cat.chance.toFixed(2)} · 新书字数中位 {Math.round((cat.fresh?.words_med || 0) / 1e4)} 万</div>
124
- {card.verdict && <p className="rk-ai-sum serif">{card.verdict}</p>}
125
- </div>
126
- <div className="rk-insp-two">
127
- <Block title="读者在为什么买单" items={card.reader_wants} />
128
- <Block title="开篇钩子写法" items={card.openings} />
129
- </div>
130
- <Block title="热门组合" items={card.hot_combos} render={x => <><b>{x.combo}</b>{arr(x.examples).length > 0 && <span className="muted">({arr(x.examples).join(';')})</span>}{x.note && <div className="small-note">{x.note}</div>}</>} />
131
- <div className="rk-insp-two">
132
- <Block title="正在冒头" items={card.rising} />
133
- <Block title="还没写透的空白" items={card.gaps} />
134
- <Block title="已经挤满(慎入)" items={card.saturated} />
135
- <Block title="避坑" items={card.avoid} />
136
- <Block title="书名公式" items={card.title_patterns} />
137
- <Block title="简介写法" items={card.blurb_tips} />
138
- </div>
139
- {arr(card.seeds).length > 0 && (
140
- <div className="rk-ideas">
141
- <h4><Lightbulb size={14} /> 灵感��子(原创点子)</h4>
142
- {arr(card.seeds).map((s: any, i: number) => (
143
- <div key={i} className="rk-idea">
144
- <div className="row between"><b>《{s.title}》</b><button className="link-btn small-note" onClick={() => onPlan(s)}>用它规划总纲</button></div>
145
- <div className="small-note">{s.logline}</div>
146
- {s.hook && <div className="small-note"><Tag>开篇</Tag> {s.hook}</div>}
147
- {s.why && <div className="muted small-note">{s.why}</div>}
148
- </div>
149
- ))}
150
- </div>
151
- )}
152
- </div>
153
- )
154
- }
 
1
  import React, { useMemo, useState } from 'react'
2
+ import { Bot, Copy, Download, Link2 } from 'lucide-react'
3
  import { get, getPassword, qs } from '../api'
4
+ import { copyText, cx, go, useAsync, useLocal } from '../lib'
5
+ import { ErrorNote, Field, Loading, Segmented, useToast } from '../ui'
6
 
7
+ // 「AI 阅读版」:把番茄热榜原文整理成 AI 好读的格式(Markdown / JSON),复制给 AI 直接创作。
8
  const A = '/fanqie/api/rank'
9
+ type FeedOpt = { scope: string; mold?: string; top?: string; abs?: string; task?: string; idea?: string; format?: string; brief?: boolean }
10
+ export const feedApi = {
11
+ cats: () => get<{ date: string; cats: { k: string; gender: number; g: string; name: string }[] }>(`${A}/cats`),
12
+ feed: (o: FeedOpt) => get<{ text: string; date: string }>(`${A}/feed${qs({ ...o, brief: o.brief ? '1' : '' })}`),
13
  }
 
 
14
 
15
+ const TASKS = [
16
+ { id: '', label: '只要榜单' },
17
+ { id: 'idea', label: '找选题' },
18
+ { id: 'plan', label: '规划总纲' },
19
+ { id: 'write', label: '直接写第一章' },
20
+ ]
21
+ function saveFile(name: string, text: string, json: boolean) {
22
+ const url = URL.createObjectURL(new Blob([text], { type: json ? 'application/json;charset=utf-8' : 'text/markdown;charset=utf-8' }))
23
  const a = document.createElement('a'); a.href = url; a.download = name; a.click()
24
  setTimeout(() => URL.revokeObjectURL(url), 1000)
25
  }
26
 
27
+ export function FeedTab({ a, arg }: { a: any; arg: string }) {
28
  const toast = useToast()
29
+ const scope = /^[01]_\d+$/.test(arg) || ['g1', 'g0', 'all'].includes(arg) ? arg : 'g1'
30
+ const g = scope === 'all' ? '1' : scope.startsWith('g') ? scope.slice(1) : scope.split('_')[0]
31
+ const one = /^[01]_\d+$/.test(scope)
32
  const cats = useMemo(() => (a.cats || []).filter((c: any) => String(c.gender) === g).sort((x: any, y: any) => y.read_share - x.read_share), [a, g])
33
  const cat = cats.find((c: any) => `${c.gender}_${c.cid}` === scope)
34
+ const [mold, setMold] = useLocal('rk-feed-mold', 'both')
35
+ const [topPick, setTop] = useLocal('rk-feed-top', '')
36
+ const [absPick, setAbs] = useLocal('rk-feed-abs', '')
37
+ const [format, setFormat] = useLocal('rk-feed-format', 'md')
38
+ const [task, setTask] = useState('')
39
+ const [idea, setIdea] = useState('')
40
+ const top = topPick || (one ? '50' : '20')
41
+ const abs = absPick || (one ? '-1' : '120')
42
+ const opt = { scope, mold, top, abs, task, idea: task ? idea : '', format }
43
+ const feed = useAsync(() => feedApi.feed(opt), [scope, mold, top, abs, task, task ? idea : '', format])
44
+ const set = (s: string) => go(`rank/feed/${s}`)
45
+ const label = cat ? `${cat.g}·${cat.name}` : scope === 'all' ? '男频+女频' : g === '1' ? '男频' : '女频'
46
+ const json = format === 'json'
47
+ const link = `${location.origin}/fanqie/feed/rank.${json ? 'json' : 'md'}${qs({ scope, mold: mold === 'both' ? '' : mold, top, abs, task, idea: task ? idea : '', key: getPassword() })}`
48
+ const size = feed.data?.text.length || 0
49
 
50
  return (
51
  <div className="rk-insp">
52
  <div className="rk-insp-intro">
53
  <Bot size={18} />
54
  <div>
55
+ <b>给 AI 读的热榜原文</b>
56
  <div className="muted small-note">
57
+ 把番茄热榜的书名、在读人数、字数、标签和简介原样整理成 AI 好读的格式,不加任何人为总结。选好范围,可以附上创作任务,复制给 AI 就能直接开写。
58
+ 写作台的「AI 提示词」和「规划总纲」也会自动带上同分类的榜单。
 
59
  </div>
60
  </div>
61
  </div>
62
+
63
  <div className="row gap rk-bar">
64
+ <Segmented value={scope === 'all' ? 'all' : g} onChange={v => set(v === 'all' ? 'all' : `g${v}`)} items={[{ id: '1', label: '男频' }, { id: '0', label: '女频' }, { id: 'all', label: '男女频全部' }]} />
65
  </div>
66
+ {scope !== 'all' && <div className="chips-row">
67
  <button className={cx('chip', scope === `g${g}` && 'on')} onClick={() => set(`g${g}`)}>整个频道</button>
68
+ {cats.map((c: any) => <button key={c.cid} className={cx('chip', `${c.gender}_${c.cid}` === scope && 'on')} onClick={() => set(`${c.gender}_${c.cid}`)}>{c.name}</button>)}
69
+ </div>}
 
 
70
 
71
  <div className="rk-insp-grid">
72
  <div className="rk-insp-main">
73
+ <section className="sheet">
74
+ <div className="rk-feed-opts">
75
+ <Field label="哪个榜"><Segmented value={mold} onChange={setMold} items={[{ id: 'both', label: '两个都要' }, { id: '2', label: '阅读榜' }, { id: '1', label: '新书榜' }]} /></Field>
76
+ <Field label="每个榜前几本"><Segmented value={top} onChange={setTop} items={['10', '20', '30', '50', '100'].map(x => ({ id: x, label: x }))} /></Field>
77
+ <Field label="简介"><Segmented value={abs} onChange={setAbs} items={[{ id: '-1', label: '完整' }, { id: '120', label: '前 120 字' }, { id: '0', label: '不要' }]} /></Field>
78
+ <Field label="格式"><Segmented value={format} onChange={setFormat} items={[{ id: 'md', label: '文本' }, { id: 'json', label: 'JSON' }]} /></Field>
79
+ <Field label="附上创作任务"><Segmented value={task} onChange={setTask} items={TASKS} /></Field>
80
+ {task && <Field label="你的想法或要求(可不填)"><input className="input" value={idea} onChange={e => setIdea(e.target.value)} placeholder="例如:女主是兽医,想写轻松一点,60 万字。" /></Field>}
81
+ </div>
82
+ </section>
83
+ <section className="sheet">
84
+ <div className="row between"><h2 className="sheet-title serif">预览 · {label}</h2><span className="muted small-note">{feed.data ? `${size.toLocaleString()} 字符` : ''}</span></div>
85
+ {feed.loading && <Loading />}
86
+ {feed.error && <ErrorNote error={feed.error} onRetry={feed.reload} />}
87
+ {feed.data && <pre className="pre rk-insp-pre">{feed.data.text.length > 30000 ? feed.data.text.slice(0, 30000) + '\n\n……(预览只显示前 3 万字,复制和下载是完整的)' : feed.data.text}</pre>}
88
+ </section>
89
  </div>
90
 
91
  <aside className="rk-insp-side">
92
  <section className="sheet">
93
+ <h2 className="sheet-title serif"><Bot size={16} />交给 AI</h2>
94
+ {feed.data && <div className="rk-insp-btns">
95
+ <button className="btn primary block" onClick={async () => { await copyText(feed.data!.text); toast('已复制,粘贴给 AI 即可', 'ok') }}><Copy size={14} />复制全文</button>
96
+ <button className="btn ghost block" onClick={() => saveFile(`番茄热榜-${label}-${feed.data!.date}.${json ? 'json' : 'md'}`, feed.data!.text, json)}><Download size={14} />下载文件</button>
97
+ <button className="btn ghost block" onClick={async () => { await copyText(link); toast('链接已复制,能上网的 AI 打开它就能读到', 'ok') }}><Link2 size={14} />复制给 AI 的链接</button>
98
+ </div>}
99
+ <div className="muted small-note">
100
+ {size > 120000 ? '内容较长,有的 AI 一次读不完,可以减少每个榜的条数、去掉简介,或只选一个分类。' : '大多数 AI 都能一次读完。'}
101
+ </div>
102
+ <div className="muted small-note">链接里带着访问密码,只发给你信任的 AI 工具。链接每次打开都是最新榜单。</div>
 
 
 
 
 
 
103
  </section>
104
  </aside>
105
  </div>
106
  </div>
107
  )
108
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui-src/src/styles.css CHANGED
@@ -1237,3 +1237,5 @@ select.input { appearance: none; padding-right: 28px; background-image: linear-g
1237
  .insp-pick { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: var(--r); }
1238
  .insp-pick label { align-items: center; font-size: 13px; cursor: pointer; }
1239
  .insp-pick select { width: 100%; }
 
 
 
1237
  .insp-pick { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: var(--r); }
1238
  .insp-pick label { align-items: center; font-size: 13px; cursor: pointer; }
1239
  .insp-pick select { width: 100%; }
1240
+ .rk-feed-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px 18px; }
1241
+ .rk-feed-opts .input { width: 100%; }