Seed editable default header and footer pages

This commit is contained in:
2026-11-23 21:21:41 +08:00
parent 74355914d9
commit e2a0db9cd5
10 changed files with 62 additions and 10 deletions
+13 -1
View File
@@ -105,7 +105,7 @@ final class Html
return self::bodyMarkup($body);
}
public static function sharedFragment(string $html, string $scope, string $account): string
public static function sharedFragment(string $html, string $scope, string $account, ?string $path = null): string
{
$document = new DOMDocument('1.0', 'UTF-8');
$document->loadHTML('<!doctype html><html><head><meta charset="UTF-8"></head><body>' . $html . '</body></html>', LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_NONET);
@@ -114,6 +114,18 @@ final class Html
return '';
}
self::scopeIds($body, $scope);
if ($path !== null) {
foreach ($body->getElementsByTagName('nav') as $nav) {
if (!in_array('primary-nav', preg_split('/\s+/', $nav->getAttribute('class')), true)) {
continue;
}
foreach ($nav->getElementsByTagName('a') as $link) {
if ($link->getAttribute('href') === $path) {
$link->setAttribute('aria-current', 'page');
}
}
}
}
foreach (iterator_to_array($body->getElementsByTagName('a')) as $node) {
if (!in_array('studio-member-slot', preg_split('/\s+/', $node->getAttribute('class')), true)) {
continue;