@arraypress/seo
v1.2.0
Published
HTML meta tag builder for SEO. Open Graph, Twitter Cards, canonical URLs, robots directives, hreflang, and site verification.
Maintainers
Readme
@arraypress/seo
HTML meta tag builder for SEO. Open Graph, Twitter Cards, canonical URLs, robots directives, hreflang, and site verification. Zero dependencies.
Installation
npm install @arraypress/seoUsage
import { buildHead, injectHead, robotsTxt } from '@arraypress/seo';
const head = buildHead({
title: 'My Page',
description: 'A great page',
url: 'https://example.com/page',
image: 'https://example.com/og.png',
siteName: 'Example',
twitterSite: '@example',
});
const html = injectHead('<html><head></head><body>...</body></html>', head);
const robots = robotsTxt({
sitemapUrl: 'https://example.com/sitemap.xml',
disallow: ['/admin'],
});API
buildHead(options?)
Build a complete <head> HTML string from options.
| Option | Type | Description |
|--------|------|-------------|
| title | string | Page title |
| description | string | Meta description |
| image | string | OG/Twitter image URL |
| imageWidth / imageHeight | number \| string | og:image:width / og:image:height (with image) |
| imageAlt | string | og:image:alt + twitter:image:alt fallback (with image) |
| url | string | Canonical URL (dropped automatically on noindex) |
| type | string | OG type (default: website) |
| robots | string \| false | Robots directive; Google snippet maxima merged in. false omits the tag |
| maxSnippet | boolean | Merge max-snippet/max-image-preview/max-video-preview (default true) |
| siteName | string | OG site name |
| twitterCard | string | Twitter card type (auto-detected from image) |
| twitterSite | string | Twitter @username for site |
| twitterCreator | string | Twitter @username for author |
| twitterFallback | boolean | Suppress twitter:title/description/image — Twitter falls back to OG (default true) |
| locale | string | OG locale |
| articlePublished | string | Article published date (ISO 8601) |
| articleModified | string | Article modified date (ISO 8601) |
| articleAuthor | string | Article author name |
| verification | object | Site verification codes (google, bing, pinterest, yandex) |
| hreflang | array | Alternate language links ({ lang, url }) |
| jsonLd | object | array | JSON-LD structured data to inject |
canonicalize(url)
Strip tracking params (utm_*, gclid, fbclid, msclkid, …) and the hash from a URL to derive a clean canonical — so ad-click and campaign variants don't fork into duplicate canonicals. Returns the input unchanged if it can't be parsed.
injectHead(html, headHtml)
Inject head HTML into an HTML document string. Replaces any existing <title> and inserts before </head>.
robotsTxt(options?)
Generate robots.txt content.
| Option | Type | Description |
|--------|------|-------------|
| sitemapUrl | string | Sitemap URL to include |
| allow | string[] | Allowed paths |
| disallow | string[] | Disallowed paths |
| crawlDelay | number | Crawl delay in seconds |
| customRules | string[] | Additional raw lines |
escapeHtml(str)
Escape HTML entities (&, ", <, >) in a string. Returns empty string for falsy input.
License
MIT
