# 将带有超链接的图片文件名用作alt标签

**URL:** <https://meta.discourse.org/t/use-the-hotlinked-image-filename-as-the-alt-tag/355843>\
**Category:** UX\
**Created:** [2025年三月5日 12:23 UTC](https://meta.discourse.org/t/use-the-hotlinked-image-filename-as-the-alt-tag/355843 "2025-03-05T12:23:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsims](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dsims/32/485916_2.png) [@dsims](https://meta.discourse.org/u/dsims)\
**Post date:** [2025年三月5日 12:23 UTC](https://meta.discourse.org/t/use-the-hotlinked-image-filename-as-the-alt-tag/355843/1 "2025-03-05T12:23:14Z")

</div>

我的论坛收到了很多带有“oneboxed”热链接图片网址的帖子，它们能自动转换为上传图片很棒，但我失望地发现原始上下文丢失了。唯一知道原始网址/来源的方法是查看帖子修订历史记录。

有几种处理方式，但我认为一个好的开始是设置 `alt` 属性为文件名，以匹配普通图片上传的工作方式。这意味着它也会出现在灯箱中，而不是一个空白的标题。

这对于可访问性来说也更好，因为一个_空白/空_的 `alt` 标签基本上意味着“你可以忽略这张图片”，但在我们的例子中，图片通常是帖子的主题。

---

<div class="post-metadata">

**Author:** ![dsims](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dsims/32/485916_2.png) [@dsims](https://meta.discourse.org/u/dsims)\
**Post date:** [2025年三月5日 12:23 UTC](https://meta.discourse.org/t/use-the-hotlinked-image-filename-as-the-alt-tag/355843/2 "2025-03-05T12:23:58Z")

</div>

PR 在此：

> <https://github.com/discourse/discourse/pull/31651>
>
> Currently, when converting raw hotlinked image urls to image upload markdown, th…e \`alt\` attribute is left blank.
> This change sets the \`alt\` to the original filename (which means it will also appear in the lightbox).
> This adds more context and accessibility to the image and is consistent with how regular uploaded images default to use the filename.
> 
> For example:
> \`http://foo.bar/screenshot.jpg\` becomes \`!\[screenshot\](upload://bEs9WFJErcB8y7m1Ye5JopTWeX3.jpeg)\`
