read.blade.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. <!DOCTYPE html>
  2. <html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>{{ $book['title'] }}</title>
  7. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tabler/core@1.3.2/dist/css/tabler.min.css" />
  8. <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
  9. @vite(['resources/css/reader.css', 'resources/js/app.js'])
  10. <script src="https://cdn.jsdelivr.net/npm/@tabler/core@1.3.2/dist/js/tabler.min.js"></script>
  11. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
  12. </head>
  13. <body class="{{ session('theme', 'light') }}-mode">
  14. <x-term-drawer />
  15. <!-- Navbar -->
  16. <header class="navbar navbar-expand-md navbar-light d-print-none">
  17. <div class="container-xl">
  18. <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocDrawer" aria-controls="tocDrawer">
  19. <span class="navbar-toggler-icon"></span>
  20. </button>
  21. {{-- 面包屑:文集标题 > 文章标题 --}}
  22. <div class="navbar-brand d-flex flex-column lh-1">
  23. @if(!empty($book['anthology']))
  24. <small class="text-muted" style="font-size:.75rem;">
  25. <a href="{{ route('library.anthology.show', $book['anthology']['id']) }}" class="text-muted text-decoration-none">
  26. {{ $book['anthology']['title'] }}
  27. </a>
  28. </small>
  29. @endif
  30. </div>
  31. <div class="navbar-nav flex-row order-md-last align-items-center">
  32. {{-- Desktop 编辑器按钮 --}}
  33. @if(!empty($editor_link))
  34. <div class="nav-item d-none d-md-block me-2">
  35. <a href="{{ $editor_link }}"
  36. target="_blank"
  37. class="nav-link">
  38. <i class="fas fa-pen-to-square me-1"></i>
  39. 编辑器
  40. </a>
  41. </div>
  42. {{-- Mobile 编辑器按钮 --}}
  43. <div class="nav-item d-md-none me-2">
  44. <a href="{{ $editor_link }}"
  45. target="_blank"
  46. class="nav-link">
  47. <i class="fas fa-pen-to-square"></i>
  48. </a>
  49. </div>
  50. @endif
  51. {{-- Desktop 设置按钮 --}}
  52. <div class="nav-item d-none d-md-block me-2">
  53. <a href="#"
  54. class="nav-link"
  55. data-bs-toggle="modal"
  56. data-bs-target="#settingsModal">
  57. <i class="fas fa-cog me-1"></i>
  58. 设置
  59. </a>
  60. </div>
  61. {{-- Mobile 设置按钮 --}}
  62. <div class="nav-item d-md-none me-2">
  63. <a href="#"
  64. class="nav-link"
  65. data-bs-toggle="modal"
  66. data-bs-target="#settingsModal">
  67. <i class="fas fa-cog"></i>
  68. </a>
  69. </div>
  70. {{-- Desktop Dropdown --}}
  71. @if(!empty($channels))
  72. <div class="nav-item dropdown d-none d-md-block me-2">
  73. <a href="#" class="nav-link" data-bs-toggle="dropdown">
  74. <i class="fas fa-layer-group me-1"></i>
  75. 版本
  76. </a>
  77. <div class="dropdown-menu dropdown-menu-end">
  78. @foreach($channels as $channel)
  79. <a class="dropdown-item"
  80. href="{{ request()->fullUrlWithQuery(['channel' => $channel['id']]) }}">
  81. {{ $channel['name'] }}
  82. <small class="text-muted">
  83. ({{ __('language.' . $channel['lang']) }})
  84. </small>
  85. </a>
  86. @endforeach
  87. </div>
  88. </div>
  89. {{-- Mobile Drawer Trigger --}}
  90. <div class="nav-item d-md-none me-2">
  91. <a href="#" class="nav-link"
  92. data-bs-toggle="offcanvas"
  93. data-bs-target="#channelDrawer">
  94. <i class="fas fa-layer-group"></i>
  95. </a>
  96. </div>
  97. @endif
  98. <div class="nav-item">
  99. <a href="#" class="nav-link" id="themeToggle">
  100. <i class="fas fa-moon"></i>
  101. </a>
  102. </div>
  103. @auth
  104. <div class="nav-item dropdown">
  105. <a href="#" class="nav-link d-flex lh-1 text-reset p-0" data-bs-toggle="dropdown">
  106. <span class="avatar avatar-sm" style="background-image: url({{ auth()->user()->avatar ?? '' }})"></span>
  107. </a>
  108. <div class="dropdown-menu dropdown-menu-end">
  109. <a class="dropdown-item" href="#">Profile</a>
  110. <a class="dropdown-item" href="{{ route('logout') }}">Logout</a>
  111. </div>
  112. </div>
  113. @endauth
  114. </div>
  115. </div>
  116. </header>
  117. <!-- TOC Drawer (Mobile) -->
  118. @if(!empty($channels))
  119. <div class="offcanvas offcanvas-end"
  120. tabindex="-1"
  121. id="channelDrawer">
  122. <div class="offcanvas-header">
  123. <h5 class="offcanvas-title">选择版本</h5>
  124. <button type="button"
  125. class="btn-close"
  126. data-bs-dismiss="offcanvas">
  127. </button>
  128. </div>
  129. <div class="offcanvas-body">
  130. <div class="list-group list-group-flush">
  131. @foreach($channels as $channel)
  132. <a
  133. href="{{ request()->fullUrlWithQuery(['channel' => $channel['id']]) }}"
  134. class="list-group-item list-group-item-action">
  135. <div class="fw-bold">
  136. {{ $channel['name'] }}
  137. </div>
  138. <small class="text-muted">
  139. {{ __('language.' . $channel['lang']) }}
  140. </small>
  141. </a>
  142. @endforeach
  143. </div>
  144. </div>
  145. </div>
  146. @endif
  147. <div class="offcanvas offcanvas-start" tabindex="-1" id="tocDrawer" aria-labelledby="tocDrawerLabel">
  148. <div class="offcanvas-header">
  149. <h5 class="offcanvas-title" id="tocDrawerLabel">目录</h5>
  150. <button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
  151. </div>
  152. <div class="offcanvas-body">
  153. @if(isset($book['toc']) && count($book['toc']) > 0)
  154. <ul>
  155. @foreach ($book['toc'] as $item)
  156. <li class="toc_item toc-level-{{ $item['level'] }} {{ $item['active'] ?? false ? 'toc-active' : ($item['disabled'] ? 'toc-disabled' : '') }}">
  157. @if($item['active'] ?? false)
  158. <span title="{{ $item['title'] }}">
  159. {{ $item['title'] }}
  160. </span>
  161. @elseif(!$item['disabled'])
  162. @if(isset($anthologyId))
  163. {{-- ✅ 修改1:使用文集阅读路由,传 anthology + article 两个参数 --}}
  164. <a href="{{ route('library.anthology.read', ['anthology' => $anthologyId, 'article' => $item['id'],'channel' => request('channel')]) }}" title="{{ $item['title'] }}">
  165. @else
  166. <a href="{{ route('library.tipitaka.read', ['id' => $item['id'] ,'channel' => request('channel')]) }}" title="{{ $item['title'] }}">
  167. @endif
  168. {{ $item['title'] }}
  169. </a>
  170. @else
  171. <span title="{{ $item['title'] }}">
  172. {{ $item['title'] }}
  173. </span>
  174. @endif
  175. </li>
  176. @endforeach
  177. </ul>
  178. @else
  179. <div class="alert alert-warning">此书没有目录</div>
  180. @endif
  181. </div>
  182. </div>
  183. <!-- Main Content Area -->
  184. <div class="main-container">
  185. <!-- TOC Sidebar (Tablet+) -->
  186. <div class="toc-sidebar card">
  187. <div class="card-body">
  188. <h5>目录</h5>
  189. @if(isset($book['toc']) && count($book['toc']) > 0)
  190. <ul>
  191. @foreach ($book['toc'] as $item)
  192. <li class="toc_item toc-level-{{ $item['level'] }} {{ $item['active'] ?? false ? 'toc-active' : ($item['disabled'] ? 'toc-disabled' : '') }}">
  193. @if($item['active'] ?? false)
  194. <span>{{ $item['title'] }}</span>
  195. @elseif(!$item['disabled'])
  196. {{-- --}}
  197. @if(isset($anthologyId))
  198. <a href="{{ route('library.anthology.read', ['anthology' => $anthologyId, 'article' => $item['id'],'channel' => request('channel')]) }}">
  199. @else
  200. <a href="{{ route('library.tipitaka.read', ['id' => $item['id'],'channel' => request('channel')]) }}">
  201. @endif
  202. {{ $item['title'] }}
  203. </a>
  204. @else
  205. <span>{{ $item['title'] }}</span>
  206. @endif
  207. </li>
  208. @endforeach
  209. </ul>
  210. @else
  211. <div class="alert alert-warning">此书没有目录</div>
  212. @endif
  213. </div>
  214. </div>
  215. <!-- Main Content -->
  216. <div class="content-area card">
  217. <div class="card-body">
  218. <div>
  219. <h2>{{ $book['title'] }}</h2>
  220. <p>
  221. <strong>Author:</strong>
  222. <span>
  223. {{ $book['author'] }}
  224. @if(isset($book['publisher']))
  225. @
  226. <a href="{{ route('blog.index', ['user' => $book['publisher']->username]) }}">
  227. {{ $book['publisher']->nickname }}
  228. </a>
  229. @endif
  230. </span>
  231. </p>
  232. <div class="content">
  233. @if(isset($book['content']) && count($book['content']) > 0)
  234. @foreach ($book['content'] as $paragraph)
  235. <div id="para-{{ $paragraph['id'] }}">
  236. @foreach ($paragraph['text'] as $rows)
  237. <div style="display:flex;">
  238. @foreach ($rows as $col)
  239. <div style="flex:1;">
  240. @if($paragraph['level'] < 8)
  241. {{-- ✅ 修改3:{!! !!} 不转义,渲染 HTML 内容 --}}
  242. <h{{ $paragraph['level'] }}>{!! $col !!}</h{{ $paragraph['level'] }}>
  243. @else
  244. <p>{!! $col !!}</p>
  245. @endif
  246. </div>
  247. @endforeach
  248. </div>
  249. @endforeach
  250. </div>
  251. @endforeach
  252. @else
  253. <div>没有内容</div>
  254. @endif
  255. </div>
  256. </div>
  257. <!-- Nav buttons -->
  258. <div class="mt-6 pt-6">
  259. <ul class="pagination">
  260. @if(!empty($book['pagination']['prev']))
  261. <li class="page-item page-prev">
  262. {{-- ✅ 修改2:翻页也用文集路由 --}}
  263. @if(isset($anthologyId))
  264. <a class="page-link"
  265. href="{{ route('library.anthology.read', [
  266. 'anthology' => $anthologyId,
  267. 'article' => $book['pagination']['prev']['id'],
  268. 'channel' => request('channel')
  269. ]) }}">
  270. @else
  271. <a class="page-link" href="{{ route('library.tipitaka.read', [
  272. 'id' => $book['pagination']['prev']['id'],
  273. 'channel' => request('channel')
  274. ]) }}">
  275. @endif
  276. <div class="row align-items-center">
  277. <div class="col-auto">
  278. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-1">
  279. <path d="M15 6l-6 6l6 6"></path>
  280. </svg>
  281. </div>
  282. <div class="col">
  283. <div class="page-item-subtitle">上一篇</div>
  284. <div class="page-item-title">{{ $book['pagination']['prev']['title'] }}</div>
  285. </div>
  286. </div>
  287. </a>
  288. </li>
  289. @endif
  290. @if(!empty($book['pagination']['next']))
  291. <li class="page-item page-next">
  292. @if(isset($anthologyId))
  293. <a class="page-link" href="{{ route('library.anthology.read', ['anthology' => $anthologyId, 'article' => $book['pagination']['next']['id'],'channel' => request('channel')]) }}">
  294. @else
  295. <a class="page-link" href="{{ route('library.tipitaka.read', ['id' => $book['pagination']['next']['id'],'channel' => request('channel')]) }}">
  296. @endif
  297. <div class="row align-items-center">
  298. <div class="col">
  299. <div class="page-item-subtitle">下一篇</div>
  300. <div class="page-item-title">{{ $book['pagination']['next']['title'] }}</div>
  301. </div>
  302. <div class="col-auto">
  303. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-1">
  304. <path d="M9 6l6 6l-6 6"></path>
  305. </svg>
  306. </div>
  307. </div>
  308. </a>
  309. </li>
  310. @endif
  311. </ul>
  312. </div>
  313. <!-- Related Books -->
  314. @if(!empty($relatedBooks))
  315. <div class="related-books">
  316. <h3>Related Books</h3>
  317. <div class="row row-cards">
  318. @foreach ($relatedBooks as $relatedBook)
  319. <div class="col-md-4">
  320. <div class="card">
  321. <div class="card-img-container">
  322. <img src="{{ $relatedBook['image'] }}" alt="{{ $relatedBook['title'] }}">
  323. </div>
  324. <div class="card-body">
  325. <h5 class="card-title">{{ $relatedBook['title'] }}</h5>
  326. <p class="card-text">{{ $relatedBook['description'] }}</p>
  327. <a href="{{ $relatedBook['link'] }}" class="btn btn-primary">Read Now</a>
  328. </div>
  329. </div>
  330. </div>
  331. @endforeach
  332. </div>
  333. </div>
  334. @endif
  335. </div>
  336. </div>
  337. <!-- Right Sidebar (Desktop) -->
  338. <div class="right-sidebar card">
  339. <div class="card-body">
  340. @if(!empty($book['downloads']))
  341. <h5>下载</h5>
  342. <ul class="list-unstyled">
  343. @foreach ($book['downloads'] as $download)
  344. <li>
  345. <a href="{{ $download['url'] }}" class="btn btn-outline-primary mb-2 w-100">
  346. <i class="fas fa-download me-2"></i>{{ $download['format'] }}
  347. </a>
  348. </li>
  349. @endforeach
  350. </ul>
  351. @endif
  352. @if(!empty($book['categories']))
  353. <h5>分类</h5>
  354. @foreach ($book['categories'] as $category)
  355. <span class="badge bg-blue text-blue-fg">{{ $category['name'] }}</span>
  356. @endforeach
  357. @endif
  358. @if(!empty($book['tags']))
  359. <h5>标签</h5>
  360. @foreach ($book['tags'] as $tag)
  361. <span class="badge me-1">{{ $tag['name'] }}</span>
  362. @endforeach
  363. @endif
  364. </div>
  365. </div>
  366. </div>
  367. <!-- Settings Modal -->
  368. <div class="modal modal-blur fade" id="settingsModal" tabindex="-1">
  369. <div class="modal-dialog">
  370. <form id="settingsForm" class="modal-content">
  371. <div class="modal-header">
  372. <h5 class="modal-title">阅读设置</h5>
  373. <button type="button"
  374. class="btn-close"
  375. data-bs-dismiss="modal"></button>
  376. </div>
  377. <div class="modal-body">
  378. {{-- 显示原文 --}}
  379. <div class="mb-4">
  380. <label class="form-label">显示原文</label>
  381. <label class="form-check form-switch">
  382. <input class="form-check-input"
  383. type="checkbox"
  384. id="showOrigin">
  385. <span class="form-check-label">
  386. 开启/关闭原文显示
  387. </span>
  388. </label>
  389. </div>
  390. {{-- 界面语言 --}}
  391. <div class="mb-4">
  392. <label class="form-label">界面语言</label>
  393. <select class="form-select" id="uiLanguage">
  394. <option value="auto">自动</option>
  395. <option value="zh">简体中文</option>
  396. <option value="en">英文</option>
  397. </select>
  398. </div>
  399. {{-- 巴利文脚本 --}}
  400. <div class="mb-4">
  401. <label class="form-label">巴利文脚本</label>
  402. <select class="form-select" id="paliScript">
  403. <option value="auto">自动</option>
  404. <option value="roman">罗马</option>
  405. <option value="myanmar">缅文</option>
  406. <option value="thai">泰文</option>
  407. </select>
  408. </div>
  409. </div>
  410. <div class="modal-footer">
  411. <button type="button"
  412. class="btn btn-link"
  413. data-bs-dismiss="modal">
  414. 取消
  415. </button>
  416. <button type="submit"
  417. class="btn btn-primary">
  418. 确定
  419. </button>
  420. </div>
  421. </form>
  422. </div>
  423. </div>
  424. <script>
  425. function toggleOriginDisplay(show) {
  426. document.querySelectorAll('.origin').forEach(el => {
  427. el.style.display = show ? 'unset' : 'none';
  428. });
  429. }
  430. function setCookie(name, value, days = 365) {
  431. let expires = "";
  432. const date = new Date();
  433. date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
  434. expires = "; expires=" + date.toUTCString();
  435. document.cookie =
  436. name + "=" + encodeURIComponent(value) +
  437. expires +
  438. "; path=/";
  439. }
  440. function getCookie(name) {
  441. const value = `; ${document.cookie}`;
  442. const parts = value.split(`; ${name}=`);
  443. if (parts.length === 2)
  444. return decodeURIComponent(parts.pop().split(';').shift());
  445. return null;
  446. }
  447. // 初始化加载 cookie
  448. document.addEventListener('DOMContentLoaded', function() {
  449. const showOrigin =
  450. getCookie('show_origin') === 'true';
  451. document.getElementById('showOrigin').checked =
  452. showOrigin;
  453. document.getElementById('uiLanguage').value =
  454. getCookie('ui_language') || 'auto';
  455. document.getElementById('paliScript').value =
  456. getCookie('pali_script') || 'auto';
  457. // 应用原文显示设置
  458. toggleOriginDisplay(showOrigin);
  459. });
  460. // 提交保存
  461. document.getElementById('settingsForm')
  462. .addEventListener('submit', function(e) {
  463. e.preventDefault();
  464. setCookie(
  465. 'show_origin',
  466. document.getElementById('showOrigin').checked
  467. );
  468. setCookie(
  469. 'ui_language',
  470. document.getElementById('uiLanguage').value
  471. );
  472. setCookie(
  473. 'pali_script',
  474. document.getElementById('paliScript').value
  475. );
  476. toggleOriginDisplay(showOrigin);
  477. location.reload();
  478. });
  479. </script>
  480. <script>
  481. const themeToggle = document.getElementById('themeToggle');
  482. themeToggle.addEventListener('click', (e) => {
  483. e.preventDefault();
  484. const isDark = document.body.classList.contains('dark-mode');
  485. document.body.classList.toggle('dark-mode', !isDark);
  486. document.body.classList.toggle('light-mode', isDark);
  487. fetch('{{ route("theme.toggle") }}', {
  488. method: 'POST',
  489. headers: {
  490. 'X-CSRF-TOKEN': '{{ csrf_token() }}',
  491. 'Content-Type': 'application/json'
  492. },
  493. body: JSON.stringify({
  494. theme: isDark ? 'light' : 'dark'
  495. })
  496. });
  497. themeToggle.innerHTML = isDark ? '<i class="fas fa-moon"></i>' : '<i class="fas fa-sun"></i>';
  498. });
  499. </script>
  500. </body>
  501. </html>