read.blade.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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="{{ route('library.book.read', $item['id']) }}">{{ $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="{{ route('library.book.read', $item['id']) }}">
  232. {{ $item['title'] }}
  233. </a>
  234. @else
  235. <span>{{ $item['title'] }}</span>
  236. @endif
  237. </li>
  238. @endforeach
  239. </ul>
  240. @else
  241. <div class="alert alert-warning">
  242. 此书没有目录
  243. </div>
  244. @endif
  245. </div>
  246. </div>
  247. <!-- Main Content -->
  248. <div class="content-area card">
  249. <div class="card-body">
  250. <!-- text area -->
  251. <div>
  252. <h2>{{ $book['title'] }}</h2>
  253. <p><strong>Author:</strong> <span>{{ $book['author'] }}@
  254. <a href="{{ route('blog.index', ['user' => $book['publisher']->username]) }}">
  255. {{ $book['publisher']->nickname }}
  256. </a>
  257. </span></p>
  258. <div class="content">
  259. @if(isset($book['content']))
  260. @foreach ($book['content'] as $index => $paragraph)
  261. <div id="para-{{ $paragraph['id'] }}">
  262. @foreach ($paragraph['text'] as $rows)
  263. <div style="display:flex;">
  264. @foreach ($rows as $col)
  265. <div style="flex:1;">
  266. @if($paragraph['level']<8)
  267. <h{{ $paragraph['level'] }}>{{ $col }}</h{{ $paragraph['level'] }}>
  268. @else
  269. <p>{{ $col }}</p>
  270. @endif
  271. </div>
  272. @endforeach
  273. </div>
  274. @endforeach
  275. </div>
  276. @endforeach
  277. @else
  278. <div>没有内容</div>
  279. @endif
  280. </div>
  281. </div>
  282. <!-- Nav buttons -->
  283. <div class="mt-6 pt-6">
  284. <ul class="pagination">
  285. @if(!empty($book["pagination"]["prev"]))
  286. <li class="page-item page-prev">
  287. <a class="page-link" href='{{ route("library.book.read",$book["pagination"]["prev"]["id"]) }}'>
  288. <div class="row align-items-center">
  289. <div class="col-auto">
  290. <!-- Download SVG icon from http://tabler.io/icons/icon/chevron-left -->
  291. <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">
  292. <path d="M15 6l-6 6l6 6"></path>
  293. </svg>
  294. </div>
  295. <div class="col">
  296. <div class="page-item-subtitle">previous</div>
  297. <div class="page-item-title">{{ $book["pagination"]["prev"]["title"] }}</div>
  298. </div>
  299. </div>
  300. </a>
  301. </li>
  302. @endif
  303. @if(!empty($book["pagination"]["next"]))
  304. <li class="page-item page-next">
  305. <a class="page-link" href='{{ route("library.book.read",$book["pagination"]["next"]["id"]) }}'>
  306. <div class="row align-items-center">
  307. <div class="col">
  308. <div class="page-item-subtitle">next</div>
  309. <div class="page-item-title">{{ $book["pagination"]["next"]["title"] }}</div>
  310. </div>
  311. <div class="col-auto">
  312. <!-- Download SVG icon from http://tabler.io/icons/icon/chevron-right -->
  313. <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">
  314. <path d="M9 6l6 6l-6 6"></path>
  315. </svg>
  316. </div>
  317. </div>
  318. </a>
  319. </li>
  320. @endif
  321. </ul>
  322. </div>
  323. <!-- Related Books -->
  324. <div class="related-books">
  325. <h3>Related Books</h3>
  326. <div class="row row-cards">
  327. @if(isset($relatedBooks))
  328. @foreach ($relatedBooks as $relatedBook)
  329. <div class="col-md-4">
  330. <div class="card">
  331. <div class="card-img-container">
  332. <img src="{{ $relatedBook['image'] }}" alt="{{ $relatedBook['title'] }}">
  333. </div>
  334. <div class="card-body">
  335. <h5 class="card-title">{{ $relatedBook['title'] }}</h5>
  336. <p class="card-text">{{ $relatedBook['description'] }}</p>
  337. <a href="{{ $relatedBook['link'] }}" class="btn btn-primary">Read Now</a>
  338. </div>
  339. </div>
  340. </div>
  341. @endforeach
  342. @else
  343. <div>没有相关章节</div>
  344. @endif
  345. </div>
  346. </div>
  347. </div>
  348. </div>
  349. <!-- Right Sidebar (Desktop) -->
  350. <div class="right-sidebar card">
  351. <div class="card-body">
  352. <h5>Download</h5>
  353. <ul class="list-unstyled">
  354. @if(isset($book['downloads']))
  355. @foreach ($book['downloads'] as $download)
  356. <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>
  357. @endforeach
  358. @else
  359. <div>没有下载链接</div>
  360. @endif
  361. </ul>
  362. <h5>Category</h5>
  363. @foreach ($book['categories'] as $category)
  364. <span class="badge bg-blue text-blue-fg">{{ $category['name'] }}</span>
  365. @endforeach
  366. <h5>Tags</h5>
  367. <div>
  368. @foreach ($book['tags'] as $tag)
  369. <span class="badge me-1">{{ $tag['name'] }}</span>
  370. @endforeach
  371. </div>
  372. </div>
  373. </div>
  374. </div>
  375. <!-- Tabler JS and Bootstrap -->
  376. <script src="https://cdn.jsdelivr.net/npm/@tabler/core@1.0.0-beta21/dist/js/tabler.min.js"></script>
  377. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
  378. <script>
  379. // Theme Toggle
  380. const themeToggle = document.getElementById('themeToggle');
  381. const body = document.body;
  382. themeToggle.addEventListener('click', (e) => {
  383. e.preventDefault();
  384. if (body.classList.contains('light-mode')) {
  385. body.classList.remove('light-mode');
  386. body.classList.add('dark-mode');
  387. fetch('{{ route("theme.toggle") }}', {
  388. method: 'POST',
  389. headers: {
  390. 'X-CSRF-TOKEN': '{{ csrf_token() }}',
  391. 'Content-Type': 'application/json'
  392. },
  393. body: JSON.stringify({
  394. theme: 'dark'
  395. })
  396. });
  397. themeToggle.innerHTML = '<i class="fas fa-sun"></i>';
  398. } else {
  399. body.classList.remove('dark-mode');
  400. body.classList.add('light-mode');
  401. fetch('{{ route("theme.toggle") }}', {
  402. method: 'POST',
  403. headers: {
  404. 'X-CSRF-TOKEN': '{{ csrf_token() }}',
  405. 'Content-Type': 'application/json'
  406. },
  407. body: JSON.stringify({
  408. theme: 'light'
  409. })
  410. });
  411. themeToggle.innerHTML = '<i class="fas fa-moon"></i>';
  412. }
  413. });
  414. // Smooth scroll for TOC links
  415. document.querySelectorAll('.toc-sidebar a, .offcanvas-body a').forEach(anchor => {
  416. anchor.addEventListener('click', function(e) {
  417. e.preventDefault();
  418. const targetId = this.getAttribute('href');
  419. const targetElement = document.querySelector(targetId);
  420. targetElement.scrollIntoView({
  421. behavior: 'smooth'
  422. });
  423. // Close drawer on mobile after clicking
  424. if (window.innerWidth < 768) {
  425. const drawer = document.querySelector('#tocDrawer');
  426. const bsDrawer = bootstrap.Offcanvas.getInstance(drawer);
  427. bsDrawer.hide();
  428. }
  429. });
  430. });
  431. </script>
  432. </body>
  433. </html>