read.blade.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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 Reading - {{ $book['title'] }}</title>
  7. <!-- Tabler CSS -->
  8. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tabler/core@1.3.2/dist/css/tabler.min.css" />
  9. <!-- FontAwesome for icons -->
  10. <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
  11. <script
  12. src="https://cdn.jsdelivr.net/npm/@tabler/core@1.3.2/dist/js/tabler.min.js">
  13. </script>
  14. <style>
  15. /* Custom styles for responsive layout */
  16. body {
  17. font-family: 'Inter', sans-serif;
  18. transition: background-color 0.3s, color 0.3s;
  19. }
  20. .main-container {
  21. display: flex;
  22. gap: 20px;
  23. padding: 20px;
  24. max-width: 1400px;
  25. margin: 0 auto;
  26. }
  27. .toc-sidebar {
  28. width: 250px;
  29. flex-shrink: 0;
  30. display: none;
  31. }
  32. .content-area {
  33. flex-grow: 1;
  34. max-width: 100%;
  35. }
  36. .right-sidebar {
  37. width: 300px;
  38. flex-shrink: 0;
  39. display: none;
  40. }
  41. .related-books {
  42. margin-top: 30px;
  43. }
  44. .card-img-container {
  45. height: 150px;
  46. overflow: hidden;
  47. }
  48. .card-img-container img {
  49. width: 100%;
  50. height: 100%;
  51. object-fit: cover;
  52. }
  53. /* Mobile: Show only content, TOC in drawer */
  54. @media (max-width: 767px) {
  55. .content-area {
  56. width: 100%;
  57. }
  58. }
  59. /* Tablet: Show TOC and content */
  60. @media (min-width: 768px) {
  61. .toc-sidebar {
  62. display: block;
  63. }
  64. .content-area {
  65. max-width: calc(100% - 270px);
  66. }
  67. }
  68. /* Desktop: Show TOC, content, and right sidebar */
  69. @media (min-width: 992px) {
  70. .right-sidebar {
  71. display: block;
  72. }
  73. .content-area {
  74. max-width: calc(100% - 570px);
  75. }
  76. }
  77. /* Dark mode styles */
  78. .dark-mode {
  79. background-color: #1a1a1a;
  80. color: #ffffff;
  81. }
  82. .dark-mode .card {
  83. background-color: #2a2a2a;
  84. border-color: #3a3a3a;
  85. color: #ffffff;
  86. }
  87. .dark-mode .navbar {
  88. background-color: #2a2a2a;
  89. }
  90. .dark-mode .offcanvas {
  91. background-color: #2a2a2a;
  92. color: #ffffff;
  93. }
  94. .dark-mode .offcanvas .nav-link {
  95. color: #ffffff;
  96. }
  97. .dark-mode .toc-sidebar,
  98. .dark-mode .right-sidebar {
  99. background-color: #2a2a2a;
  100. }
  101. .toc-sidebar ul {
  102. list-style: none;
  103. padding: 0;
  104. }
  105. .toc-sidebar ul li {
  106. padding: 10px 0;
  107. }
  108. .toc-sidebar ul li a {
  109. color: #206bc4;
  110. text-decoration: none;
  111. }
  112. .toc-sidebar ul li a:hover {
  113. text-decoration: underline;
  114. }
  115. .dark-mode .toc-sidebar ul li a {
  116. color: #4dabf7;
  117. }
  118. /* Multi-level TOC styles */
  119. .toc-sidebar ul,
  120. .offcanvas-body ul {
  121. list-style: none;
  122. padding: 0;
  123. }
  124. .toc-sidebar ul li,
  125. .offcanvas-body ul li {
  126. padding: 5px 0;
  127. }
  128. .toc-sidebar ul li a,
  129. .offcanvas-body ul li a {
  130. color: #206bc4;
  131. text-decoration: none;
  132. }
  133. .toc-sidebar ul li a:hover,
  134. .offcanvas-body ul li a:hover {
  135. text-decoration: underline;
  136. }
  137. .dark-mode .toc-sidebar ul li a,
  138. .dark-mode .offcanvas-body ul li a {
  139. color: #4dabf7;
  140. }
  141. /* Indentation for TOC levels */
  142. .toc-level-1 {
  143. padding-left: 0 !important;
  144. }
  145. .toc-level-2 {
  146. padding-left: 10px !important;
  147. }
  148. .toc-level-3 {
  149. padding-left: 20px !important;
  150. }
  151. .toc-level-4 {
  152. padding-left: 30px !important;
  153. }
  154. /* Disabled TOC item styles */
  155. .toc-disabled {
  156. color: #6c757d;
  157. cursor: not-allowed;
  158. pointer-events: none;
  159. }
  160. .dark-mode .toc-disabled {
  161. color: #adb5bd;
  162. }
  163. </style>
  164. </head>
  165. <body class="{{ session('theme', 'light') }}-mode">
  166. <!-- Navbar -->
  167. <header class="navbar navbar-expand-md navbar-light d-print-none">
  168. <div class="container-xl">
  169. <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocDrawer" aria-controls="tocDrawer">
  170. <span class="navbar-toggler-icon"></span>
  171. </button>
  172. <h1 class="navbar-brand">{{ $book['title'] }}</h1>
  173. <div class="navbar-nav flex-row order-md-last">
  174. <!-- Theme Toggle -->
  175. <div class="nav-item">
  176. <a href="#" class="nav-link" id="themeToggle">
  177. <i class="fas fa-moon"></i>
  178. </a>
  179. </div>
  180. <!-- User Settings -->
  181. <div class="nav-item dropdown">
  182. <a href="#" class="nav-link d-flex lh-1 text-reset p-0" data-bs-toggle="dropdown" aria-label="Open user menu">
  183. <span class="avatar avatar-sm" style="background-image: url({{ auth()->user()->avatar ?? 'https://via.placeholder.com/40' }})">use</span>
  184. </a>
  185. <div class="dropdown-menu dropdown-menu-end">
  186. <a class="dropdown-item" href="#">Profile</a>
  187. <a class="dropdown-item" href="#">Settings</a>
  188. <a class="dropdown-item" href="{{ route('logout') }}">Logout</a>
  189. </div>
  190. </div>
  191. </div>
  192. </div>
  193. </header>
  194. <!-- TOC Drawer for Mobile -->
  195. <div class="offcanvas offcanvas-start" tabindex="-1" id="tocDrawer" aria-labelledby="tocDrawerLabel">
  196. <div class="offcanvas-header">
  197. <h5 class="offcanvas-title" id="tocDrawerLabel">Table of Contents</h5>
  198. <button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
  199. </div>
  200. <div class="offcanvas-body">
  201. @if(isset($book['toc']) && is_array($book['toc']) && count($book['toc']) > 0)
  202. <ul>
  203. @foreach ($book['toc'] as $index => $item)
  204. <li class="toc-level-{{ $item['level'] }} {{ $item['disabled'] ? 'toc-disabled' : '' }}">
  205. @if (!$item['disabled'])
  206. <a href="#section-{{ $index }}">{{ $item['title'] }}</a>
  207. @else
  208. <span>{{ $item['title'] }}</span>
  209. @endif
  210. </li>
  211. @endforeach
  212. </ul>
  213. @else
  214. <div class="alert alert-warning">
  215. 此书没有目录
  216. </div>
  217. @endif
  218. </div>
  219. </div>
  220. <!-- Main Content Area -->
  221. <div class="main-container">
  222. <!-- Table of Contents Sidebar (Tablet+) -->
  223. <div class="toc-sidebar card">
  224. <div class="card-body">
  225. <h5>Table of Contents</h5>
  226. @if(isset($book['toc']) && is_array($book['toc']) && count($book['toc']) > 0)
  227. <ul>
  228. @foreach ($book['toc'] as $index => $item)
  229. <li class="toc-level-{{ $item['level'] }} {{ $item['disabled'] ? 'toc-disabled' : '' }}">
  230. @if (!$item['disabled'])
  231. <a href="/library/book/{{ $item['id'] }}/read">{{ $item['title'] }}</a>
  232. @else
  233. <span>{{ $item['title'] }}</span>
  234. @endif
  235. </li>
  236. @endforeach
  237. </ul>
  238. @else
  239. <div class="alert alert-warning">
  240. 此书没有目录
  241. </div>
  242. @endif
  243. </div>
  244. </div>
  245. <!-- Main Content -->
  246. <div class="content-area card">
  247. <div class="card-body">
  248. <!-- text area -->
  249. <div>
  250. <h2>{{ $book['title'] }}</h2>
  251. <p><strong>Author:</strong> {{ $book['author'] }}</p>
  252. <div class="content">
  253. @if(isset($book['content']))
  254. @foreach ($book['content'] as $index => $paragraph)
  255. <div id="para-{{ $paragraph['id'] }}">
  256. @foreach ($paragraph['text'] as $rows)
  257. <div style="display:flex;">
  258. @foreach ($rows as $col)
  259. <div style="flex:1;">
  260. @if($paragraph['level']<8)
  261. <h{{ $paragraph['level'] }}>{{ $col }}</h{{ $paragraph['level'] }}>
  262. @else
  263. <p>{{ $col }}</p>
  264. @endif
  265. </div>
  266. @endforeach
  267. </div>
  268. @endforeach
  269. </div>
  270. @endforeach
  271. @else
  272. <div>没有内容</div>
  273. @endif
  274. </div>
  275. </div>
  276. <!-- Nav buttons -->
  277. <div class="mt-6 pt-6">
  278. <ul class="pagination">
  279. @if(!empty($book["pagination"]["prev"]))
  280. <li class="page-item page-prev">
  281. <a class="page-link" href='{{ route("library.book.read",$book["pagination"]["prev"]["id"]) }}'>
  282. <div class="row align-items-center">
  283. <div class="col-auto">
  284. <!-- Download SVG icon from http://tabler.io/icons/icon/chevron-left -->
  285. <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">
  286. <path d="M15 6l-6 6l6 6"></path>
  287. </svg>
  288. </div>
  289. <div class="col">
  290. <div class="page-item-subtitle">previous</div>
  291. <div class="page-item-title">{{ $book["pagination"]["prev"]["title"] }}</div>
  292. </div>
  293. </div>
  294. </a>
  295. </li>
  296. @endif
  297. @if(!empty($book["pagination"]["next"]))
  298. <li class="page-item page-next">
  299. <a class="page-link" href='{{ route("library.book.read",$book["pagination"]["next"]["id"]) }}'>
  300. <div class="row align-items-center">
  301. <div class="col">
  302. <div class="page-item-subtitle">next</div>
  303. <div class="page-item-title">{{ $book["pagination"]["next"]["title"] }}</div>
  304. </div>
  305. <div class="col-auto">
  306. <!-- Download SVG icon from http://tabler.io/icons/icon/chevron-right -->
  307. <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">
  308. <path d="M9 6l6 6l-6 6"></path>
  309. </svg>
  310. </div>
  311. </div>
  312. </a>
  313. </li>
  314. @endif
  315. </ul>
  316. </div>
  317. <!-- Related Books -->
  318. <div class="related-books">
  319. <h3>Related Books</h3>
  320. <div class="row row-cards">
  321. @if(isset($relatedBooks))
  322. @foreach ($relatedBooks as $relatedBook)
  323. <div class="col-md-4">
  324. <div class="card">
  325. <div class="card-img-container">
  326. <img src="{{ $relatedBook['image'] }}" alt="{{ $relatedBook['title'] }}">
  327. </div>
  328. <div class="card-body">
  329. <h5 class="card-title">{{ $relatedBook['title'] }}</h5>
  330. <p class="card-text">{{ $relatedBook['description'] }}</p>
  331. <a href="{{ $relatedBook['link'] }}" class="btn btn-primary">Read Now</a>
  332. </div>
  333. </div>
  334. </div>
  335. @endforeach
  336. @else
  337. <div>没有相关章节</div>
  338. @endif
  339. </div>
  340. </div>
  341. </div>
  342. </div>
  343. <!-- Right Sidebar (Desktop) -->
  344. <div class="right-sidebar card">
  345. <div class="card-body">
  346. <h5>Download</h5>
  347. <ul class="list-unstyled">
  348. @if(isset($book['downloads']))
  349. @foreach ($book['downloads'] as $download)
  350. <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>
  351. @endforeach
  352. @else
  353. <div>没有下载链接</div>
  354. @endif
  355. </ul>
  356. <h5>Category</h5>
  357. @foreach ($book['categories'] as $category)
  358. <span class="badge bg-blue text-blue-fg">{{ $category['name'] }}</span>
  359. @endforeach
  360. <h5>Tags</h5>
  361. <div>
  362. @foreach ($book['tags'] as $tag)
  363. <span class="badge me-1">{{ $tag['name'] }}</span>
  364. @endforeach
  365. </div>
  366. </div>
  367. </div>
  368. </div>
  369. <!-- Tabler JS and Bootstrap -->
  370. <script src="https://cdn.jsdelivr.net/npm/@tabler/core@1.0.0-beta21/dist/js/tabler.min.js"></script>
  371. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
  372. <script>
  373. // Theme Toggle
  374. const themeToggle = document.getElementById('themeToggle');
  375. const body = document.body;
  376. themeToggle.addEventListener('click', (e) => {
  377. e.preventDefault();
  378. if (body.classList.contains('light-mode')) {
  379. body.classList.remove('light-mode');
  380. body.classList.add('dark-mode');
  381. fetch('{{ route("theme.toggle") }}', {
  382. method: 'POST',
  383. headers: {
  384. 'X-CSRF-TOKEN': '{{ csrf_token() }}',
  385. 'Content-Type': 'application/json'
  386. },
  387. body: JSON.stringify({
  388. theme: 'dark'
  389. })
  390. });
  391. themeToggle.innerHTML = '<i class="fas fa-sun"></i>';
  392. } else {
  393. body.classList.remove('dark-mode');
  394. body.classList.add('light-mode');
  395. fetch('{{ route("theme.toggle") }}', {
  396. method: 'POST',
  397. headers: {
  398. 'X-CSRF-TOKEN': '{{ csrf_token() }}',
  399. 'Content-Type': 'application/json'
  400. },
  401. body: JSON.stringify({
  402. theme: 'light'
  403. })
  404. });
  405. themeToggle.innerHTML = '<i class="fas fa-moon"></i>';
  406. }
  407. });
  408. // Smooth scroll for TOC links
  409. document.querySelectorAll('.toc-sidebar a, .offcanvas-body a').forEach(anchor => {
  410. anchor.addEventListener('click', function(e) {
  411. e.preventDefault();
  412. const targetId = this.getAttribute('href');
  413. const targetElement = document.querySelector(targetId);
  414. targetElement.scrollIntoView({
  415. behavior: 'smooth'
  416. });
  417. // Close drawer on mobile after clicking
  418. if (window.innerWidth < 768) {
  419. const drawer = document.querySelector('#tocDrawer');
  420. const bsDrawer = bootstrap.Offcanvas.getInstance(drawer);
  421. bsDrawer.hide();
  422. }
  423. });
  424. });
  425. </script>
  426. </body>
  427. </html>