Skip to content

Commit 9a56e78

Browse files
committed
use new seo alt text field
1 parent 6563ce5 commit 9a56e78

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

site/blueprints/files/image.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ title: Image
22
accept:
33
extension: jpg, jpeg, png, svg
44
type: image
5+
create:
6+
width: 2600
7+
quality: 90
58

69
fields:
710
alt:
811
label: Alternative Text/Image Description
9-
type: seo-alt-text
12+
type: alt-text
13+
autogenerate: true
1014
help: The alternative text helps visually impaired users & search engine crawlers understand the content of the image.

site/config/seo.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
'template' => 'image'
1313
],
1414
'ai' => [
15-
'provider' => 'openrouter',
15+
'provider' => 'gemini',
1616
'providers' => [
17-
'openrouter' => [
17+
'gemini' => [
1818
'config' => [
19-
'apiKey' => env('OPENROUTER_API_KEY'),
20-
'model' => 'google/gemini-2.5-flash-preview-09-2025',
19+
'apiKey' => env('GEMINI_API_KEY'),
2120
]
2221
]
2322
]

site/snippets/image.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,17 @@
4141
$existing = $svg->getAttribute('style');
4242
$svg->setAttribute('style', $existing ? "{$existing}; {$attrStyle}" : $attrStyle);
4343
}
44-
$altText = $alt ?? ($isFile ? $image->alt()->value() : null);
45-
if ($altText) {
46-
$svg->setAttribute('aria-label', $altText);
44+
if (isset($alt)) {
45+
$svg->setAttribute('aria-label', $alt);
4746
$svg->setAttribute('role', 'img');
47+
} elseif ($isFile) {
48+
$altText = $image->alt()->toAltText();
49+
if ($altText->isDecorative()) {
50+
$svg->setAttribute('role', 'presentation');
51+
} elseif ($altText->text() !== '') {
52+
$svg->setAttribute('aria-label', $altText->text());
53+
$svg->setAttribute('role', 'img');
54+
}
4855
}
4956
foreach ($attr as $key => $value) {
5057
$svg->setAttribute($key, $value);
@@ -88,13 +95,12 @@
8895
$src = $clientBlur
8996
? 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='
9097
: $image->thUri($ratio);
91-
?>
98+
$altAttr = isset($alt) ? ['alt' => $alt] : ($isFile ? $image->alt()->toAltText()->toAttr() : []); ?>
9299
<?= Html::img($src, [
93100
'data-thumbhash' => $clientBlur ? $image->th($ratio) : null,
94101
'data-src' => $medianUrl,
95102
'width' => $image->width(),
96103
'height' => $ratio ? floor($image->width() / $ratio) : $image->height(),
97-
'alt' => $alt ?? ($isFile ? $image->alt() : null),
98104
'loading' => $lazy ? 'lazy' : null,
99105
'draggable' => false,
100106
($lazy ? 'data-srcset' : 'srcset') => $srcsetString,
@@ -106,6 +112,7 @@
106112
"object-position: " . ($focus ?? "50% 50%"),
107113
$attrStyle ?: null,
108114
]), '; '),
115+
...$altAttr,
109116
...$attr,
110117
]) ?>
111118
<?php endif ?>

0 commit comments

Comments
 (0)