Skip to content

Commit 1514b88

Browse files
committed
bug #114 Fix some edge-case related to TOCs of docs without titles (javiereguiluz)
This PR was merged into the main branch. Discussion ---------- Fix some edge-case related to TOCs of docs without titles In some symfony.com docs we have some partial docs that are included in other docs ... but instead of naming them as `foo.rst.inc` as in Symfony Docs, we name them as `foo.rst`. This included file is just a paragraph without any titles, so when trying to generate the TOC it fails. Commits ------- 51d6c0f Fix some edge-case related to TOCs of docs without titles
2 parents da18734 + 51d6c0f commit 1514b88

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Generator/JsonGenerator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@ public function generateJson(string $masterDocument = 'index'): array
6868

6969
$crawler = new Crawler(file_get_contents($this->buildConfig->getOutputDir().'/'.$filename.'.html'));
7070

71+
// happens when some doc is a partial included in other doc an it doesn't have any titles
72+
$toc = false === current($metaEntry->getTitles()) ? [] : $this->generateToc($metaEntry, current($metaEntry->getTitles())[1]);
7173
$next = $this->determineNext($parserFilename, $flattenedTocTree, $masterDocument);
7274
$prev = $this->determinePrev($parserFilename, $flattenedTocTree);
7375
$data = [
7476
'title' => $metaEntry->getTitle(),
7577
'parents' => $this->determineParents($parserFilename, $tocTreeHierarchy) ?: [],
7678
'current_page_name' => $parserFilename,
77-
'toc' => $toc = $this->generateToc($metaEntry, current($metaEntry->getTitles())[1]),
79+
'toc' => $toc,
7880
'toc_options' => TocExtension::getOptions($toc),
7981
'next' => $next,
8082
'prev' => $prev,

0 commit comments

Comments
 (0)