Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add lens open graph standards #2948

Merged
merged 4 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions apps/prerender/src/components/Shared/Tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ const Tags: FC<TagsProps> = ({
<meta property="twitter:image:width" content="400" />
<meta property="twitter:image:height" content="400" />
<meta property="twitter:creator" content="lensterxyz" />
{/* Lenster OG */}
<meta property="lenster:card" content={cardType} />
<meta property="lenster:site" content="Lenster" />
<meta property="lenster:title" content={title} />
<meta property="lenster:description" content={description} />
<meta property="lenster:image" content={image} />
{/* Lens OG */}
<meta property="lens:card" content={cardType} />
<meta property="lens:site" content="Lenster" />
<meta property="lens:title" content={title} />
<meta property="lens:description" content={description} />
<meta property="lens:image" content={image} />
{publishedTime ? (
<meta property="article:published_time" content={publishedTime} />
) : null}
Expand Down
11 changes: 9 additions & 2 deletions packages/workers/oembed/src/helper/meta/getDescription.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import type { Document } from 'linkedom';

const getDescription = (document: Document): string | null => {
const og = document.querySelector('meta[property="og:description"]');
const lens =
document.querySelector('meta[name="lens:description"]') ||
document.querySelector('meta[property="lens:description"]');
const og =
document.querySelector('meta[name="og:description"]') ||
document.querySelector('meta[property="og:description"]');
const twitter =
document.querySelector('meta[name="twitter:description"]') ||
document.querySelector('meta[property="twitter:description"]');

if (og) {
if (lens) {
return lens.getAttribute('content');
} else if (og) {
return og.getAttribute('content');
} else if (twitter) {
return twitter.getAttribute('content');
Expand Down
9 changes: 8 additions & 1 deletion packages/workers/oembed/src/helper/meta/getEmbedUrl.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import type { Document } from 'linkedom';

const getEmbedUrl = (document: Document): string | null => {
const lens =
document.querySelector('meta[name="lens:player"]') ||
document.querySelector('meta[property="lens:player"]');
const og =
document.querySelector('meta[name="og:video:url"]') ||
document.querySelector('meta[name="og:video:secure_url"]') ||
document.querySelector('meta[property="og:video:url"]') ||
document.querySelector('meta[property="og:video:secure_url"]');
const twitter =
document.querySelector('meta[name="twitter:player"]') ||
document.querySelector('meta[property="twitter:player"]');

if (og) {
if (lens) {
return lens.getAttribute('content');
} else if (og) {
return og.getAttribute('content');
} else if (twitter) {
return twitter.getAttribute('content');
Expand Down
11 changes: 9 additions & 2 deletions packages/workers/oembed/src/helper/meta/getImage.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import type { Document } from 'linkedom';

const getImage = (document: Document): string | null => {
const og = document.querySelector('meta[property="og:image"]');
const lens =
document.querySelector('meta[name="lens:image"]') ||
document.querySelector('meta[property="lens:image"]');
const og =
document.querySelector('meta[name="og:image"]') ||
document.querySelector('meta[property="og:image"]');
const twitter =
document.querySelector('meta[name="twitter:image"]') ||
document.querySelector('meta[name="twitter:image:src"]') ||
document.querySelector('meta[property="twitter:image"]') ||
document.querySelector('meta[property="twitter:image:src"]');

if (og) {
if (lens) {
return lens.getAttribute('content');
} else if (og) {
return og.getAttribute('content');
} else if (twitter) {
return twitter.getAttribute('content');
Expand Down
8 changes: 7 additions & 1 deletion packages/workers/oembed/src/helper/meta/getIsLarge.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import type { Document } from 'linkedom';

const getIsLarge = (document: Document): boolean | null => {
const lens =
document.querySelector('meta[name="lens:card"]') ||
document.querySelector('meta[property="lens:card"]');
const twitter =
document.querySelector('meta[name="twitter:card"]') ||
document.querySelector('meta[property="twitter:card"]');

const largeTypes = ['summary_large_image', 'player'];

if (twitter) {
if (lens) {
const card = lens.getAttribute('content') || '';
return largeTypes.includes(card);
} else if (twitter) {
const card = twitter.getAttribute('content') || '';
return largeTypes.includes(card);
}
Expand Down
11 changes: 9 additions & 2 deletions packages/workers/oembed/src/helper/meta/getSite.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import type { Document } from 'linkedom';

const getSite = (document: Document): string | null => {
const og = document.querySelector('meta[property="og:site_name"]');
const lens =
document.querySelector('meta[name="lens:site"]') ||
document.querySelector('meta[property="lens:site"]');
const og =
document.querySelector('meta[name="og:site_name"]') ||
document.querySelector('meta[property="og:site_name"]');
const twitter =
document.querySelector('meta[name="twitter:site"]') ||
document.querySelector('meta[property="twitter:site"]');

if (og) {
if (lens) {
return lens.getAttribute('content');
} else if (og) {
return og.getAttribute('content');
} else if (twitter) {
return twitter.getAttribute('content');
Expand Down
11 changes: 9 additions & 2 deletions packages/workers/oembed/src/helper/meta/getTitle.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import type { Document } from 'linkedom';

const getTitle = (document: Document): string | null => {
const og = document.querySelector('meta[property="og:title"]');
const lens =
document.querySelector('meta[name="lens:title"]') ||
document.querySelector('meta[property="lens:title"]');
const og =
document.querySelector('meta[name="og:title"]') ||
document.querySelector('meta[property="og:title"]');
const twitter =
document.querySelector('meta[name="twitter:title"]') ||
document.querySelector('meta[property="twitter:title"]');

if (og) {
if (lens) {
return lens.getAttribute('content');
} else if (og) {
return og.getAttribute('content');
} else if (twitter) {
return twitter.getAttribute('content');
Expand Down