Skip to content

Commit 55f230b

Browse files
author
Greg Bowler
authored
<title> updates (#594)
* build: update dependencies * feature: change the title in the body of the page
1 parent 4962ceb commit 55f230b

File tree

2 files changed

+51
-37
lines changed

2 files changed

+51
-37
lines changed

composer.lock

Lines changed: 37 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Middleware/RequestHandler.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ protected function completeRequestHandling(
128128
$this->handleProtectedGlobals();
129129
$this->handleLogicExecution();
130130

131+
$this->tidyView($this->viewModel);
132+
131133
// TODO: Why is this in the handle function?
132134
$documentBinder = $this->serviceContainer->get(DocumentBinder::class);
133135
$documentBinder->cleanDatasets();
@@ -428,4 +430,16 @@ private function forceTrailingSlashes(ServerRequestInterface $request):void {
428430
)
429431
->withStatus(307);
430432
}
433+
434+
// TODO: Handle other types of view.
435+
private function tidyView(HTMLDocument $document):void {
436+
foreach($document->querySelectorAll("body title, [data-page-title]") as $element) {
437+
$existing = $document->querySelector("title");
438+
$existing->remove();
439+
440+
$title = $document->createElement("title");
441+
$title->innerText = $element->innerText;
442+
$document->head->appendChild($title);
443+
}
444+
}
431445
}

0 commit comments

Comments
 (0)