@djangocfg/nextjs 1.0.1 → 1.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djangocfg/nextjs",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Next.js utilities and components: sitemap, health, OG images, legal pages, error pages",
5
5
  "keywords": [
6
6
  "nextjs",
@@ -109,14 +109,14 @@
109
109
  "next": "^15.4.4",
110
110
  "react": "^19.1.0",
111
111
  "react-dom": "^19.1.0",
112
- "@djangocfg/ui": "^1.4.31",
113
- "@djangocfg/layouts": "^2.0.1",
114
- "@djangocfg/api": "^1.4.31",
112
+ "@djangocfg/ui": "^1.4.32",
113
+ "@djangocfg/layouts": "^2.0.2",
114
+ "@djangocfg/api": "^1.4.32",
115
115
  "lucide-react": "^0.469.0"
116
116
  },
117
117
  "devDependencies": {
118
- "@djangocfg/typescript-config": "^1.4.31",
119
- "@djangocfg/layouts": "^2.0.1",
118
+ "@djangocfg/typescript-config": "^1.4.32",
119
+ "@djangocfg/layouts": "^2.0.2",
120
120
  "@types/node": "^24.7.2",
121
121
  "@types/react": "19.2.2",
122
122
  "@types/react-dom": "19.2.1",
@@ -199,6 +199,10 @@ export function createBaseNextConfig(
199
199
  buildDependencies: {},
200
200
  };
201
201
 
202
+ // Note: Dynamic API routes should use `export const dynamic = 'force-dynamic'`
203
+ // in the route file itself to exclude them from static export.
204
+ // This is simpler than using webpack plugins.
205
+
202
206
  // Compression plugins (only for static build in production)
203
207
  // Note: compression-webpack-plugin should be installed in the consuming project
204
208
  if (!isServer && isStaticBuild && !dev) {
@@ -252,6 +256,7 @@ export function createBaseNextConfig(
252
256
  // Cleanup: Remove our custom options that are not part of NextConfig
253
257
  // These are internal to BaseNextConfigOptions and should not be in the final config
254
258
  delete (finalConfig as any).basePath;
259
+ delete (finalConfig as any).staticBuildPath;
255
260
  delete (finalConfig as any).optimizePackageImports;
256
261
  // Note: We don't delete transpilePackages, experimental, env, webpack
257
262
  // as they are valid NextConfig keys and may have been overridden by user
@@ -105,7 +105,9 @@ export function createOgImageHandler(config: OgImageHandlerConfig) {
105
105
  let description = defaultProps.description || subtitle;
106
106
 
107
107
  // Support base64 data parameter (priority: base64 > query params > defaults)
108
+ // All template props can be encoded in base64, including styling params
108
109
  const dataParam = searchParams.get('data');
110
+ let decodedParams: Record<string, any> = {};
109
111
 
110
112
  if (dataParam) {
111
113
  try {
@@ -115,17 +117,17 @@ export function createOgImageHandler(config: OgImageHandlerConfig) {
115
117
  paramsObj[key] = value;
116
118
  }
117
119
  }
118
- const decodedData = parseOgImageData(paramsObj);
120
+ decodedParams = parseOgImageData(paramsObj);
119
121
 
120
122
  // Base64 data takes precedence - apply all decoded values
121
- if (decodedData.title && typeof decodedData.title === 'string' && decodedData.title.trim() !== '') {
122
- title = decodedData.title.trim();
123
+ if (decodedParams.title && typeof decodedParams.title === 'string' && decodedParams.title.trim() !== '') {
124
+ title = decodedParams.title.trim();
123
125
  }
124
- if (decodedData.subtitle && typeof decodedData.subtitle === 'string' && decodedData.subtitle.trim() !== '') {
125
- subtitle = decodedData.subtitle.trim();
126
+ if (decodedParams.subtitle && typeof decodedParams.subtitle === 'string' && decodedParams.subtitle.trim() !== '') {
127
+ subtitle = decodedParams.subtitle.trim();
126
128
  }
127
- if (decodedData.description && typeof decodedData.description === 'string' && decodedData.description.trim() !== '') {
128
- description = decodedData.description.trim();
129
+ if (decodedParams.description && typeof decodedParams.description === 'string' && decodedParams.description.trim() !== '') {
130
+ description = decodedParams.description.trim();
129
131
  }
130
132
  } catch (error) {
131
133
  // Silently fall back to defaults
@@ -158,12 +160,56 @@ export function createOgImageHandler(config: OgImageHandlerConfig) {
158
160
  fonts = await loadGoogleFonts(fontConfig);
159
161
  }
160
162
 
161
- // Merge props
163
+ // Helper function to parse numeric/boolean values from decoded params
164
+ const parseValue = (value: any, type: 'number' | 'boolean' | 'string' = 'string'): any => {
165
+ if (value === undefined || value === null || value === '') {
166
+ return undefined;
167
+ }
168
+ if (type === 'number') {
169
+ const num = Number(value);
170
+ return isNaN(num) ? undefined : num;
171
+ }
172
+ if (type === 'boolean') {
173
+ if (typeof value === 'boolean') return value;
174
+ if (typeof value === 'string') {
175
+ return value.toLowerCase() === 'true' || value === '1';
176
+ }
177
+ return Boolean(value);
178
+ }
179
+ return String(value);
180
+ };
181
+
182
+ // Merge props: decoded params from URL override defaultProps
162
183
  const templateProps: OgImageTemplateProps = {
163
184
  ...defaultProps,
185
+ // Content
164
186
  title,
165
187
  subtitle,
166
188
  description,
189
+ // Override with decoded params if present
190
+ siteName: decodedParams.siteName || defaultProps.siteName,
191
+ logo: decodedParams.logo || defaultProps.logo,
192
+ // Background
193
+ backgroundType: (decodedParams.backgroundType as 'gradient' | 'solid') || defaultProps.backgroundType,
194
+ gradientStart: decodedParams.gradientStart || defaultProps.gradientStart,
195
+ gradientEnd: decodedParams.gradientEnd || defaultProps.gradientEnd,
196
+ backgroundColor: decodedParams.backgroundColor || defaultProps.backgroundColor,
197
+ // Typography - Title
198
+ titleSize: parseValue(decodedParams.titleSize, 'number') ?? defaultProps.titleSize,
199
+ titleWeight: parseValue(decodedParams.titleWeight, 'number') ?? defaultProps.titleWeight,
200
+ titleColor: decodedParams.titleColor || defaultProps.titleColor,
201
+ // Typography - Description
202
+ descriptionSize: parseValue(decodedParams.descriptionSize, 'number') ?? defaultProps.descriptionSize,
203
+ descriptionColor: decodedParams.descriptionColor || defaultProps.descriptionColor,
204
+ // Typography - Site Name
205
+ siteNameSize: parseValue(decodedParams.siteNameSize, 'number') ?? defaultProps.siteNameSize,
206
+ siteNameColor: decodedParams.siteNameColor || defaultProps.siteNameColor,
207
+ // Layout
208
+ padding: parseValue(decodedParams.padding, 'number') ?? defaultProps.padding,
209
+ logoSize: parseValue(decodedParams.logoSize, 'number') ?? defaultProps.logoSize,
210
+ // Visibility flags
211
+ showLogo: parseValue(decodedParams.showLogo, 'boolean') ?? defaultProps.showLogo,
212
+ showSiteName: parseValue(decodedParams.showSiteName, 'boolean') ?? defaultProps.showSiteName,
167
213
  };
168
214
 
169
215
 
@@ -221,7 +267,7 @@ export function createOgImageDynamicRoute(config: OgImageHandlerConfig) {
221
267
  const handler = createOgImageHandler(config);
222
268
  const isStaticBuild = typeof process !== 'undefined' && process.env.NEXT_PUBLIC_STATIC_BUILD === 'true';
223
269
 
224
- return async function GET(
270
+ async function GET(
225
271
  request: NextRequest,
226
272
  context: { params: Promise<{ data: string }> }
227
273
  ) {
@@ -249,5 +295,16 @@ export function createOgImageDynamicRoute(config: OgImageHandlerConfig) {
249
295
  });
250
296
 
251
297
  return handler.GET(modifiedRequest);
298
+ }
299
+
300
+ // For static export, provide generateStaticParams that returns empty array
301
+ // This allows the route to be excluded from static build
302
+ async function generateStaticParams(): Promise<Array<{ data: string }>> {
303
+ return [];
304
+ }
305
+
306
+ return {
307
+ GET,
308
+ generateStaticParams,
252
309
  };
253
310
  }
@@ -108,7 +108,7 @@ export function generateOgImageMetadata(
108
108
  options: OgImageMetadataOptions = {}
109
109
  ): Metadata {
110
110
  const {
111
- ogImageBaseUrl = '/api/og',
111
+ ogImageBaseUrl = 'https://djangocfg.com/api/og',
112
112
  siteUrl: providedSiteUrl,
113
113
  defaultParams = {},
114
114
  useBase64 = true,
@@ -45,6 +45,7 @@ function decodeBase64(str: string): string {
45
45
 
46
46
  /**
47
47
  * OG Image URL parameters
48
+ * All parameters can be encoded in URL via base64
48
49
  */
49
50
  export interface OgImageUrlParams {
50
51
  /** Page title */
@@ -55,6 +56,36 @@ export interface OgImageUrlParams {
55
56
  siteName?: string;
56
57
  /** Logo URL (optional) */
57
58
  logo?: string;
59
+ /** Background type: 'gradient' or 'solid' */
60
+ backgroundType?: 'gradient' | 'solid';
61
+ /** Gradient start color (hex) */
62
+ gradientStart?: string;
63
+ /** Gradient end color (hex) */
64
+ gradientEnd?: string;
65
+ /** Background color (for solid type) */
66
+ backgroundColor?: string;
67
+ /** Title font size (px) */
68
+ titleSize?: number;
69
+ /** Title font weight */
70
+ titleWeight?: number;
71
+ /** Title text color */
72
+ titleColor?: string;
73
+ /** Description font size (px) */
74
+ descriptionSize?: number;
75
+ /** Description text color */
76
+ descriptionColor?: string;
77
+ /** Site name font size (px) */
78
+ siteNameSize?: number;
79
+ /** Site name text color */
80
+ siteNameColor?: string;
81
+ /** Padding (px) */
82
+ padding?: number;
83
+ /** Logo size (px) */
84
+ logoSize?: number;
85
+ /** Show logo flag */
86
+ showLogo?: boolean;
87
+ /** Show site name flag */
88
+ showSiteName?: boolean;
58
89
  /** Additional custom parameters */
59
90
  [key: string]: string | number | boolean | undefined;
60
91
  }
@@ -69,12 +100,26 @@ export interface OgImageUrlParams {
69
100
  *
70
101
  * @example
71
102
  * ```typescript
72
- * // Base64 encoding (safe, default)
103
+ * // Base64 encoding (safe, default) - all parameters can be encoded
73
104
  * const url = generateOgImageUrl('/api/og', {
74
105
  * title: 'My Page Title',
75
106
  * description: 'Page description here',
107
+ * siteName: 'My Site',
108
+ * logo: '/logo.svg',
109
+ * backgroundType: 'gradient',
110
+ * gradientStart: '#0f172a',
111
+ * gradientEnd: '#334155',
112
+ * titleSize: 80,
113
+ * titleWeight: 800,
114
+ * titleColor: 'white',
115
+ * descriptionSize: 36,
116
+ * descriptionColor: 'rgba(226, 232, 240, 0.9)',
117
+ * siteNameSize: 32,
118
+ * siteNameColor: 'rgba(255, 255, 255, 0.95)',
119
+ * padding: 80,
120
+ * logoSize: 56,
76
121
  * });
77
- * // Result: /api/og?data=eyJ0aXRsZSI6Ik15IFBhZ2UgVGl0bGUiLCJkZXNjcmlwdGlvbiI6IlBhZ2UgZGVzY3JpcHRpb24gaGVyZSJ9
122
+ * // Result: /api/og/[base64-encoded-json]
78
123
  *
79
124
  * // Query params (legacy)
80
125
  * const url = generateOgImageUrl('/api/og', { title: 'Hello' }, false);