Skip to content

Commit ed5fa13

Browse files
author
Greg Bowler
committed
Implement better URI class/ID on body tag, closes #242
1 parent 17608b0 commit ed5fa13

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/Dispatcher/PageDispatcher.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,21 +225,35 @@ public function setContentUri($uri, ResponseContent $content) {
225225
if(strrpos($uri, "/") === strlen($uri) - 1) {
226226
$uri .= "index";
227227
}
228+
228229
$body = $content->querySelector("body");
229230
$uri = trim($uri, "/");
230-
$uriPartTotal = "";
231-
foreach (explode("/", $uri) as $uriPart) {
232-
$body->classList->add($uriPart);
233-
if($uriPartTotal) {
234-
$body->classList->add($uriPartTotal);
231+
$classArray = [];
232+
233+
foreach(explode("/", $uri) as $uriPart) {
234+
$newClass = "";
235+
236+
foreach($classArray as $c) {
237+
if(strlen($newClass) > 0) {
238+
$newClass .= "_";
239+
}
240+
$newClass .= $c;
235241
}
236-
$uriPartTotal .= $uriPartTotal ? "_$uriPart" : $uriPart;
242+
243+
if(strlen($newClass) > 0) {
244+
$newClass .= "_";
245+
}
246+
247+
$classArray []= $newClass . $uriPart;
248+
}
249+
250+
foreach($classArray as $c) {
251+
$body->classList->add("dir--" . $c);
237252
}
238253

239254
$uri = str_replace("/", "_", $uri);
240-
$idUri = $uri;
241-
$content->querySelector("body")->id = $idUri;
255+
$body->id = "uri--" . $uri;
242256

243257
}
244258

245-
}#
259+
}#

0 commit comments

Comments
 (0)