getkirby / kirby

Kirby's core application folder
https://getkirby.com
Other
1.31k stars 168 forks source link

Srcset support for `(image: ...)` #2741

Closed distantnative closed 4 years ago

tobiasfabian commented 5 years ago

I think you are planning something like this: (image: plant.jpg srcset: aside) or (image: plant.jpg srcset: 300, 800, 1024])

Which will be super cool!

Maybe it’s difficult to explain content editors the meaning of srcset. What do you think about a srcset field property like this.

fields:
  text:
    label: Text
    type: textarea
    srcset: 300, 800, 1024

So the content editor can just throw in images and all images will be automatically resized with the given srcset.

Another idea would be srcset presets per textarea field. Like this:

fields:
  text:
    label: Text
    type: textarea
    srcsets: 
      default: 300, 800, 1024
      cover: 800, 1024, 2048

But maybe that’s too much.

bastianallgeier commented 5 years ago

@tobiasfabian I love this idea!

distantnative commented 5 years ago

This would mean that we need to load the blueprint when rendering a page. Usually we don’t do that.

Alternatively the blueprint settings could only have the effect that the right srcset attributes get entered when using the textareas toolbar.

iamwebrocker commented 5 years ago

This is cool, I just thought about tinkering with the (image: ) kirbytag in a similar way. To keep simple I thought about using srcset preset names defined in config.php image -> thumbs -> srcset … (which I have there defined anyway) and then using the image->srcset() function in the tag's php section. :)

moritzebeling commented 5 years ago

Theoretically:


That means, additionally to the Srcset option in the Kirbytag, there should be a way to define default values of Kirbytags. Where would be a good place to do that?

PS: Sorry, but personally I am very emotional about this, since Wordpress so heavily messed up the separation of editing content and rendering layouts.

bvdputte commented 4 years ago

I fully agree with @moritzebeling : this should be invisible for editors if possible. A set of opinionated defaults, set in the config.php would also be the first place where I'ld look to set this (consistent ith video options).

It would be a plus to expose this in the kirbytag as described above by @tobiasfabian for the more advanced editor.

If you want this to be configurable per template, but don't want to read blueprints on read content, you could also add this to config.php e.g. like this:

// site/config/config.php
return [
  'kirbytext' => [
    'img' => [
      'default' => [
        'srcset' => [ 400, 800, 1600 ]
      ],
      'template-a' => [
        'srcset' => [ 200, 400, 800 ]
      ],
      'template-b' => [
        'srcset' => [ 300, 600, 900 ]
      ]
    ]
  ]
];
ipenburg commented 4 years ago

Who's problem are we trying to solve here? It's not like it's currently impossible or even hard to create a responsive website with Kirby. Based on a visual design you can choose if you need to implement only some automatic resolution switching or need to also bother editors with solving art direction problems. If it's not clear what built-in srcset support is supposed to solve we probably just end up with an opinionated default that ticks some responsive checkbox without much additional value over a less complex solution.

So, maybe it makes sense to formulate this feature as a User Story: As a < type of user >, I want < some goal > so that < some reason >?

distantnative commented 4 years ago

Since this doesn't seem as clear cut and with our ambition to reduce issues in this repo to mainly bug reports, I have created a Idea on Nolt referencing this great discussion: https://kirby.nolt.io/112