mirror of
https://github.com/getgrav/grav.git
synced 2026-05-06 12:06:40 +02:00
don't output srcset when only one image
This commit is contained in:
@@ -151,28 +151,37 @@ trait ParsedownGravTrait
|
||||
// set the src element with the new generated url
|
||||
if (!isset($actions['lightbox'])) {
|
||||
$excerpt['element']['attributes']['src'] = $data['img_src'];
|
||||
$excerpt['element']['attributes']['srcset'] = $data['img_srcset'];;
|
||||
$excerpt['element']['attributes']['sizes'] = '100vw';
|
||||
|
||||
if ($data['img_srcset']) {
|
||||
$excerpt['element']['attributes']['srcset'] = $data['img_srcset'];;
|
||||
$excerpt['element']['attributes']['sizes'] = '100vw';
|
||||
}
|
||||
|
||||
} else {
|
||||
// Create the custom lightbox element
|
||||
|
||||
$attributes = $data['a_attributes'];
|
||||
$attributes['href'] = $data['a_href'];
|
||||
|
||||
$img_attributes = [
|
||||
'src' => $data['img_src'],
|
||||
'alt' => $alt,
|
||||
'title' => $title
|
||||
];
|
||||
|
||||
if ($data['img_srcset']) {
|
||||
$img_attributes['srcset'] = $data['img_srcset'];
|
||||
$img_attributes['sizes'] = '100vw';
|
||||
}
|
||||
|
||||
$element = array(
|
||||
'name' => 'a',
|
||||
'attributes' => $attributes,
|
||||
'handler' => 'element',
|
||||
'text' => array(
|
||||
'name' => 'img',
|
||||
'attributes' => array(
|
||||
'src' => $data['img_src'],
|
||||
'srcset' => $data['img_srcset'],
|
||||
'sizes' => '100vw',
|
||||
'alt' => $alt,
|
||||
'title' => $title
|
||||
)
|
||||
),
|
||||
'attributes' => $img_attributes
|
||||
)
|
||||
);
|
||||
|
||||
// Set any custom classes on the lightbox element
|
||||
|
||||
@@ -173,6 +173,11 @@ class Medium extends Data
|
||||
*/
|
||||
public function srcset($reset = true)
|
||||
{
|
||||
if (empty($this->alternatives)) {
|
||||
if ($reset) $this->reset();
|
||||
return '';
|
||||
}
|
||||
|
||||
$srcset = [ $this->url($reset) . ' ' . $this->get('width') . 'w' ];
|
||||
|
||||
foreach ($this->alternatives as $ratio => $medium) {
|
||||
@@ -213,13 +218,14 @@ class Medium extends Data
|
||||
*/
|
||||
public function html($title = null, $class = null, $reset = true)
|
||||
{
|
||||
$data = $this->htmlRaw($title, $class, $reset);
|
||||
$data = $this->htmlRaw($reset);
|
||||
|
||||
$title = $title ? $title : $this->get('title');
|
||||
$class = $class ? $class : '';
|
||||
|
||||
if ($this->image) {
|
||||
$output = '<img src="' . $data['img_src'] . '" srcset="' . $data['img_srcset'] . '" sizes="100vw" class="'. $class . '" alt="' . $title . '" />';
|
||||
$attributes = $data['img_srcset'] ? ' srcset="' . $data['img_srcset'] . '" sizes="100vw"' : '';
|
||||
$output = '<img src="' . $data['img_src'] . '"' . $attributes . ' class="'. $class . '" alt="' . $title . '" />';
|
||||
} else {
|
||||
$output = $data['text'];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user