FriendsOfFlarum / upload

The file upload extension with insane intelligence for your Flarum forum.
https://discuss.flarum.org/d/4154
MIT License
176 stars 95 forks source link

Image title / alt #300

Open majkimajki opened 2 years ago

majkimajki commented 2 years ago

Hi,

am I blind, or does FoF Upload not put in alt / title when uploading an image?

Is there anyway you could make it a feature so that let's say the title of the disscusion is put in the alt or title tag?

clarkwinkelmann commented 2 years ago

There are 3 different templates that render an image:

Image preview template: uses img tag with a title and alt attributes set to the label

https://github.com/FriendsOfFlarum/upload/blob/98d02117bc152dbe548e06cd018a31d751273dca/resources/templates/image-preview.blade.php#L1

Image: uses a CSS background image, so alt isn't applicable

https://github.com/FriendsOfFlarum/upload/blob/98d02117bc152dbe548e06cd018a31d751273dca/resources/templates/image.blade.php#L3

Markdown: uses the built-in Markdown image tag. I see we hard-coded "Image description" as the default alt value, this was probably done with the intent that the user will modify it. We could probably use the label as the default value here, though since the label is generated from the filename, it might or might not be an improvement depending on the circumstances. We could also keep the alt value blank by default in the Markdown template.

https://github.com/FriendsOfFlarum/upload/blob/98d02117bc152dbe548e06cd018a31d751273dca/src/Templates/MarkdownImageTemplate.php#L45

Were you referring to one of these 3 situations, or is there another place where the alt value is completely missing?

majkimajki commented 2 years ago

Hi,

I'm using Upload by FriendsOfFlarum v.1.0.3

In the editor it shows as: upl-image-preview url=https://....jpg

Rendered html gives and output:

img src=".....jpg" title="" alt=""

clarkwinkelmann commented 2 years ago

Most likely the values will be blank in the preview, but they should be filled in the final render.

You could check what the base_name value is for the file inside of the database (fof_upload_files table). Maybe it's blank because the original filename consists of non-ASCII characters? Or maybe we have something going wrong with the base_name attribute generation?

majkimajki commented 2 years ago

Final render gives, img src=".....jpg" title="" alt="" - missing alt and title.

Both with jph/png, filename tested was, test.jpg so this should not be a problem.

To be honest I do not know what {@base_name} is, will check everything you wrote in the morning.

Is anybody able to replicate this error? I can't seem to find a flarum with FoF upload to check another site.

EDIT: Eg. https://creatorswave.com/d/327-what-do-you-want-to-make/3 gives blank also in rendered html.

Still, from what I understand {@base_name} gives exactly what? The name of the filename?

Maybe, a feature where title = title of disscussion, alt = 3 words from the post content?