khaosdoctor / deno-opengraph

Fetches and parses data from website to get their OpenGraph metadata
MIT License
4 stars 2 forks source link

OG image data not parsed correctly #5

Open darth-cheney opened 2 weeks ago

darth-cheney commented 2 weeks ago

When attempting to parse the og metadata from this article, I am getting a mangled object for the image part of the data:

{
    "site_name": "The Verge",
    "title": "Procreate’s anti-AI pledge attracts praise from digital creatives",
    "description": "“The path generative AI is on is wrong for us”",
    "url": "https://www.theverge.com/2024/8/19/24223473/procreate-anti-generative-ai-pledge-digital-illustration-creatives",
    "type": "image/jpeg",
    "image": "628", // <-- should be the image url
    "alt": "The Procreate logo against a pink and yellow backdrop.",
    "width": "1200",
    "height": "628"
}

The relevant OG meta tags for that article are:

<meta property="og:image" content="https://cdn.vox-cdn.com/thumbor/Hdefn7BxsBypcMb5faM0K-Ep1To=/0x0:2040x1360/1200x628/filters:focal(1020x680:1021x681)/cdn.vox-cdn.com/uploads/chorus_asset/file/25578652/Procreate_App_Icon.jpg">
<meta property="og:image:alt" content="The Procreate logo against a pink and yellow backdrop.">
<meta property="og:image:type" content="image/jpeg">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="628">

It seems that due to the (rather unfriendly) nature of the property names, and the fact that the root og:image itself has content that is, in fact, a url that is not explicitly named as its own property, the height is somehow getting assigned to the overall image property in the results.

It also appears that other image attributes -- which would ideally be in their own object -- are being pulled out into the top level (such as width, height, and alt)

For clarity, I think we would expect the above result to be:

{
    "site_name": "The Verge",
    "title": "Procreate’s anti-AI pledge attracts praise from digital creatives",
    "description": "“The path generative AI is on is wrong for us”",
    "url": "https://www.theverge.com/2024/8/19/24223473/procreate-anti-generative-ai-pledge-digital-illustration-creatives",
    "type": "image/jpeg",
    "image": {
        "content": "https://cdn.vox-cdn.com/thumbor/Hdefn7BxsBypcMb5faM0K-Ep1To=/0x0:2040x1360/1200x628/filters:focal(1020x680:1021x681)/cdn.vox-cdn.com/uploads/chorus_asset/file/25578652/Procreate_App_Icon.jpg",
        "alt": "The Procreate logo against a pink and yellow backdrop.",
        "width": "1200",
        "height": "628"
    }
}
khaosdoctor commented 1 week ago

Thanks for the comment! I'll get to it ASAP