otiai10 / opengraph

Open Graph Parser for Go
https://pkg.go.dev/github.com/otiai10/opengraph
MIT License
65 stars 13 forks source link

og.url is not mapped #11

Closed anuragdhingra closed 3 years ago

anuragdhingra commented 3 years ago

@otiai10 In the current implementation, opengraph.URL defaults to the parsed request URL and doesn't maps the og.url meta tag. Is it okay to add a new field called Value in opengraph.URL struct which maps the og.url meta tag value?

Or if I am missing something here, please let me know. I want fetch the og.url meta tag from the parsed HTML. Thank you.

otiai10 commented 3 years ago

ah... nice catch. You caught the problem correctly. Thank you.

If og:url exists, it should be preferred over the URL which is parsed from initial input. Thus, we don't need Value field in opengraph.URL, but just overwrite it if og:url exists.

What do you think?

anuragdhingra commented 3 years ago

The reason I would prefer a different value is that if og.URL is overwritten we won't have any clear mechanism to know if it was fetched from the meta tag or is the default value. Also, I believe maybe passing the value as string instead of URL would be better due to validity issues. What do you think?

otiai10 commented 3 years ago

What kind of validity do you mean?

anuragdhingra commented 3 years ago

What kind of validity do you mean?

If the content/URL set on og:url meta property is invalid then parsing it might cause an error which might not be what we want maybe? Just returning back the content fetched from the property as string should be okay acc. to me.

Also, if we overrite it do we have any way to check if og.url property was found or not?

anuragdhingra commented 3 years ago

Closing this now. Thank you!