Skip to content

About

A package providing tooling and library to deal with programmatic seo needs on SPA applications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

programmatic-seo

Framework-agnostic programmatic SEO engine for SPAs and component frameworks.

  • Declarative page spec (ISeoPage) with an atomic emit() commit
  • Chainable builder API (L1 SeoPageBuilder, L2 ContentPageBuilder) with URL hygiene guard
  • Managed JSON-LD @graph — stable @ids, idempotent node upserts by canonical path
  • Meta / canonical / Open Graph / Twitter Card rendering into the document head
  • Zero framework dependencies — the only runtime dependency is schema-dts

Install

bun add programmatic-seo-sdk

ESM-only, TypeScript declarations included, Node 22+.

Quickstart

import {SeoService} from "programmatic-seo-sdk";

const seo = new SeoService();

seo.initialize({
    rootUrl: "https://example.com",
    siteTitle: "Example",
    logger: console,
});

seo.siteWide
    .setBreadcrumb([{name: "Home", url: "/"}])
    .setLogo({url: "https://example.com/logo.png", width: 300, height: 68})
    .setOrganization({name: "Example Inc.", url: "https://example.com"})
    .setWebApplication({name: "Example App", description: "What the app does."});

seo.prepareToNavigate();

seo.page()
    .setTitle("My Article")
    .setDescription("What the article is about.")
    .setUrl("/articles/my-article")
    .contentPage()
    .setDates({published: "2026-01-15", modified: "2026-02-01"})
    .setKeywords("example", "seo")
    .emit();

seo.setUrl("https://example.com/articles/my-article");

The lifecycle: initialize() once at startup → configure site-wide nodes on the siteWide builder → per navigation call prepareToNavigate(), then commit the page's spec via emit(spec) or a page() / contentPage() builder chain → on navigation end, sync the URL with setUrl(window.location.href).

The full public surface — emit() merge semantics, spec field tables, builder chains, URL hygiene guard, date normalization, config parsing — is documented in docs/API.md.

Framework integration

ISeoPage is pure data with zero framework types, so the service drops into any host. The package ships no adapters; wiring stays consumer-side.

Aurelia

The proven pattern (as consumed by BillGrokker): a DI token, a logger bridge, an initialization AppTask, and a navigation-event handler.

import {DI} from "aurelia";
import {SeoService} from "programmatic-seo-sdk";

export const ISeoService = DI.createInterface<ISeoService>(
    "ISeoService",
    x => x.singleton(SeoService),
);
export type ISeoService = SeoService;

Register and initialize in an AppTask, bridging Aurelia's ILogger over the package's SeoLogger interface:

import {AppTask, ILogger} from "aurelia";
import {ISeoService} from "./seo-service.di";
import type {SeoLogger} from "programmatic-seo-sdk";
import {HomeBreadcrumbItem} from "./constants/breadcrumbs";

export const initializeSeo: IRegistry = {
    register(container: IContainer): IContainer {
        const seoLogger: SeoLogger = container.get(ILogger).scopeTo("SeoService");
        return container.register(AppTask.activated(ISeoService, seoSvc => {
            seoSvc.initialize({rootUrl: ROOT_URL, logger: seoLogger});
            seoSvc.siteWide.setBreadcrumb([HomeBreadcrumbItem]);
            seoSvc.siteWide.setLogo({url: `${ROOT_URL}/logo.png`, width: 300, height: 68});
            seoSvc.siteWide.setOrganization({name: "Example", url: ROOT_URL});
        }));
    },
};

Sync navigation: au:router:navigation-start → prepareToNavigate(); au:router:navigation-end → setUrl(window.location.href):

import {resolve} from "aurelia";
import {IRouterEvents} from "@aurelia/router";
import {ISeoService} from "./seo-service.di";

events.subscribe("au:router:navigation-start", () => seo.prepareToNavigate());
events.subscribe("au:router:navigation-end", () => {
    seo.setUrl(window.location.href);
});

Page components then emit in attached():

public attached(): void {
    this._seo.page().setTitle(title).setDescription(desc).setUrl(path).emit();
}

React

import {useEffect, useMemo} from "react";
import type {ISeoPage} from "programmatic-seo-sdk";

function useSeo(spec: ISeoPage) {
    useEffect(() => {
        seo.emit(spec);
    }, [spec]);
}

function Article({post}: {post: Post}) {
    const spec = useMemo<ISeoPage>(() => ({
        title: post.title,
        description: post.excerpt,
        url: `/posts/${post.slug}`,
        ogType: "article",
        article: {
            canonicalPath: `/posts/${post.slug}`,
            description: post.excerpt,
            datePublished: post.publishedAt,
            dateModified: post.modifiedAt,
        },
    }), [post]);
    useSeo(spec);
    return <article>…</article>;
}

Vue

import {watch} from "vue";
import type {ISeoPage} from "programmatic-seo-sdk";

export function useSeo(spec: Ref<ISeoPage>) {
    watch(spec, v => seo.emit(v), {deep: true});
}

Next.js

The spec is plain serializable data, so a client <SeoHead> component calls emit() on mount, or a server-side renderer can pass the same ISeoPage shape down:

"use client";
import {useEffect} from "react";
import type {ISeoPage} from "programmatic-seo-sdk";

export function SeoHead({spec}: {spec: ISeoPage}) {
    useEffect(() => {
        seo.emit(spec);
    }, [spec]);
    return null;
}

Logger bridging

The package never logs through a framework; it calls the SeoLogger seam supplied via the config logger field. Bridge your framework logger over it:

import type {SeoLogger} from "programmatic-seo-sdk";

const seoLogger: SeoLogger = {
    debug: (msg, ...args) => frameworkLogger.debug(msg, args),
    info: (msg, ...args) => frameworkLogger.info(msg, args),
    warn: (msg, ...args) => frameworkLogger.warn(msg, args),
    error: (msg, ...args) => frameworkLogger.error(msg, args),
};

seo.initialize({rootUrl: "https://example.com", logger: seoLogger});

Without a logger, the service stays silent (no-op defaults). Aurelia users: see the ILogger.scopeTo("SeoService") bridge above.

Production baseline

The implementation iterates against production truth: committed fixtures of the SPA-rendered <head> per route, captured once from https://billgrokker.com (#3), with synthesis tests proving the public API reproduces them (#6).

  • Capture once: fixtures are committed artifacts; the git history is the baseline's history. Volatile runtime values (dates that default to "now") are normalized to the {{NOW}} token; every rule is documented in fixtures/baseline/NORMALIZATION.md.

  • Re-capture is manual and deliberate: a PR titled baseline: recapture with a justification in the body (production head change, new route, fixture drift). CI never auto-recaptures. The procedure:

    bun install && bunx playwright install chromium
    npm run capture-baseline

    This rewrites fixtures/baseline/*.json for all nine routes from https://billgrokker.com. Verify idempotence: run the command a second time and confirm git status shows no further diff outside {{NOW}} fields (see fixtures/baseline/NORMALIZATION.md). Commit the changed fixtures in a single baseline: recapture PR describing what changed in production and why.

  • Interpreting synthesis failures: a fixture mismatch means either the package output drifted from upstream behavior (a regression — fix the implementation) or production changed legitimately (a real-world change — re-capture via a reviewed PR). A failure is never silenced by editing the fixture inline with the change that broke it.

Baseline synthesis tests

test/baseline-synthesis.spec.ts reconstructs each of the nine fixture routes through the public API only — initialize → siteWide.set*(...) → emit() / page() chains → setUrl(href) — inside a fresh jsdom document seeded with the SPA's served static head, then compares the serialized head against the fixture after the shared normalization (scripts/normalize.ts, the single source of truth, shared with the capture harness).

Content inputs come from the fixtures' stored data blocks, never the network: bill-detail routes synthesize from the fixture's bill metadata block (title, dates, policyArea, breadcrumbs) plus the captured description meta, and the FAQ routes reuse the fixture's stored Question content. The doubled <title> values on router-titled routes (home, FAQ, not-found, account) and the /faq → /faq/index canonical are reproduced as-is: they are upstream behaviors (the SPA router's buildTitle composition and the router's /faq/index URL) — not bugs to fix here.

Granular failure interpretation:

  • Diff only inside {{NOW}} fields → a normalization bug. Fix the normalization module or the test harness; never the fixture.
  • Diff in JSON-LD shape, @id values, key order, meta set, canonical, or title → a package regression. Fix the package; the fixture is production truth.
  • Diff caused by an intentional behavior change → land a baseline: recapture PR first, then update the synthesis expectation. Do not weaken the comparison in the test.

Rendered output is byte-identical to the upstream implementation; this is the hard constraint inherited from the source project (stable @id ordering, key insertion order, @context/@graph shape).

Status

Pre-release: the engine is being extracted behavior-identically from Expert-Vision-Software/billgrokker (BillGrokker's SPA SEO service, hardened and extraction-prepared upstream).

  • Normative spec: #1
  • First publish: #9 — npm programmatic-seo-sdk (v0.2.0)

Extraction plan

Ticket Scope
#2 Package scaffold (manifest, toolchain, MIT license)
#3 Production baseline fixtures captured from billgrokker.com
#4 Core module migration (types, service, builders, dates, config parser)
#5 Golden-master unit suites migrated in-package
#6 Baseline synthesis tests (package output ≡ production)
#7 README, API reference, framework integration guidance
#8 CI: PR gate + tag-driven npm publish with provenance
#9 Publish v0.1.0

Downstream adoption

BillGrokker switches to this package under its own spec: Expert-Vision-Software/billgrokker#36 (baseline parity gate → integration → import swap → parity verification → docs).

License

MIT

About

A package providing tooling and library to deal with programmatic seo needs on SPA applications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages