read.blade.php 18 KB

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