Skip to content

Schema & Open Graph

aeo.js can generate JSON-LD structured data and Open Graph meta tags for your pages.

Enable schema generation in your config:

{
schema: {
enabled: true,
organization: {
name: 'My Company',
url: 'https://mysite.com',
logo: 'https://mysite.com/logo.png',
sameAs: [
'https://twitter.com/mycompany',
'https://github.com/mycompany',
],
},
defaultType: 'WebPage', // or 'Article'
},
}

This generates <script type="application/ld+json"> blocks with:

  • Organization schema for your site
  • WebPage or Article schema for each page
  • Proper @context, @type, name, description, and url fields

Enable OG tag generation:

{
og: {
enabled: true,
image: 'https://mysite.com/og.png',
twitterHandle: '@mycompany',
type: 'website', // or 'article'
},
}

This generates meta tags like:

<meta property="og:title" content="Page Title" />
<meta property="og:description" content="Page description" />
<meta property="og:image" content="https://mysite.com/og.png" />
<meta property="og:url" content="https://mysite.com/page" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@mycompany" />

The lower-level helpers expect a resolved config and a page entry.

import {
generateJsonLdScript,
generateOGTags,
generateOGTagsHtml,
generateSchemaObjects,
resolveConfig,
} from 'aeo.js';
const page = {
pathname: '/page',
title: 'Page Title',
description: 'Page description',
content: 'Page content',
};
const resolvedConfig = resolveConfig({
title: 'My Company',
description: 'My company website',
url: 'https://mysite.com',
pages: [page],
});
// Get schema objects
const schemas = generateSchemaObjects(resolvedConfig);
// Get a <script> tag string
const script = generateJsonLdScript([
...schemas.site,
...(schemas.pages[page.pathname] ?? []),
]);
// Get OG meta tag objects
const tags = generateOGTags(page, resolvedConfig);
// Get OG meta tags as HTML string
const html = generateOGTagsHtml(page, resolvedConfig);