@djangocfg/nextjs 2.1.225 → 2.1.227

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @djangocfg/nextjs
2
2
 
3
- > Server-side Next.js utilities: sitemap generation, health checks, OG images, navigation, and config
3
+ > Server-side Next.js utilities: OG images, sitemap, health checks, i18n, PWA, navigation, and config
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@djangocfg/nextjs.svg)](https://www.npmjs.com/package/@djangocfg/nextjs)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
@@ -11,22 +11,20 @@
11
11
 
12
12
  ## Overview
13
13
 
14
- `@djangocfg/nextjs` provides server-side utilities for Next.js applications. This package focuses on server-only functionality: SEO optimization with sitemaps, health monitoring, dynamic OG images, navigation utilities, and configuration management.
14
+ `@djangocfg/nextjs` provides server-side utilities for Next.js applications built on top of Django-CFG.
15
15
 
16
- > **Note:** Client components (legal pages, error pages, redirect components) have been moved to `@djangocfg/layouts` to keep this package server-only.
16
+ > **Note:** Client components (legal pages, error pages, redirect components) are in `@djangocfg/layouts`.
17
17
 
18
18
  ## Features
19
19
 
20
- - **i18n (Internationalization)** - Full next-intl integration with routing, middleware, and components
21
- - **Dev Server with Browser Auto-Open** - Cross-platform CLI that works with Turbopack and webpack
22
- - **Zero-Config PWA** - Progressive Web App out of the box (service worker, offline support, manifest)
23
- - **Base Next.js Config** - Universal, reusable Next.js configuration factory for monorepos
24
- - **AI Documentation** - Search DjangoCFG docs via MCP server and CLI
25
- - **Sitemap Generation** - Dynamic XML sitemap with i18n hreflang support
26
- - **Health Checks** - Production-ready health monitoring endpoints
27
- - **OG Images** - Dynamic Open Graph image generation with templates
28
- - **Navigation Utilities** - Route definitions, menu generation, and navigation helpers
29
- - **TypeScript** - Full type safety throughout
20
+ - **OG Images** typed URL builder for Django's `django_ogimage` renderer (`@djangocfg/nextjs/og-image`)
21
+ - **i18n** full next-intl integration with routing, middleware, and components
22
+ - **PWA** — zero-config service worker and manifest
23
+ - **Base Next.js Config** reusable `createBaseNextConfig()` factory for monorepos
24
+ - **Sitemap** dynamic XML sitemap with i18n hreflang support
25
+ - **Health Checks** — production-ready health monitoring endpoints
26
+ - **Navigation** route definitions, menu generation, and active-state helpers
27
+ - **AI Documentation** search DjangoCFG docs via MCP server and CLI
30
28
 
31
29
  ## Installation
32
30
 
@@ -358,44 +356,21 @@ export const GET = createHealthHandler({
358
356
 
359
357
  ### OG Image Generation
360
358
 
361
- Generate dynamic Open Graph images with custom templates:
359
+ Builds typed URLs pointing to Django's `django_ogimage` renderer — no Edge Runtime, no `@vercel/og`:
362
360
 
363
361
  ```tsx
364
- // app/api/og/route.tsx
365
- import { createOgImageHandler } from '@djangocfg/nextjs/og-image';
366
- import { OgImageTemplate } from '@/components/OgImageTemplate';
367
-
368
- export const runtime = 'edge';
369
-
370
- const handler = createOgImageHandler({
371
- template: OgImageTemplate,
372
- defaultProps: {
373
- siteName: 'My App',
374
- logo: '/logo.svg',
375
- },
376
- fonts: [
377
- { family: 'Manrope', weight: 700 },
378
- { family: 'Manrope', weight: 500 },
379
- ],
380
- size: { width: 1200, height: 630 },
381
- });
362
+ // app/page.tsx
363
+ import { withOgImage } from '@djangocfg/nextjs/og-image'
382
364
 
383
- export async function GET(request: NextRequest) {
384
- return handler.GET(request);
365
+ export async function generateMetadata(): Promise<Metadata> {
366
+ return withOgImage(
367
+ { title: 'My Page', description: 'Description' },
368
+ { preset: 'DARK_BLUE', layout: 'HERO' }
369
+ )
385
370
  }
386
371
  ```
387
372
 
388
- Automatically add OG images to page metadata:
389
-
390
- ```tsx
391
- // app/page.tsx
392
- import { generateAppMetadata } from '@djangocfg/nextjs/og-image/utils';
393
-
394
- export const metadata = generateAppMetadata({
395
- title: 'My Page',
396
- description: 'Page description',
397
- });
398
- ```
373
+ The URL is resolved automatically from `NEXT_PUBLIC_MEDIA_URL` → `NEXT_PUBLIC_API_URL` → `NEXT_PUBLIC_SITE_URL`. Django renders and caches the PNG — no Edge Runtime or `@vercel/og` required.
399
374
 
400
375
  ### Navigation Utilities
401
376
 
@@ -445,9 +420,7 @@ import { RedirectPage } from '@djangocfg/layouts/components/RedirectPage';
445
420
  | `@djangocfg/nextjs/pwa/worker` | Service worker creation helpers |
446
421
  | `@djangocfg/nextjs/sitemap` | Sitemap generation with i18n hreflang support |
447
422
  | `@djangocfg/nextjs/health` | Health check handlers |
448
- | `@djangocfg/nextjs/og-image` | OG image generation |
449
- | `@djangocfg/nextjs/og-image/utils` | OG image URL and metadata utilities |
450
- | `@djangocfg/nextjs/og-image/components` | OG image template components |
423
+ | `@djangocfg/nextjs/og-image` | OG image URL builder for Django's `django_ogimage` renderer |
451
424
  | `@djangocfg/nextjs/navigation` | Route definitions, menu generation, navigation helpers |
452
425
 
453
426
  ## API Reference
@@ -609,54 +582,50 @@ createHealthHandler({
609
582
 
610
583
  ### OG Image
611
584
 
612
- #### `createOgImageHandler(config)`
585
+ `@djangocfg/nextjs/og-image` builds typed URLs pointing to Django's `django_ogimage` renderer.
586
+ No Edge Runtime, no `@vercel/og`, no JSX templates — Django renders and caches the PNG.
613
587
 
614
- Creates an OG image generation handler with custom template component.
588
+ See [`src/og-image/README.md`](./src/og-image/README.md) for full docs including URL resolution logic and deployment examples.
589
+
590
+ #### `withOgImage(metadata, params)`
591
+
592
+ Merges OG image into an existing `Metadata` object. Auto-extracts `title` if not in params.
615
593
 
616
594
  ```tsx
617
- createOgImageHandler({
618
- template: (props: OgImageTemplateProps) => ReactElement; // Template component
619
- defaultProps?: Partial<OgImageTemplateProps>; // Default props
620
- fonts?: Array<{ family: string; weight: number }>; // Google Fonts to load
621
- size?: { width: number; height: number }; // Image dimensions
622
- debug?: boolean; // Enable debug mode
623
- })
595
+ import { withOgImage } from '@djangocfg/nextjs/og-image'
596
+
597
+ export async function generateMetadata(): Promise<Metadata> {
598
+ return withOgImage(
599
+ { title: 'My Page', description: 'Description' },
600
+ { preset: 'DARK_BLUE', layout: 'HERO' }
601
+ )
602
+ }
624
603
  ```
625
604
 
626
- #### `generateAppMetadata(metadata, params?, options?)`
605
+ #### `createOgMetadata(params)`
627
606
 
628
- Automatically adds OG image to Next.js metadata.
607
+ Returns a `Metadata` fragment with `openGraph.images` + `twitter.images`.
629
608
 
630
609
  ```tsx
631
- generateAppMetadata(
632
- metadata: Metadata, // Base metadata
633
- ogImageParams?: Partial<OgImageUrlParams>, // Optional explicit params
634
- options?: {
635
- ogImageBaseUrl?: string; // Default: '/api/og'
636
- siteUrl?: string; // Auto-detected if not provided
637
- defaultParams?: Partial<OgImageUrlParams>; // Default params
638
- useBase64?: boolean; // Default: true
639
- }
640
- )
641
- ```
610
+ import { createOgMetadata } from '@djangocfg/nextjs/og-image'
642
611
 
643
- #### `generateOgImageUrl(baseUrl, params, useBase64?)`
612
+ export async function generateMetadata() {
613
+ return createOgMetadata({ title: 'Page', preset: 'DARK_BLUE' })
614
+ }
615
+ ```
644
616
 
645
- > **Note:** This utility has been moved to `@djangocfg/layouts/utils/og-image` for client-side usage.
617
+ #### `buildOgUrl(params)`
646
618
 
647
- For server-side usage, you can still use it from `@djangocfg/nextjs/og-image/utils`, but for client components, import from layouts:
619
+ Returns the raw URL string. Useful when you need the URL outside of metadata.
648
620
 
649
621
  ```tsx
650
- // Client component
651
- import { generateOgImageUrl } from '@djangocfg/layouts/utils/og-image';
622
+ import { buildOgUrl } from '@djangocfg/nextjs/og-image'
652
623
 
653
- const url = generateOgImageUrl('/api/og', {
654
- title: 'My Page',
655
- description: 'Page description',
656
- siteName: 'My Site',
657
- });
624
+ const url = buildOgUrl({ title: 'Hello', preset: 'DARK_BLUE' })
658
625
  ```
659
626
 
627
+ **URL resolution** (`NEXT_PUBLIC_MEDIA_URL` → `NEXT_PUBLIC_API_URL` → `NEXT_PUBLIC_SITE_URL` → relative).
628
+
660
629
  ### Navigation
661
630
 
662
631
  #### `defineRoute(path, metadata, config?)`
@@ -14,7 +14,7 @@ var require_package = __commonJS({
14
14
  "package.json"(exports, module) {
15
15
  module.exports = {
16
16
  name: "@djangocfg/nextjs",
17
- version: "2.1.225",
17
+ version: "2.1.227",
18
18
  description: "Next.js server utilities: sitemap, health, OG images, contact forms, navigation, config",
19
19
  keywords: [
20
20
  "nextjs",
@@ -58,21 +58,6 @@ var require_package = __commonJS({
58
58
  import: "./dist/health/index.mjs",
59
59
  default: "./dist/health/index.mjs"
60
60
  },
61
- "./og-image": {
62
- types: "./dist/og-image/index.d.mts",
63
- import: "./dist/og-image/index.mjs",
64
- default: "./dist/og-image/index.mjs"
65
- },
66
- "./og-image/utils": {
67
- types: "./dist/og-image/utils/index.d.mts",
68
- import: "./dist/og-image/utils/index.mjs",
69
- default: "./dist/og-image/utils/index.mjs"
70
- },
71
- "./og-image/components": {
72
- types: "./dist/og-image/components/index.d.mts",
73
- import: "./dist/og-image/components/index.mjs",
74
- default: "./dist/og-image/components/index.mjs"
75
- },
76
61
  "./navigation": {
77
62
  types: "./dist/navigation/index.d.mts",
78
63
  import: "./dist/navigation/index.mjs",
@@ -103,6 +88,11 @@ var require_package = __commonJS({
103
88
  import: "./dist/pwa/worker/index.mjs",
104
89
  default: "./dist/pwa/worker/index.mjs"
105
90
  },
91
+ "./og-image": {
92
+ types: "./dist/og-image/index.d.mts",
93
+ import: "./dist/og-image/index.mjs",
94
+ default: "./dist/og-image/index.mjs"
95
+ },
106
96
  "./monitor": {
107
97
  types: "./dist/monitor/index.d.mts",
108
98
  import: "./dist/monitor/index.mjs",
@@ -201,7 +191,6 @@ var require_package = __commonJS({
201
191
  "@types/react-dom": "^19.1.0",
202
192
  "@types/semver": "^7.7.1",
203
193
  "@types/webpack": "^5.28.5",
204
- "@vercel/og": "^0.8.5",
205
194
  eslint: "^9.37.0",
206
195
  "lucide-react": "^0.545.0",
207
196
  tsup: "^8.0.1",