├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * 清洗小说内容,移除原始网站信息
  3. * @param {string} content - 原始内容
  4. * @returns {string} 清洗后的内容
  5. */
  6. export function cleanNovelContent(content) {
  7. if (!content) return ''
  8. // 移除特定网站信息
  9. const cleanContent = content
  10. .replace(/最新网址[::]?\s*[a-z0-9.-]+/gi, '')
  11. .replace(/www\.[a-z0-9]+\.[a-z]{2,}/gi, '')
  12. .replace(/请收藏本站:https:\/\/www\.\w+\.\w+/g, '')
  13. .replace(/ | /g, ' ') // 替换空格实体
  14. .replace(/<br\s*\/?>/g, '\n') // 替换换行标签
  15. .replace(/<[^>]+>/g, '') // 移除所有HTML标签
  16. // 移除多余空行
  17. return cleanContent
  18. .split('\n')
  19. .map(line => line.trim())
  20. .filter(line => line.length > 0)
  21. .join('\n\n')
  22. }
  23. /**
  24. * 分页处理小说内容
  25. * @param {string} content - 清洗后的内容
  26. * @param {number} pageSize - 每页字符数
  27. * @returns {string[]} 分页后的内容数组
  28. */
  29. export function paginateContent(content, pageSize = 800) {
  30. const pages = []
  31. let currentPage = ''
  32. let currentLength = 0
  33. const paragraphs = content.split('\n\n')
  34. for (const paragraph of paragraphs) {
  35. // 如果当前页加上新段落不会超长
  36. if (currentLength + paragraph.length <= pageSize) {
  37. currentPage += (currentPage ? '\n\n' : '') + paragraph
  38. currentLength += paragraph.length
  39. }
  40. // 如果段落本身超过一页
  41. else if (paragraph.length > pageSize) {
  42. // 先保存当前页
  43. if (currentPage) {
  44. pages.push(currentPage)
  45. currentPage = ''
  46. currentLength = 0
  47. }
  48. // 将长段落分割成多页
  49. let start = 0
  50. while (start < paragraph.length) {
  51. const end = start + pageSize
  52. let pageContent = paragraph.substring(start, end)
  53. // 尽量在句号处分页
  54. const lastPunctuation = Math.max(
  55. pageContent.lastIndexOf('。'),
  56. pageContent.lastIndexOf('!'),
  57. pageContent.lastIndexOf('?'),
  58. pageContent.lastIndexOf('.'),
  59. pageContent.lastIndexOf('!'),
  60. pageContent.lastIndexOf('?')
  61. )
  62. if (lastPunctuation > -1 && lastPunctuation > start + pageSize * 0.8) {
  63. pageContent = pageContent.substring(0, lastPunctuation + 1)
  64. start = start + lastPunctuation + 1
  65. } else {
  66. start = end
  67. }
  68. pages.push(pageContent)
  69. }
  70. }
  71. // 如果段落会导致当前页超长
  72. else {
  73. pages.push(currentPage)
  74. currentPage = paragraph
  75. currentLength = paragraph.length
  76. }
  77. }
  78. if (currentPage) {
  79. pages.push(currentPage)
  80. }
  81. return pages
  82. }