Skip to content

Orphaned pages do not enforce uniqe title #502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public function applies(FieldListItemNode $fieldListItemNode): bool

public function apply(FieldListItemNode $fieldListItemNode, DocumentParserContext $documentParserContext): MetadataNode
{
$documentParserContext->getDocument()->setOrphan(true);

return new OrphanNode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function leaveNode(Node $node, CompilerContext $compilerContext): Node|nu
return $node;
}

if ($node->getTitle() === null) {
if ($node->getTitle() === null && !$node->isOrphan()) {
$this->logger->warning('Document has not title', $node->getLoggerInformation());
}

Expand Down
13 changes: 13 additions & 0 deletions packages/guides/src/Nodes/DocumentNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ final class DocumentNode extends CompoundNode
private DocumentEntryNode|null $documentEntry = null;
private SectionEntryNode|null $rootSectionEntry = null;
private bool $isRoot = false;
private bool $orphan = false;

public function __construct(
private readonly string $hash,
Expand Down Expand Up @@ -285,4 +286,16 @@ public function withIsRoot(bool $isRoot): DocumentNode

return $node;
}

public function isOrphan(): bool
{
return $this->orphan;
}

public function setOrphan(bool $orphan): DocumentNode
{
$this->orphan = $orphan;

return $this;
}
}
15 changes: 15 additions & 0 deletions tests/Integration/tests/orphan-without-title/expected/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document Title</title>

</head>
<body>
<div class="section" id="document-title">
<h1>Document Title</h1>

<p>Some Document</p>
</div>

</body>
</html>
11 changes: 11 additions & 0 deletions tests/Integration/tests/orphan-without-title/expected/orphan.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>


</head>
<body>
<p>A page without title that is marked as <code>orphan</code> does not cause warnings.</p>
</body>
</html>
5 changes: 5 additions & 0 deletions tests/Integration/tests/orphan-without-title/input/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
==============
Document Title
==============

Some Document
3 changes: 3 additions & 0 deletions tests/Integration/tests/orphan-without-title/input/orphan.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:orphan:

A page without title that is marked as `orphan` does not cause warnings.