Skip to content

Commit 5e01735

Browse files
committed
feat: priority tags (closes #112)
1 parent d144793 commit 5e01735

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

classes/Meta.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ protected function metaArray(): array
121121
public const TAG_TYPE_MAP = [
122122
[
123123
'tag' => 'title',
124+
'priority' => true,
124125
'tags' => [
125126
'title'
126127
]
@@ -221,6 +222,7 @@ public function snippetData(?array $raw = null): array
221222
'tag' => $tag['tag'],
222223
'attributes' => $value,
223224
'content' => null,
225+
'priority' => $tag['priority'] ?? false,
224226
];
225227
continue;
226228
}
@@ -234,6 +236,7 @@ public function snippetData(?array $raw = null): array
234236
$tag['attributes']['content'] => $value,
235237
] : null,
236238
'content' => !isset($tag['attributes']) ? $value : null,
239+
'priority' => $tag['priority'] ?? false,
237240
];
238241
}
239242

classes/Sitemap/Sitemap.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ public function toString(): string
7171

7272
$root = $doc->createElementNS('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset');
7373
$root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
74-
$root->setAttribute('seo-version', App::plugin('tobimori/seo')->version());
74+
75+
// version can be null when installing branches during development
76+
if ($version = App::plugin('tobimori/seo')->version()) {
77+
$root->setAttribute('seo-version', $version);
78+
}
7579

7680
foreach ($this as $url) {
7781
$root->appendChild($url->toDOMNode($doc));

snippets/head.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88

99
$tags = $page->metadata()->snippetData();
1010

11+
// if we're using slots, the user wants to output priority tags such as <title>
12+
// before their stylesheet, script, etc. tags
13+
if (isset($slot)) {
14+
foreach (array_filter($tags, fn($tag) => $tag['priority']) as $tag) {
15+
echo Html::tag($tag['tag'], $tag['content'] ?? null, $tag['attributes'] ?? []) . PHP_EOL;
16+
}
17+
18+
echo $slot;
19+
20+
$tags = array_filter($tags, fn($tag) => !$tag['priority']);
21+
}
22+
23+
// then output other tags as normal
24+
// this is unfiltered if slots is not set.
1125
foreach ($tags as $tag) {
1226
echo Html::tag($tag['tag'], $tag['content'] ?? null, $tag['attributes'] ?? []) . PHP_EOL;
1327
}

0 commit comments

Comments
 (0)