read.blade.php 24 KB

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