read.blade.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. <script src="https://cdn.jsdelivr.net/npm/@tabler/core@1.3.2/dist/js/tabler.min.js"></script>
  10. <style>
  11. body {
  12. font-family: 'Inter', sans-serif;
  13. transition: background-color 0.3s, color 0.3s;
  14. }
  15. .main-container {
  16. display: flex;
  17. gap: 20px;
  18. padding: 20px;
  19. max-width: 1400px;
  20. margin: 0 auto;
  21. }
  22. .toc-sidebar {
  23. width: 250px;
  24. flex-shrink: 0;
  25. display: none;
  26. }
  27. .content-area {
  28. flex-grow: 1;
  29. max-width: 100%;
  30. }
  31. .right-sidebar {
  32. width: 300px;
  33. flex-shrink: 0;
  34. display: none;
  35. }
  36. .related-books { margin-top: 30px; }
  37. .card-img-container { height: 150px; overflow: hidden; }
  38. .card-img-container img { width: 100%; height: 100%; object-fit: cover; }
  39. @media (max-width: 767px) {
  40. .content-area { width: 100%; }
  41. .main-container { padding: 0; }
  42. .card { border: none; }
  43. }
  44. @media (min-width: 768px) {
  45. .toc-sidebar { display: block; }
  46. .content-area { max-width: calc(100% - 270px); }
  47. }
  48. @media (min-width: 992px) {
  49. .right-sidebar { display: block; }
  50. .content-area { max-width: calc(100% - 570px); }
  51. }
  52. .dark-mode { background-color: #1a1a1a; color: #ffffff; }
  53. .dark-mode .card { background-color: #2a2a2a; border-color: #3a3a3a; color: #ffffff; }
  54. .dark-mode .navbar { background-color: #2a2a2a; }
  55. .dark-mode .offcanvas { background-color: #2a2a2a; color: #ffffff; }
  56. .dark-mode .offcanvas .nav-link { color: #ffffff; }
  57. .dark-mode .toc-sidebar, .dark-mode .right-sidebar { background-color: #2a2a2a; }
  58. .toc-sidebar ul, .offcanvas-body ul { list-style: none; padding: 0; }
  59. .toc-sidebar ul li, .offcanvas-body ul li { padding: 5px 0; }
  60. .toc-sidebar ul li a, .offcanvas-body ul li a { color: #206bc4; text-decoration: none; }
  61. .toc-sidebar ul li a:hover, .offcanvas-body ul li a:hover { text-decoration: underline; }
  62. .dark-mode .toc-sidebar ul li a, .dark-mode .offcanvas-body ul li a { color: #4dabf7; }
  63. .toc-level-1 { padding-left: 0 !important; }
  64. .toc-level-2 { padding-left: 10px !important; }
  65. .toc-level-3 { padding-left: 20px !important; }
  66. .toc-level-4 { padding-left: 30px !important; }
  67. .toc-disabled { color: #6c757d; cursor: not-allowed; pointer-events: none; }
  68. .dark-mode .toc-disabled { color: #adb5bd; }
  69. .toc-active {
  70. color: #206bc4 !important;
  71. font-weight: 600;
  72. background: rgba(32, 107, 196, 0.08);
  73. border-left: 3px solid #206bc4;
  74. padding-left: 6px !important;
  75. border-radius: 2px;
  76. cursor: default;
  77. pointer-events: none;
  78. }
  79. .dark-mode .toc-active {
  80. color: #4dabf7 !important;
  81. background: rgba(77, 171, 247, 0.1);
  82. border-left-color: #4dabf7;
  83. }
  84. </style>
  85. </head>
  86. <body class="{{ session('theme', 'light') }}-mode">
  87. <!-- Navbar -->
  88. <header class="navbar navbar-expand-md navbar-light d-print-none">
  89. <div class="container-xl">
  90. <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocDrawer" aria-controls="tocDrawer">
  91. <span class="navbar-toggler-icon"></span>
  92. </button>
  93. {{-- 面包屑:文集标题 > 文章标题 --}}
  94. <div class="navbar-brand d-flex flex-column lh-1">
  95. @if(!empty($book['anthology']))
  96. <small class="text-muted" style="font-size:.75rem;">
  97. <a href="{{ route('library.anthology.show', $book['anthology']['id']) }}" class="text-muted text-decoration-none">
  98. {{ $book['anthology']['title'] }}
  99. </a>
  100. </small>
  101. @endif
  102. <span>{{ $book['title'] }}</span>
  103. </div>
  104. <div class="navbar-nav flex-row order-md-last">
  105. <div class="nav-item">
  106. <a href="#" class="nav-link" id="themeToggle">
  107. <i class="fas fa-moon"></i>
  108. </a>
  109. </div>
  110. @auth
  111. <div class="nav-item dropdown">
  112. <a href="#" class="nav-link d-flex lh-1 text-reset p-0" data-bs-toggle="dropdown">
  113. <span class="avatar avatar-sm" style="background-image: url({{ auth()->user()->avatar ?? '' }})"></span>
  114. </a>
  115. <div class="dropdown-menu dropdown-menu-end">
  116. <a class="dropdown-item" href="#">Profile</a>
  117. <a class="dropdown-item" href="{{ route('logout') }}">Logout</a>
  118. </div>
  119. </div>
  120. @endauth
  121. </div>
  122. </div>
  123. </header>
  124. <!-- TOC Drawer (Mobile) -->
  125. <div class="offcanvas offcanvas-start" tabindex="-1" id="tocDrawer" aria-labelledby="tocDrawerLabel">
  126. <div class="offcanvas-header">
  127. <h5 class="offcanvas-title" id="tocDrawerLabel">目录</h5>
  128. <button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
  129. </div>
  130. <div class="offcanvas-body">
  131. @if(isset($book['toc']) && count($book['toc']) > 0)
  132. <ul>
  133. @foreach ($book['toc'] as $item)
  134. <li class="toc-level-{{ $item['level'] }} {{ $item['active'] ?? false ? 'toc-active' : ($item['disabled'] ? 'toc-disabled' : '') }}">
  135. @if($item['active'] ?? false)
  136. <span>{{ $item['title'] }}</span>
  137. @elseif(!$item['disabled'])
  138. {{-- ✅ 修改1:使用文集阅读路由,传 anthology + article 两个参数 --}}
  139. <a href="{{ route('library.anthology.read', ['anthology' => $anthologyId, 'article' => $item['id']]) }}">
  140. {{ $item['title'] }}
  141. </a>
  142. @else
  143. <span>{{ $item['title'] }}</span>
  144. @endif
  145. </li>
  146. @endforeach
  147. </ul>
  148. @else
  149. <div class="alert alert-warning">此书没有目录</div>
  150. @endif
  151. </div>
  152. </div>
  153. <!-- Main Content Area -->
  154. <div class="main-container">
  155. <!-- TOC Sidebar (Tablet+) -->
  156. <div class="toc-sidebar card">
  157. <div class="card-body">
  158. <h5>目录</h5>
  159. @if(isset($book['toc']) && count($book['toc']) > 0)
  160. <ul>
  161. @foreach ($book['toc'] as $item)
  162. <li class="toc-level-{{ $item['level'] }} {{ $item['active'] ?? false ? 'toc-active' : ($item['disabled'] ? 'toc-disabled' : '') }}">
  163. @if($item['active'] ?? false)
  164. <span>{{ $item['title'] }}</span>
  165. @elseif(!$item['disabled'])
  166. {{-- ✅ 修改1:同上 --}}
  167. <a href="{{ route('library.anthology.read', ['anthology' => $anthologyId, 'article' => $item['id']]) }}">
  168. {{ $item['title'] }}
  169. </a>
  170. @else
  171. <span>{{ $item['title'] }}</span>
  172. @endif
  173. </li>
  174. @endforeach
  175. </ul>
  176. @else
  177. <div class="alert alert-warning">此书没有目录</div>
  178. @endif
  179. </div>
  180. </div>
  181. <!-- Main Content -->
  182. <div class="content-area card">
  183. <div class="card-body">
  184. <div>
  185. <h2>{{ $book['title'] }}</h2>
  186. <p>
  187. <strong>Author:</strong>
  188. <span>
  189. {{ $book['author'] }}
  190. @if(isset($book['publisher']))
  191. @
  192. <a href="{{ route('blog.index', ['user' => $book['publisher']->username]) }}">
  193. {{ $book['publisher']->nickname }}
  194. </a>
  195. @endif
  196. </span>
  197. </p>
  198. <div class="content">
  199. @if(isset($book['content']) && count($book['content']) > 0)
  200. @foreach ($book['content'] as $paragraph)
  201. <div id="para-{{ $paragraph['id'] }}">
  202. @foreach ($paragraph['text'] as $rows)
  203. <div style="display:flex;">
  204. @foreach ($rows as $col)
  205. <div style="flex:1;">
  206. @if($paragraph['level'] < 8)
  207. {{-- ✅ 修改3:{!! !!} 不转义,渲染 HTML 内容 --}}
  208. <h{{ $paragraph['level'] }}>{!! $col !!}</h{{ $paragraph['level'] }}>
  209. @else
  210. <p>{!! $col !!}</p>
  211. @endif
  212. </div>
  213. @endforeach
  214. </div>
  215. @endforeach
  216. </div>
  217. @endforeach
  218. @else
  219. <div>没有内容</div>
  220. @endif
  221. </div>
  222. </div>
  223. <!-- Nav buttons -->
  224. <div class="mt-6 pt-6">
  225. <ul class="pagination">
  226. @if(!empty($book['pagination']['prev']))
  227. <li class="page-item page-prev">
  228. {{-- ✅ 修改2:翻页也用文集路由 --}}
  229. <a class="page-link" href="{{ route('library.anthology.read', ['anthology' => $anthologyId, 'article' => $book['pagination']['prev']['id']]) }}">
  230. <div class="row align-items-center">
  231. <div class="col-auto">
  232. <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">
  233. <path d="M15 6l-6 6l6 6"></path>
  234. </svg>
  235. </div>
  236. <div class="col">
  237. <div class="page-item-subtitle">上一篇</div>
  238. <div class="page-item-title">{{ $book['pagination']['prev']['title'] }}</div>
  239. </div>
  240. </div>
  241. </a>
  242. </li>
  243. @endif
  244. @if(!empty($book['pagination']['next']))
  245. <li class="page-item page-next">
  246. <a class="page-link" href="{{ route('library.anthology.read', ['anthology' => $anthologyId, 'article' => $book['pagination']['next']['id']]) }}">
  247. <div class="row align-items-center">
  248. <div class="col">
  249. <div class="page-item-subtitle">下一篇</div>
  250. <div class="page-item-title">{{ $book['pagination']['next']['title'] }}</div>
  251. </div>
  252. <div class="col-auto">
  253. <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">
  254. <path d="M9 6l6 6l-6 6"></path>
  255. </svg>
  256. </div>
  257. </div>
  258. </a>
  259. </li>
  260. @endif
  261. </ul>
  262. </div>
  263. <!-- Related Books -->
  264. @if(!empty($relatedBooks))
  265. <div class="related-books">
  266. <h3>Related Books</h3>
  267. <div class="row row-cards">
  268. @foreach ($relatedBooks as $relatedBook)
  269. <div class="col-md-4">
  270. <div class="card">
  271. <div class="card-img-container">
  272. <img src="{{ $relatedBook['image'] }}" alt="{{ $relatedBook['title'] }}">
  273. </div>
  274. <div class="card-body">
  275. <h5 class="card-title">{{ $relatedBook['title'] }}</h5>
  276. <p class="card-text">{{ $relatedBook['description'] }}</p>
  277. <a href="{{ $relatedBook['link'] }}" class="btn btn-primary">Read Now</a>
  278. </div>
  279. </div>
  280. </div>
  281. @endforeach
  282. </div>
  283. </div>
  284. @endif
  285. </div>
  286. </div>
  287. <!-- Right Sidebar (Desktop) -->
  288. <div class="right-sidebar card">
  289. <div class="card-body">
  290. @if(!empty($book['downloads']))
  291. <h5>下载</h5>
  292. <ul class="list-unstyled">
  293. @foreach ($book['downloads'] as $download)
  294. <li><a href="{{ $download['url'] }}" class="btn btn-outline-primary mb-2 w-100"><i class="fas fa-download me-2"></i>{{ $download['format'] }}</a></li>
  295. @endforeach
  296. </ul>
  297. @endif
  298. @if(!empty($book['categories']))
  299. <h5>分类</h5>
  300. @foreach ($book['categories'] as $category)
  301. <span class="badge bg-blue text-blue-fg">{{ $category['name'] }}</span>
  302. @endforeach
  303. @endif
  304. @if(!empty($book['tags']))
  305. <h5>标签</h5>
  306. @foreach ($book['tags'] as $tag)
  307. <span class="badge me-1">{{ $tag['name'] }}</span>
  308. @endforeach
  309. @endif
  310. </div>
  311. </div>
  312. </div>
  313. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
  314. <script>
  315. const themeToggle = document.getElementById('themeToggle');
  316. themeToggle.addEventListener('click', (e) => {
  317. e.preventDefault();
  318. const isDark = document.body.classList.contains('dark-mode');
  319. document.body.classList.toggle('dark-mode', !isDark);
  320. document.body.classList.toggle('light-mode', isDark);
  321. fetch('{{ route("theme.toggle") }}', {
  322. method: 'POST',
  323. headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}', 'Content-Type': 'application/json' },
  324. body: JSON.stringify({ theme: isDark ? 'light' : 'dark' })
  325. });
  326. themeToggle.innerHTML = isDark ? '<i class="fas fa-moon"></i>' : '<i class="fas fa-sun"></i>';
  327. });
  328. </script>
  329. </body>
  330. </html>