Kaynağa Gözat

feat: 阅读页 TOC 标题显示书名

新增 getBookTitle(),取所在书的顶层 para 的章节标题(ProgressChapter
优先,回退 PaliText.toc)。read.blade.php 的 TOC 抽屉与侧边栏标题
由「目录」改为显示书名。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
visuddhinanda 4 hafta önce
ebeveyn
işleme
74295bf4cd

+ 18 - 1
api-v13/app/Http/Controllers/Library/BookController.php

@@ -41,7 +41,7 @@ class BookController extends Controller
 
         $book = $this->getBookInfo($bookRaw);
         $book['contents'] = $this->getBookToc($bookRaw->book, $bookRaw->para, $channelId);
-
+        $book['book_title'] = $this->getBookTitle($bookRaw->book, $bookRaw->para, $channelId);
         // 获取其他版本
         $others = ProgressChapter::with('channel.owner')
             ->where('book', $bookRaw->book)
@@ -130,6 +130,7 @@ class BookController extends Controller
         $book['author'] = $channel['name'];
         $book['studio'] = $studio;
         $book['tags'] = [];
+        $book['book_title'] = $this->getBookTitle((int) $bookId, (int) $paraId, $channelId);
 
         $book['pagination'] = $this->pagination((int) $bookId, (int) $paraId, $channelId);
 
@@ -190,6 +191,22 @@ class BookController extends Controller
         ];
     }
 
+    private function getBookTitle(int $book, int $paragraph, string $channelId)
+    {
+        $bookTopPara = $this->paliTextService->getBookPara($book, $paragraph)->paragraph;
+        $title = $chapters = ProgressChapter::where('book', $book)
+            ->where('para', $bookTopPara)
+            ->where('channel_id', $channelId)
+            ->value('title');
+        if (empty($title)) {
+            $title = PaliText::where('book', $book)
+                ->whereBetween('paragraph', $bookTopPara)
+                ->value('toc');
+        }
+
+        return $title;
+    }
+
     private function getBookToc(int $book, int $paragraph, string $channelId, $minLevel = 2, $maxLevel = 2): array
     {
         $currBook = $this->bookStart($book, $paragraph);

+ 2 - 2
api-v13/resources/views/library/book/read.blade.php

@@ -135,7 +135,7 @@
 {{-- TOC Offcanvas(mobile) --}}
 <div class="offcanvas offcanvas-start" tabindex="-1" id="tocDrawer">
     <div class="offcanvas-header">
-        <h5 class="offcanvas-title">{{ __('library.toc') }}</h5>
+        <h5 class="offcanvas-title">{{ $book['book_title'] }}</h5>
         <button type="button" class="btn-close" data-bs-dismiss="offcanvas"></button>
     </div>
     <div class="offcanvas-body">
@@ -150,7 +150,7 @@
         {{-- TOC 侧边栏(tablet+) --}}
         <div class="toc-sidebar card">
             <div class="card-body">
-                <h5>{{ __('library.toc') }}</h5>
+                <h5>{{ $book['book_title'] }}</h5>
                 @include('library.book.toc', ['toc' => $book['toc'] ?? []])
             </div>
         </div>