Framework-agnostic tutorial

Add Mosaicora with npm

Build Open Graph image URLs and safe, typed JSON-LD render overrides in any Node.js or TypeScript application.

What you will build

A framework-independent integration that publishes a Mosaicora CDN image through standard social metadata and supplies exact image-render content through safely serialized JSON-LD.

Package: @mosaicora/plugin-mosaicora-core 1.0.0Runtime: Node.js 20+Language: TypeScript or JavaScriptLicense: MIT

Before you begin

  • A Node.js 20 or newer application that can publish server-rendered or statically generated HTML.
  • The public canonical URL for each integrated page.
  • Your public Mosaicora site ID.
  • Access to the template, document head, or SEO layer that emits meta and JSON-LD script tags.
1

Step 1

Install the core package

Add the framework-agnostic ESM package to your application.

Install from the project root. The package is side-effect free and includes TypeScript declarations.

Install with pnpm

pnpm add @mosaicora/plugin-mosaicora-core

Expected result

  • The dependency appears in package.json.
  • The runtime can import ESM package exports.
2

Step 2

Build the image URL

Turn the page’s canonical identity into a deterministic Mosaicora CDN address.

Call buildOgImageUrl on the server or during static generation. Pass the site ID and the same absolute canonical URL your page publishes.

The fallback URL gives the generator a stable page identity when your application supports alternate entry URLs.

Generate the CDN URL

import { buildOgImageUrl } from "@mosaicora/plugin-mosaicora-core";

const imageUrl = buildOgImageUrl({
  siteId: "321cac22d2103fb1660c50bd",
  canonicalHref:
    "https://example.com/products/view?sku=123&campaign=launch",
  fallbackHref: "https://example.com/products/view",
});

Expected result

  • imageUrl starts with https://cdn.mosaicora.io/s/.
  • The URL ends in .jpg before any query string.
3

Step 3

Publish the social metadata

Use the generated URL in standard Open Graph and X/Twitter tags.

Pass imageUrl into your framework, CMS, or template engine. Render these tags in the document head before returning the page to crawlers.

Framework-neutral HTML

<meta property="og:image" content="IMAGE_URL" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:image" content="IMAGE_URL" />
4

Step 4

Supply the image-render content

Build and safely serialize JSON-LD values for the Mosaicora generator.

Keep your existing Schema.org fields and add mosaicora:og semantic values for content the generator should render exactly. These overrides guide the Open Graph image; they do not replace normal page metadata.

serializeJsonLd removes undefined values and escapes less-than characters so the result can be embedded in an HTML JSON-LD script element.

Build and serialize the override

import {
  buildMosaicoraOgJsonLd,
  serializeJsonLd,
} from "@mosaicora/plugin-mosaicora-core";

const jsonLd = buildMosaicoraOgJsonLd({
  schemaType: "Product",
  name: "Example product",
  offers: {
    "@type": "Offer",
    price: "49",
    priceCurrency: "USD",
  },
  mosaicoraOg: {
    schemaVersion: 3,
    semanticValues: {
      "content.title": "Example product",
      "content.description": "A polished product preview.",
      "product.price": "$49",
      "product.features": ["Fast setup", "Consistent previews"],
    },
  },
});

const serialized = serializeJsonLd(jsonLd);

Embed with your template engine

Insert serialized as the text content of an application/ld+json script.

<script type="application/ld+json">
  SERIALIZED_JSON_LD
</script>
5

Step 5

Verify the published output

Check the server-rendered HTML, image URL, and JSON-LD together.

Publish the page at its canonical public URL, inspect the initial HTML response, and run the URL through the Open Graph Checker.

Confirm that the image metadata uses imageUrl and that the JSON-LD contains the same page identity and intended semantic render values.

Expected result

  • The initial HTML contains og:image and twitter:image.
  • The JSON-LD script parses without errors.
  • The checker recognizes the Mosaicora CDN image.

Reference

Advanced usage

Deterministic URL rules

The same canonical input always maps to the same normalized image location.

  • The root path becomes https://cdn.mosaicora.io/s/{siteId}.jpg.
  • Nested paths remain below /s/{siteId}.
  • Query parameters are preserved and sorted by key and value.
  • Hash fragments are ignored and UTF-8 paths remain readable.

Typed public contract

The package exports URL helpers, JSON-LD builders, and the complete v3 semantic contract.

  • MosaicoraOgOverride and MosaicoraOgSemanticValues
  • MosaicoraOgSemanticRole and role-specific value types
  • buildOgImageUrl and buildMosaicoraOgJsonLd
  • serializeJsonLd for safe HTML embedding

Help

Troubleshooting

The package cannot be imported

Confirm the application uses Node.js 20+ and supports ESM imports. Import from the package root rather than a private dist path.

The social crawler does not see the tags

Move metadata generation to the server or static build. Tags injected only after browser hydration are not reliable for social crawlers.

The JSON-LD script is quoted or malformed

Embed the output from serializeJsonLd once as script text. Do not run JSON.stringify on the serialized string a second time.

Build Better Open Graph Images

Join the waitlist and tell us what your publishing workflow needs.