apply static method

void apply({
  1. required String title,
  2. required String description,
  3. required String imageUrl,
  4. String? url,
  5. String? siteName,
  6. String? twitterSite,
  7. String? twitterCreator,
  8. TwitterCardType twitterCardType = TwitterCardType.summaryLargeImage,
  9. OgType ogType = OgType.website,
  10. String? imageWidth,
  11. String? imageHeight,
  12. String? imageAlt,
  13. String? locale,
})

Apply social preview tags for all platforms at once.

This sets Open Graph tags (Facebook, LinkedIn, Discord, Slack) and Twitter Card tags simultaneously.

Implementation

static void apply({
  required String title,
  required String description,
  required String imageUrl,
  String? url,
  String? siteName,
  String? twitterSite,
  String? twitterCreator,
  TwitterCardType twitterCardType = TwitterCardType.summaryLargeImage,
  OgType ogType = OgType.website,
  String? imageWidth,
  String? imageHeight,
  String? imageAlt,
  String? locale,
}) {
  if (!Webify.isInitialized) return;

  final webify = Webify.instance;

  // Open Graph (Facebook, LinkedIn, Discord, Slack, etc.)
  webify.platform.setPropertyMetaTag('og:title', title);
  webify.platform.setPropertyMetaTag('og:description', description);
  webify.platform.setPropertyMetaTag('og:image', imageUrl);
  webify.platform.setPropertyMetaTag('og:type', ogType.value);

  if (url != null) {
    webify.platform.setPropertyMetaTag('og:url', url);
  }
  if (siteName != null) {
    webify.platform.setPropertyMetaTag('og:site_name', siteName);
  }
  if (imageWidth != null) {
    webify.platform.setPropertyMetaTag('og:image:width', imageWidth);
  }
  if (imageHeight != null) {
    webify.platform.setPropertyMetaTag('og:image:height', imageHeight);
  }
  if (imageAlt != null) {
    webify.platform.setPropertyMetaTag('og:image:alt', imageAlt);
  }
  if (locale != null) {
    webify.platform.setPropertyMetaTag('og:locale', locale);
  }

  // Twitter / X
  webify.platform.setMetaTag('twitter:card', twitterCardType.value);
  webify.platform.setMetaTag('twitter:title', title);
  webify.platform.setMetaTag('twitter:description', description);
  webify.platform.setMetaTag('twitter:image', imageUrl);

  if (twitterSite != null) {
    webify.platform.setMetaTag('twitter:site', twitterSite);
  } else if (webify.config.twitterSite != null) {
    webify.platform.setMetaTag('twitter:site', webify.config.twitterSite!);
  }
  if (twitterCreator != null) {
    webify.platform.setMetaTag('twitter:creator', twitterCreator);
  }
  if (imageAlt != null) {
    webify.platform.setMetaTag('twitter:image:alt', imageAlt);
  }
}