-
Notifications
You must be signed in to change notification settings - Fork 941
Open
Description
Moved from https://yoast.atlassian.net/browse/IM-2032
Reporter: @jonoalderson
Description
When an attachment page represents a non-image (e.g., a txt file or video), our schema output is incorrect.
E.g., an uploaded txt file generates the following output. Note that the thumbnailUrl property of the WebPage is blank, and the ImageObject (referenced by the primaryImageOfPage and image properties of the WebPage) is ‘empty’.
{
"@type": "WebPage",
"@id": "http://blank-test.local/wp-content/uploads/2022/09/test.txt",
"url": "http://blank-test.local/wp-content/uploads/2022/09/test.txt",
"name": "test - blank test",
"isPartOf": {
"@id": "http://blank-test.local/#website"
},
"primaryImageOfPage": {
"@id": "http://blank-test.local/wp-content/uploads/2022/09/test.txt#primaryimage"
},
"image": {
"@id": "http://blank-test.local/wp-content/uploads/2022/09/test.txt#primaryimage"
},
"thumbnailUrl": "",
"datePublished": "2022-09-27T09:36:02+00:00",
"dateModified": "2022-09-27T09:36:02+00:00",
"breadcrumb": {
"@id": "http://blank-test.local/wp-content/uploads/2022/09/test.txt#breadcrumb"
},
"inLanguage": "en-US",
"potentialAction": [
{
"@type": "ReadAction",
"target": [
"http://blank-test.local/wp-content/uploads/2022/09/test.txt"
]
}
]
},
{
"@type": "ImageObject",
"inLanguage": "en-US",
"@id": "http://blank-test.local/wp-content/uploads/2022/09/test.txt#primaryimage",
"url": "",
"contentUrl": ""
},
To address this, we should (on attachment pages only):
- Determine whether the attachment is a valid image:
- If it has a suitable mime type (e.g.,
jpg/png/svg/gif/bmp/webp/avif) - If it has a valid
urlandcontentUrlproperty
- If it has a suitable mime type (e.g.,
- If not:
- Don’t output the
ImageObjectnode representing it - If that node would have been referenced in the
primaryImageOfPageand/orimageproperty of theWebPage, unset those properties.
- Don’t output the