khaosdoctor / deno-opengraph

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

Why don't you export the interfaces as well? #1

Open ooker777 opened 1 month ago

ooker777 commented 1 month ago

I don't see any drawback for this. Also, how about declaring standard metadata names? Or is it that you don't have time to declaring them?

ooker777 commented 1 month ago

How about this?

type MetaTags = {
  /**
   * Defined from HTML specification
   * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta/name 
   */
  "application-name"?: string,
  author?: string
  description?: string,
  generator?: string,
  keywords?: string,
  referrer?: string,
  "theme-color"?: string,
  "color-scheme"?: string,
  viewport?: string,

  // Defined from other specifications
  creator?: string,
  googlebot?: string,
  robots?: string,
  publisher?: string,

  /**
   * Defined from Open Graph
   * @see https://ogp.me/
   */ 
  og?: OpenGraphTags,
  article: {
    publish_time: string,
    modified_time: string,
    expiration_time: string,
    author: string,
    section: string,
    tag: string
  }   
  book: {
    author: string,
    isbn: string,
    release_date: string,
    tag: string
  } 
  profile: {
    first_name: string,
    last_name: string,
    username: string,
    gender: string
  } 

  // Defined from Twitter
  twitter: TwitterTags

  [extraKeys: string]: unknown;
}
khaosdoctor commented 1 month ago

I'm not sure if this would fit in the scope because these are not OpenGraph tags, they're HTML meta tags. In general when you're looking up for OG-specific content, you wouldn't receive these tags back.

ooker777 commented 1 month ago

But isn't that the plugin returns HTML meta tags as well?

khaosdoctor commented 1 month ago

I mean, it's possible, because we are already fetching all the HTML along with it, the OG tags are a subset of the meta tags returned from the HTML response. I could add a method just to return anything that doesn't have a prefix and it's just meta but I'm not sure if it would be within this scope because this package was supposed to pick up only OG tags.

Maybe I'm getting your proposal wrong too, if you could open a PR with the changes you'd like to see, I can review them :)

ooker777 commented 1 month ago

Me too. I first comes to this lib to extract OG tags only, but after some refactors I only use the getMetaTags() function. I think the standard meta tags are more important, more popular and more used than the OG tags. After all if the OG tags are missing the social card previewer will use the standard tags.

In this PR I add an utils.ts file to illustrate how I use the lib to extract the correct info. Can you take a look at it?