Schema & Open Graph
aeo.js can generate JSON-LD structured data and Open Graph meta tags for your pages.
JSON-LD Schema
Section titled “JSON-LD Schema”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, andurlfields
Open Graph tags
Section titled “Open Graph tags”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" />Programmatic API
Section titled “Programmatic API”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 objectsconst schemas = generateSchemaObjects(resolvedConfig);
// Get a <script> tag stringconst script = generateJsonLdScript([ ...schemas.site, ...(schemas.pages[page.pathname] ?? []),]);
// Get OG meta tag objectsconst tags = generateOGTags(page, resolvedConfig);
// Get OG meta tags as HTML stringconst html = generateOGTagsHtml(page, resolvedConfig);