Open Graph для тех, кто не хочет думать

Никита Дубко, Веб-стандарты

Open Graph для тех, кто не хочет думать

Никита Дубко, Веб-стандарты

Кто я?

Веб-стандарты

Сделай мне красиво!

Create Your Own Automated Social Images With Resoc
Recycling Open Graph images for display on my web site
Respecting Users’ Motion Preferences

The
Open Graph
protocol

The Open Graph protocol
<head>
    <title>Fwdays: JS is back!</title>

    <meta property="og:title"
          content="Fwdays: JS is back!">
    <meta property="og:type"
          content="website">
    <meta property="og:url"
          content="https://fwdays.com/">
    <meta property="og:image"
          content="https://fwdays.com/og_image.jpg" />
</head>
        
<head>
    <title>Fwdays: JS is back!</title>

    <meta property="og:title"
          content="Fwdays: JS is back!">
    <meta property="og:type"
          content="website">
    <meta property="og:url"
          content="https://fwdays.com/">
    <meta property="og:image"
          content="https://fwdays.com/og_image.jpg" />
</head>
        

og:*

og:title

og:description

og:image

og:site_name

og:type

article

video.movie

Open Graph Types

og:image

<meta property="og:image"
      content="https://fwdays.com/ogp.jpg">
<meta property="og:image:secure_url"
      content="https://s.fwdays.com/ogp.jpg">
<meta property="og:image:type"
      content="image/jpeg">
<meta property="og:image:width"
      content="1200">
<meta property="og:image:height"
      content="630">
<meta property="og:image:alt"
      content="Happy people are smiling">

Массивы

<meta property="og:image"
      content="https://mefody.dev/og-s.jpg">
<meta property="og:image:width" content="300">
<meta property="og:image:height" content="300">

<meta property="og:image"
      content="https://mefody.dev/og-l.jpg">
<meta property="og:image:width" content="1000">
<meta property="og:image:height" content="1000">

og:locale

uk_UA, en_US

og:determiner

a, an, the, "", auto

Facebook

Руководство по публикации для веб-мастеров

fb:app_id

og:asset

3D asset URL

How to Specify 3D Assets for Link Sharing

> 200 x 200

Изображения в публикациях ссылок

< 8 МБ

HD: 1200 х 630

> 600 х 315

Twitter

Twitter Cards
<meta name="twitter:card"
      content="summary">

twitter:card

summary
summary_large_image
app
player

twitter:site

@fwdays

twitter:creator

@dark_mefody

Cards Markup
Tag Reference

Pinterest

<meta name="pinterest-rich-pin"
      content="false">
Pinterest Developers

og:availability

instock, preorder, backorder,
out of stock, discontinued

Crawlers 🕷

Twitter

Twitterbot/1.0

Facebook

facebookexternalhit/1.1

Краулер Facebook

Telegram

TelegramBot (like TwitterBot)

robots.txt

User-agent: Twitterbot
Disallow:
monperrus/crawler-user-agents

Как проверить?

Twitter Card validator
Facebook: отладчик репостов
LinkedIn Post Inspector
@webpagebot
metatags.io
OG Spy

Картинки кэшируются

По урлу

The Twitter web crawler re-indexes the Card tag information on your page roughly every seven days.

Прикручиваем og:image

A framework for building Open Graph images
Vercel
11ty/api-opengraph-image

Пишем велосипед
на электродвигателе

Puppeteer
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({
    width: 1200,
    height: 630,
    deviceScaleFactor: 1,
});
await page.goto(url);
const screenshotBuffer = await page.screenshot({
    fullPage: false,
    type: 'png',
});
await page.close();

Live Coding 💻

Больше кода!

Be lazy!

mefody.dev/talks/lazy-og/
@dark_mefody
n.a.dubko@gmail.com QR-код со ссылкой на доклад