Storyline: unfoldable section list per chapter in the sidebar

Each chapter in the right-hand menu gets a caret that unfolds its
numbered sections (e.g. the prologue's 28 scenes); clicking one jumps
straight to it. The chapter you're reading starts unfolded, other
chapters' sections link across (/storyline/overview#section-…), and the
section at the top of the pane is highlighted as you scroll.

- ChapterOutline service parses each rendered chapter for its
  <h2 class="storyline-section"> headings, adds anchor ids and returns the
  outline; the controller renders all chapters once to feed the sidebar.
- storyline-toc Stimulus controller: fold/unfold, in-pane jump, scroll-spy
  (works in the split view and in the small-screen window-scroll fallback).
- Tests for the outline parser.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Frank
2026-09-21 18:44:54 +02:00
co-authored by Claude Sonnet 5
parent 8b8f67c1d0
commit b77e5eaa4f
6 changed files with 229 additions and 8 deletions
+16 -1
View File
@@ -4,6 +4,7 @@ namespace App\Controller;
use App\Form\ChapterNoteType;
use App\Repository\ChapterNoteRepository;
use App\Storyline\ChapterOutline;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
@@ -51,7 +52,7 @@ class StorylineController extends AbstractController
}
#[Route('/storyline/{slug}', name: 'app_storyline_chapter', requirements: ['slug' => '[a-z0-9-]+'], methods: ['GET', 'POST'])]
public function chapter(string $slug, Request $request, ChapterNoteRepository $notes, EntityManagerInterface $em): Response
public function chapter(string $slug, Request $request, ChapterNoteRepository $notes, EntityManagerInterface $em, ChapterOutline $outline): Response
{
if (!isset(self::CHAPTERS[$slug])) {
throw $this->createNotFoundException('No such storyline chapter.');
@@ -71,6 +72,18 @@ class StorylineController extends AbstractController
return $this->redirectToRoute('app_storyline_chapter', ['slug' => $slug]);
}
// Render every chapter once: the current one is shown (with anchors),
// the rest only feed the sidebar's per-section jump lists.
$sections = [];
$body = '';
foreach (self::CHAPTERS as $s => $c) {
$processed = $outline->process($this->renderView($c['template']));
$sections[$s] = $processed['sections'];
if ($s === $slug) {
$body = $processed['html'];
}
}
$slugs = array_keys(self::CHAPTERS);
$pos = array_search($slug, $slugs, true);
@@ -78,6 +91,8 @@ class StorylineController extends AbstractController
'chapters' => self::CHAPTERS,
'slug' => $slug,
'chapter' => self::CHAPTERS[$slug],
'body' => $body,
'sections' => $sections,
'note' => $note,
'form' => $form,
'prev' => $pos > 0 ? $slugs[$pos - 1] : null,