$ show garmeeh/next-seo
This repository is a Next.js SEO library that provides React components for generating JSON-LD structured data (Schema.org) to enhance search engine optimization. The library offers over 50 specialized components for various Schema.org types (Article, Recipe, Product, Event, etc.) and a core JsonLdScript component for rendering JSON-LD tags. It includes utility processors for normalizing flexible input data into Schema.org-compliant formats and emphasizes security through XSS prevention in JSON-LD stringification. The architecture follows a modular component pattern with strong TypeScript typing, comprehensive testing (unit and E2E), and support for both Pages Router and App Router in Next.js. The library is actively maintained with recent updates, a changeset-based versioning system, and extensive documentation.
The LLM identified 3 files worth highlighting for reuse:
The core component responsible for rendering JSON-LD script tags, featuring automatic CSP nonce support and secure handling of script tags to prevent XSS vulnerabilities. It is used by all Schema-specific components and demonstrates a reusable pattern for safe script tag injection in React applications.
A collection of utility functions that normalize flexible input data (strings, objects, arrays) into Schema.org compliant objects, automatically adding required @type properties and ensuring data consistency. This reduces boilerplate in components and provides a reusable pattern for handling diverse data formats in structured data generation.
A safe stringification utility that escapes harmful sequences (like </script>) in JSON-LD output to prevent XSS attacks when embedding structured data in HTML. This critical security feature is used by the JsonLdScript component and exemplifies a reusable pattern for secure JSON-LD serialization in web applications.