Skip to content

Commit 903f575

Browse files
authored
Release v0.4.0
2 parents 9a0210d + 7ca9731 commit 903f575

23 files changed

Lines changed: 1612 additions & 32 deletions

.changeset/dull-mirrors-care.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@devsantara/head': minor
3+
---
4+
5+
feat: remove unnecessary exported types

.changeset/famous-candles-relax.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@devsantara/head': minor
3+
---
4+
5+
feat(meta): add http-equiv

.changeset/tender-eggs-go.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@devsantara/head': minor
3+
---
4+
5+
feat(schema-org): add SchemaOrgBuilder for type-safe structured data
6+
7+
Add SchemaOrgBuilder class for creating type-safe Schema.org structured data with JSON-LD output.
8+
9+
- Type-safe Schema.org entities with schema-dts integration
10+
- Entity relationship management with references
11+
- URL resolution with configurable base URLs
12+
- JSON-LD compilation for search engines

.oxfmtrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "./node_modules/oxfmt/configuration_schema.json",
3-
"ignorePatterns": ["pnpm-lock.yaml"],
3+
"ignorePatterns": ["pnpm-lock.yaml", "CHANGELOG.md"],
44
"printWidth": 80,
55
"tabWidth": 2,
66
"useTabs": false,

README.md

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Build SEO-friendly metadata with a fluent API, full TypeScript support, and fram
2323
- **Social Media** – Open Graph and Twitter Card meta tags for rich previews.
2424
- **Mobile Optimization** – Viewport configuration, color schemes, PWA icons.
2525
- **Advanced Tags** – Alternates, manifests, stylesheets, scripts, and custom meta tags.
26+
- **Structured Data** – Schema.org JSON-LD support for rich snippets, knowledge graphs, and enhanced SEO.
2627
- **Simplified URL Management** – Most metadata (Open Graph, canonical, alternates) requires absolute URLs. Set `metadataBase` once and use convenient relative paths everywhere.
2728
- **Continuously Expanding** – Actively adding more metadata types based on community feedback.
2829

@@ -326,6 +327,42 @@ export const Route = createRootRoute({
326327
]
327328
```
328329

330+
## 🌐 Schema.org Structured Data
331+
332+
Add rich structured data with [Schema.org](https://schema.org) JSON-LD support for enhanced search engine understanding and knowledge graphs.
333+
334+
### Quick Start
335+
336+
```typescript
337+
import { HeadBuilder } from '@devsantara/head';
338+
import { SchemaOrgBuilder } from '@devsantara/head/schema-org';
339+
import type { Organization } from 'schema-dts';
340+
341+
const schema = new SchemaOrgBuilder<Organization>().addEntity('org', {
342+
'@type': 'Organization',
343+
name: 'My Company',
344+
url: 'https://devsantara.com',
345+
});
346+
347+
const head = new HeadBuilder()
348+
.addTitle('Welcome')
349+
.addDescription('Visit our site')
350+
.addSchemaOrg(schema)
351+
.build();
352+
```
353+
354+
### Features
355+
356+
- **Type-Safe Entities** – Full TypeScript support with `schema-dts` package
357+
- **Multiple Entities** – Build complex entity graphs with relationships
358+
- **Entity References** – Link entities together with `@id` cross-references
359+
- **URL Resolution** – Automatically resolve relative URLs with metadata base
360+
- **JSON-LD Output** – Standards-compliant format ready for search engines
361+
362+
### Learn More
363+
364+
For comprehensive documentation, examples, and best practices, see the [Schema.org Module Documentation](./src/schema-org/README.md).
365+
329366
## 📚 API Reference
330367

331368
### Core Methods
@@ -350,20 +387,22 @@ For advanced use cases not covered by the essential methods below, use these bas
350387

351388
High-level convenience methods for common metadata patterns. These methods handle the complexity of creating properly structured head.
352389

353-
| Method | Description |
354-
| ---------------------------------------------------------------------- | ----------------------------------------------------------- |
355-
| `addDescription(description: string)` | Adds a meta description tag |
356-
| `addCanonical(valueOrFn: BuilderOption<string \| URL>)` | Adds a canonical URL link |
357-
| `addRobots(options: RobotsOptions)` | Adds robots meta tag for search engine directives |
358-
| `addCharSet(charset: CharSet)` | Adds character encoding declaration |
359-
| `addViewport(options: ViewportOptions)` | Adds viewport configuration for responsive design |
360-
| `addColorScheme(colorScheme: ColorScheme)` | Adds color scheme preference (light/dark mode) |
361-
| `addOpenGraph(valueOrFn: BuilderOption<OpenGraphOptions>)` | Adds Open Graph meta tags for social media previews |
362-
| `addTwitter(valueOrFn: BuilderOption<TwitterOptions>)` | Adds Twitter Card meta tags |
363-
| `addIcon(preset: IconPreset, valueOrFn: BuilderOption<IconOptions>)` | Adds favicon or app icons (favicon, apple-touch-icon, etc.) |
364-
| `addStylesheet(href: string \| URL, options?: StylesheetOptions)` | Adds an external stylesheet link |
365-
| `addManifest(valueOrFn: BuilderOption<string \| URL>)` | Adds a web app manifest link |
366-
| `addAlternateLocale(valueOrFn: BuilderOption<AlternateLocaleOptions>)` | Adds alternate language/locale links |
390+
| Method | Description |
391+
| ------------------------------------------------------------------------------ | ----------------------------------------------------------- |
392+
| `addDescription(description: string)` | Adds a meta description tag |
393+
| `addCanonical(valueOrFn: BuilderOption<string \| URL>)` | Adds a canonical URL link |
394+
| `addRobots(options: RobotsOptions)` | Adds robots meta tag for search engine directives |
395+
| `addCharSet(charset: CharSet)` | Adds character encoding declaration |
396+
| `addViewport(options: ViewportOptions)` | Adds viewport configuration for responsive design |
397+
| `addColorScheme(colorScheme: ColorScheme)` | Adds color scheme preference (light/dark mode) |
398+
| `addOpenGraph(valueOrFn: BuilderOption<OpenGraphOptions>)` | Adds Open Graph meta tags for social media previews |
399+
| `addTwitter(valueOrFn: BuilderOption<TwitterOptions>)` | Adds Twitter Card meta tags |
400+
| `addIcon(preset: IconPreset, valueOrFn: BuilderOption<IconOptions>)` | Adds favicon or app icons (favicon, apple-touch-icon, etc.) |
401+
| `addStylesheet(href: string \| URL, options?: StylesheetOptions)` | Adds an external stylesheet link |
402+
| `addManifest(valueOrFn: BuilderOption<string \| URL>)` | Adds a web app manifest link |
403+
| `addAlternateLocale(valueOrFn: BuilderOption<AlternateLocaleOptions>)` | Adds alternate language/locale links |
404+
| `addHttpEquiv(httpEquiv: HttpEquivKey, content: string)` | Adds a pragma directive using the `http-equiv` attribute |
405+
| `addSchemaOrg(valueOrFn: SchemaOrgBuilder \| BuilderOption<SchemaOrgBuilder>)` | Adds Schema.org structured data as JSON-LD |
367406

368407
> **💡 Tip:** Most methods support either direct values or callback functions that receive a helper object with `resolveUrl()` for dynamic URL resolution.
369408

package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
{
22
"name": "@devsantara/head",
33
"version": "0.3.0",
4-
"description": "A type-safe HTML head builder",
4+
"description": "A type-safe HTML head builder library for managing document head metadata with full TypeScript support",
55
"keywords": [
66
"devsantara",
7-
"head"
7+
"head",
8+
"json-ld",
9+
"meta",
10+
"metadata",
11+
"react",
12+
"schema.org",
13+
"seo",
14+
"typescript"
815
],
916
"homepage": "https://github.com/devsantara/head#readme",
1017
"bugs": {
@@ -27,6 +34,7 @@
2734
"types": "./dist/index.d.ts",
2835
"exports": {
2936
".": "./dist/index.js",
37+
"./schema-org": "./dist/schema-org/index.js",
3038
"./adapters": "./dist/adapters/index.js",
3139
"./package.json": "./package.json"
3240
},
@@ -56,6 +64,7 @@
5664
"oxfmt": "^0.27.0",
5765
"oxlint": "^1.42.0",
5866
"oxlint-tsgolint": "^0.11.4",
67+
"schema-dts": "^1.1.5",
5968
"tsdown": "^0.20.1",
6069
"typescript": "^5.9.3",
6170
"vitest": "^4.0.18"

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/adapters/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from './react-adapter';
2-
export * from './tanstack-router-adapter';
1+
export { HeadReactAdapter } from './react-adapter';
2+
export { HeadTanstackRouterAdapter } from './tanstack-router-adapter';

src/adapters/react-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createElement, type ReactNode } from 'react';
22
import type { HeadAdapter, HeadElement } from '../types';
33

4-
export type HeadReactAdapterResult = ReactNode[];
4+
type HeadReactAdapterResult = ReactNode[];
55

66
/**
77
* Adapter that transforms head elements into React components for rendering in React applications.

src/adapters/tanstack-router-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
} from '../types';
99
import { isElementOfType } from '../utils';
1010

11-
export interface HeadTanStackRouterAdapterResult {
11+
interface HeadTanStackRouterAdapterResult {
1212
links?: HeadLinkAttributes[];
1313
scripts?: HeadScriptAttributes[];
1414
meta?: HeadMetaAttributes[];

0 commit comments

Comments
 (0)