搜索功能增强 + 设置页自动提现 + 部署规则

## 小程序
1. 搜索页面:添加热门章节推荐
2. 我的页面:点击ID可复制
3. 设置页面:添加自动提现开关

## 后台
1. 新增热门章节API (/api/book/hot)
2. 章节保存时自动去掉Markdown标题

## 规则
1. .cursorrules添加完整部署流程
This commit is contained in:
卡若
2026-01-29 12:18:51 +08:00
parent 6a556c2470
commit 0f50fb7c3b
12 changed files with 402 additions and 8 deletions

View File

@@ -130,11 +130,21 @@ export default function ContentPage() {
setIsSaving(true)
try {
// 自动去掉内容中的重复标题(如# 1.2 xxx
// 自动去掉内容中的重复标题(如# 1.2 xxx 或 # 1.4 人性的三角结构...
let content = editingSection.content || ''
// 匹配 # 数字.数字 开头的标题并去掉
const titlePattern = new RegExp(`^#\\s*${editingSection.id}\\s+.*$`, 'm')
content = content.replace(titlePattern, '').trim()
// 匹配多种格式的Markdown标题并去掉
// 1. # 1.2 标题内容
// 2. # 1.2 标题内容(多个空格)
// 3. ## 1.2 标题内容
const titlePatterns = [
new RegExp(`^#+\\s*${editingSection.id.replace('.', '\\.')}\\s+.*$`, 'gm'), // # 1.4 xxx
new RegExp(`^#+\\s*${editingSection.id.replace('.', '\\.')}[:].*$`, 'gm'), // # 1.4xxx
new RegExp(`^#\\s+.*${editingSection.title?.slice(0, 10).replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}.*$`, 'gm') // # xxx标题内容
]
for (const pattern of titlePatterns) {
content = content.replace(pattern, '')
}
content = content.replace(/^\s*\n+/, '').trim() // 去掉开头的空行
const res = await fetch('/api/db/book', {
method: 'PUT',

74
app/api/book/hot/route.ts Normal file
View File

@@ -0,0 +1,74 @@
/**
* 热门章节API
* 返回点击量最高的章节
*/
import { NextResponse } from 'next/server'
import { query } from '@/lib/db'
export async function GET() {
try {
// 从数据库查询点击量高的章节(如果有统计表)
let hotChapters = []
try {
// 尝试从订单表统计购买量高的章节
const rows = await query(`
SELECT
section_id as id,
COUNT(*) as purchase_count
FROM orders
WHERE status = 'completed' AND section_id IS NOT NULL
GROUP BY section_id
ORDER BY purchase_count DESC
LIMIT 10
`) as any[]
if (rows && rows.length > 0) {
// 补充章节信息
const sectionInfo: Record<string, any> = {
'1.1': { title: '荷包:电动车出租的被动收入模式', part: '真实的人', tag: '免费' },
'9.12': { title: '美业整合:一个人的公司如何月入十万', part: '真实的赚钱', tag: '热门' },
'3.1': { title: '3000万流水如何跑出来', part: '真实的行业', tag: '热门' },
'8.1': { title: '流量杠杆:抖音、Soul、飞书', part: '真实的赚钱', tag: '推荐' },
'9.13': { title: 'AI工具推广一个隐藏的高利润赛道', part: '真实的赚钱', tag: '最新' },
'9.14': { title: '大健康私域一个月150万的70后', part: '真实的赚钱', tag: '热门' },
'1.2': { title: '老墨:资源整合高手的社交方法', part: '真实的人', tag: '推荐' },
'2.1': { title: '电商的底层逻辑', part: '真实的行业', tag: '推荐' },
'4.1': { title: '我的第一次创业失败', part: '真实的错误', tag: '热门' },
'5.1': { title: '未来职业的三个方向', part: '真实的社会', tag: '推荐' }
}
hotChapters = rows.map((row: any) => ({
id: row.id,
...(sectionInfo[row.id] || { title: `章节${row.id}`, part: '', tag: '热门' }),
purchaseCount: row.purchase_count
}))
}
} catch (e) {
console.log('[Hot] 数据库查询失败,使用默认数据')
}
// 如果没有数据,返回默认热门章节
if (hotChapters.length === 0) {
hotChapters = [
{ id: '1.1', title: '荷包:电动车出租的被动收入模式', tag: '免费', part: '真实的人' },
{ id: '9.12', title: '美业整合:一个人的公司如何月入十万', tag: '热门', part: '真实的赚钱' },
{ id: '3.1', title: '3000万流水如何跑出来', tag: '热门', part: '真实的行业' },
{ id: '8.1', title: '流量杠杆:抖音、Soul、飞书', tag: '推荐', part: '真实的赚钱' },
{ id: '9.13', title: 'AI工具推广一个隐藏的高利润赛道', tag: '最新', part: '真实的赚钱' }
]
}
return NextResponse.json({
success: true,
chapters: hotChapters
})
} catch (error) {
console.error('[Hot] Error:', error)
return NextResponse.json({
success: false,
chapters: []
})
}
}