@djangocfg/nextjs 2.1.5 → 2.1.7
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/dist/ai/cli.d.mts +1 -0
- package/dist/ai/cli.mjs +171 -0
- package/dist/ai/cli.mjs.map +1 -0
- package/dist/ai/index.d.mts +81 -0
- package/dist/ai/index.mjs +139 -0
- package/dist/ai/index.mjs.map +1 -0
- package/dist/config/index.d.mts +360 -0
- package/dist/config/index.mjs +1363 -0
- package/dist/config/index.mjs.map +1 -0
- package/dist/constants-HezbftFb.d.mts +10 -0
- package/dist/contact/index.d.mts +47 -0
- package/dist/contact/index.mjs +98 -0
- package/dist/contact/index.mjs.map +1 -0
- package/dist/contact/route.d.mts +35 -0
- package/dist/contact/route.mjs +99 -0
- package/dist/contact/route.mjs.map +1 -0
- package/dist/health/index.d.mts +43 -0
- package/dist/health/index.mjs +38 -0
- package/dist/health/index.mjs.map +1 -0
- package/dist/index.d.mts +19 -0
- package/dist/index.mjs +2565 -0
- package/dist/index.mjs.map +1 -0
- package/dist/navigation/index.d.mts +89 -0
- package/dist/navigation/index.mjs +63 -0
- package/dist/navigation/index.mjs.map +1 -0
- package/dist/og-image/components/index.d.mts +59 -0
- package/dist/og-image/components/index.mjs +325 -0
- package/dist/og-image/components/index.mjs.map +1 -0
- package/dist/og-image/index.d.mts +112 -0
- package/dist/og-image/index.mjs +823 -0
- package/dist/og-image/index.mjs.map +1 -0
- package/dist/og-image/utils/index.d.mts +302 -0
- package/dist/og-image/utils/index.mjs +317 -0
- package/dist/og-image/utils/index.mjs.map +1 -0
- package/dist/sitemap/index.d.mts +66 -0
- package/dist/sitemap/index.mjs +76 -0
- package/dist/sitemap/index.mjs.map +1 -0
- package/dist/types-CwhXnEbK.d.mts +30 -0
- package/package.json +7 -6
- package/src/config/createNextConfig.ts +31 -2
|
@@ -0,0 +1,823 @@
|
|
|
1
|
+
// src/og-image/route.tsx
|
|
2
|
+
import { ImageResponse } from "next/og";
|
|
3
|
+
import { NextRequest } from "next/server";
|
|
4
|
+
|
|
5
|
+
// src/og-image/utils/fonts.ts
|
|
6
|
+
async function loadGoogleFont(font, text, weight = 700) {
|
|
7
|
+
let url = `https://fonts.googleapis.com/css2?family=${font}:wght@${weight}`;
|
|
8
|
+
if (text) {
|
|
9
|
+
url += `&text=${encodeURIComponent(text)}`;
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
const css = await fetch(url, {
|
|
13
|
+
headers: {
|
|
14
|
+
// Required to get TTF format instead of WOFF2
|
|
15
|
+
"User-Agent": "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1"
|
|
16
|
+
}
|
|
17
|
+
}).then((res) => res.text());
|
|
18
|
+
const resource = css.match(/src: url\((.+)\) format\('(opentype|truetype)'\)/);
|
|
19
|
+
if (!resource || !resource[1]) {
|
|
20
|
+
throw new Error(`Failed to parse font URL from CSS for font: ${font}`);
|
|
21
|
+
}
|
|
22
|
+
const response = await fetch(resource[1]);
|
|
23
|
+
if (response.status !== 200) {
|
|
24
|
+
throw new Error(`Failed to fetch font data: HTTP ${response.status}`);
|
|
25
|
+
}
|
|
26
|
+
return await response.arrayBuffer();
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error(`Error loading Google Font "${font}":`, error);
|
|
29
|
+
throw new Error(`Failed to load font "${font}": ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function loadGoogleFonts(fonts) {
|
|
33
|
+
const fontConfigs = await Promise.all(
|
|
34
|
+
fonts.map(async ({ family, weight = 700, style = "normal", text }) => {
|
|
35
|
+
const data = await loadGoogleFont(family, text, weight);
|
|
36
|
+
return {
|
|
37
|
+
name: family,
|
|
38
|
+
weight,
|
|
39
|
+
style,
|
|
40
|
+
data
|
|
41
|
+
};
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
return fontConfigs;
|
|
45
|
+
}
|
|
46
|
+
function createFontLoader() {
|
|
47
|
+
const cache = /* @__PURE__ */ new Map();
|
|
48
|
+
return {
|
|
49
|
+
/**
|
|
50
|
+
* Load a font with caching
|
|
51
|
+
*/
|
|
52
|
+
async load(family, weight = 700, text) {
|
|
53
|
+
const cacheKey = `${family}-${weight}-${text || "all"}`;
|
|
54
|
+
if (!cache.has(cacheKey)) {
|
|
55
|
+
cache.set(cacheKey, loadGoogleFont(family, text, weight));
|
|
56
|
+
}
|
|
57
|
+
return cache.get(cacheKey);
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* Clear the cache
|
|
61
|
+
*/
|
|
62
|
+
clear() {
|
|
63
|
+
cache.clear();
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* Get cache size
|
|
67
|
+
*/
|
|
68
|
+
size() {
|
|
69
|
+
return cache.size;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/og-image/utils/url.ts
|
|
75
|
+
var DEFAULT_OG_IMAGE_BASE_URL = "https://djangocfg.com/api/og";
|
|
76
|
+
function encodeBase64(str) {
|
|
77
|
+
if (typeof Buffer !== "undefined") {
|
|
78
|
+
return Buffer.from(str, "utf-8").toString("base64");
|
|
79
|
+
}
|
|
80
|
+
return btoa(unescape(encodeURIComponent(str)));
|
|
81
|
+
}
|
|
82
|
+
function decodeBase64(str) {
|
|
83
|
+
if (typeof Buffer !== "undefined") {
|
|
84
|
+
return Buffer.from(str, "base64").toString("utf-8");
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const binaryString = atob(str);
|
|
88
|
+
return decodeURIComponent(
|
|
89
|
+
binaryString.split("").map((c) => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)).join("")
|
|
90
|
+
);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
return decodeURIComponent(escape(atob(str)));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function generateOgImageUrl(params, options = {}) {
|
|
96
|
+
const {
|
|
97
|
+
baseUrl = DEFAULT_OG_IMAGE_BASE_URL,
|
|
98
|
+
useBase64 = true
|
|
99
|
+
} = options;
|
|
100
|
+
if (useBase64) {
|
|
101
|
+
const cleanParams = {};
|
|
102
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
103
|
+
if (value !== void 0 && value !== null && value !== "") {
|
|
104
|
+
cleanParams[key] = value;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
const jsonString = JSON.stringify(cleanParams);
|
|
108
|
+
const base64Data = encodeBase64(jsonString);
|
|
109
|
+
return `${baseUrl}/${base64Data}`;
|
|
110
|
+
} else {
|
|
111
|
+
const searchParams = new URLSearchParams();
|
|
112
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
113
|
+
if (value !== void 0 && value !== null && value !== "") {
|
|
114
|
+
searchParams.append(key, String(value));
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
const query = searchParams.toString();
|
|
118
|
+
return query ? `${baseUrl}?${query}` : baseUrl;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function getAbsoluteOgImageUrl(relativePath, siteUrl) {
|
|
122
|
+
if (relativePath.startsWith("http://") || relativePath.startsWith("https://")) {
|
|
123
|
+
return relativePath;
|
|
124
|
+
}
|
|
125
|
+
const cleanSiteUrl = siteUrl.replace(/\/$/, "");
|
|
126
|
+
const cleanPath = relativePath.startsWith("/") ? relativePath : `/${relativePath}`;
|
|
127
|
+
return `${cleanSiteUrl}${cleanPath}`;
|
|
128
|
+
}
|
|
129
|
+
function createOgImageUrlBuilder(defaults = {}, options = {}) {
|
|
130
|
+
return (params) => {
|
|
131
|
+
return generateOgImageUrl(
|
|
132
|
+
{ ...defaults, ...params },
|
|
133
|
+
options
|
|
134
|
+
);
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function parseOgImageUrl(url) {
|
|
138
|
+
try {
|
|
139
|
+
const urlObj = new URL(url, "http://dummy.com");
|
|
140
|
+
const params = {};
|
|
141
|
+
urlObj.searchParams.forEach((value, key) => {
|
|
142
|
+
params[key] = value;
|
|
143
|
+
});
|
|
144
|
+
return params;
|
|
145
|
+
} catch {
|
|
146
|
+
return {};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function parseOgImageData(searchParams) {
|
|
150
|
+
try {
|
|
151
|
+
let params;
|
|
152
|
+
if (searchParams instanceof URLSearchParams) {
|
|
153
|
+
params = {};
|
|
154
|
+
for (const [key, value] of searchParams.entries()) {
|
|
155
|
+
params[key] = value;
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
158
|
+
params = searchParams;
|
|
159
|
+
}
|
|
160
|
+
if (process.env.NODE_ENV === "development") {
|
|
161
|
+
console.log("[parseOgImageData] Input params keys:", Object.keys(params));
|
|
162
|
+
console.log("[parseOgImageData] Input params:", params);
|
|
163
|
+
}
|
|
164
|
+
const dataParam = params.data;
|
|
165
|
+
if (dataParam && typeof dataParam === "string" && dataParam.trim() !== "") {
|
|
166
|
+
if (process.env.NODE_ENV === "development") {
|
|
167
|
+
console.log("[parseOgImageData] Found data param, length:", dataParam.length);
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
const decoded = decodeBase64(dataParam);
|
|
171
|
+
if (process.env.NODE_ENV === "development") {
|
|
172
|
+
console.log("[parseOgImageData] Decoded string:", decoded.substring(0, 100));
|
|
173
|
+
}
|
|
174
|
+
const parsed = JSON.parse(decoded);
|
|
175
|
+
if (process.env.NODE_ENV === "development") {
|
|
176
|
+
console.log("[parseOgImageData] Parsed JSON:", parsed);
|
|
177
|
+
}
|
|
178
|
+
const result2 = {};
|
|
179
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
180
|
+
if (value !== void 0 && value !== null) {
|
|
181
|
+
result2[key] = String(value);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (process.env.NODE_ENV === "development") {
|
|
185
|
+
console.log("[parseOgImageData] Result:", result2);
|
|
186
|
+
}
|
|
187
|
+
return result2;
|
|
188
|
+
} catch (decodeError) {
|
|
189
|
+
console.error("[parseOgImageData] Error decoding/parsing data param:", decodeError);
|
|
190
|
+
if (decodeError instanceof Error) {
|
|
191
|
+
console.error("[parseOgImageData] Error message:", decodeError.message);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
} else {
|
|
195
|
+
if (process.env.NODE_ENV === "development") {
|
|
196
|
+
console.log("[parseOgImageData] No data param found or empty");
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const result = {};
|
|
200
|
+
for (const [key, value] of Object.entries(params)) {
|
|
201
|
+
if (key !== "data" && value !== void 0 && value !== null) {
|
|
202
|
+
result[key] = Array.isArray(value) ? value[0] : String(value);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (process.env.NODE_ENV === "development") {
|
|
206
|
+
console.log("[parseOgImageData] Fallback result:", result);
|
|
207
|
+
}
|
|
208
|
+
return result;
|
|
209
|
+
} catch (error) {
|
|
210
|
+
console.error("[parseOgImageData] Unexpected error:", error);
|
|
211
|
+
return {};
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// src/og-image/utils/metadata.ts
|
|
216
|
+
function extractTitle(metadata) {
|
|
217
|
+
if (typeof metadata.title === "string") {
|
|
218
|
+
return metadata.title;
|
|
219
|
+
}
|
|
220
|
+
if (metadata.title) {
|
|
221
|
+
if ("default" in metadata.title) {
|
|
222
|
+
return metadata.title.default;
|
|
223
|
+
}
|
|
224
|
+
if ("absolute" in metadata.title) {
|
|
225
|
+
return metadata.title.absolute;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return "";
|
|
229
|
+
}
|
|
230
|
+
function extractDescription(metadata) {
|
|
231
|
+
if (typeof metadata.description === "string") {
|
|
232
|
+
return metadata.description;
|
|
233
|
+
}
|
|
234
|
+
return "";
|
|
235
|
+
}
|
|
236
|
+
function getSiteUrl() {
|
|
237
|
+
if (typeof process !== "undefined" && process.env.NEXT_PUBLIC_SITE_URL) {
|
|
238
|
+
return process.env.NEXT_PUBLIC_SITE_URL;
|
|
239
|
+
}
|
|
240
|
+
return "";
|
|
241
|
+
}
|
|
242
|
+
function generateOgImageMetadata(metadata, ogImageParams, options = {}) {
|
|
243
|
+
const {
|
|
244
|
+
ogImageBaseUrl = "https://djangocfg.com/api/og",
|
|
245
|
+
siteUrl: providedSiteUrl,
|
|
246
|
+
defaultParams = {},
|
|
247
|
+
useBase64 = true
|
|
248
|
+
} = options;
|
|
249
|
+
const siteUrl = providedSiteUrl && providedSiteUrl !== "undefined" ? providedSiteUrl : getSiteUrl();
|
|
250
|
+
const extractedTitle = extractTitle(metadata);
|
|
251
|
+
const extractedDescription = extractDescription(metadata);
|
|
252
|
+
const finalOgImageParams = {
|
|
253
|
+
...defaultParams,
|
|
254
|
+
title: ogImageParams?.title || extractedTitle || defaultParams.title || "",
|
|
255
|
+
description: ogImageParams?.description || extractedDescription || defaultParams.description || "",
|
|
256
|
+
...ogImageParams
|
|
257
|
+
};
|
|
258
|
+
const imageAlt = finalOgImageParams.title || finalOgImageParams.siteName;
|
|
259
|
+
const relativeOgImageUrl = generateOgImageUrl(
|
|
260
|
+
finalOgImageParams,
|
|
261
|
+
{ baseUrl: ogImageBaseUrl, useBase64 }
|
|
262
|
+
);
|
|
263
|
+
const ogImageUrl = siteUrl ? getAbsoluteOgImageUrl(relativeOgImageUrl, siteUrl) : relativeOgImageUrl;
|
|
264
|
+
const existingOgImages = metadata.openGraph?.images ? Array.isArray(metadata.openGraph.images) ? metadata.openGraph.images : [metadata.openGraph.images] : [];
|
|
265
|
+
const existingTwitterImages = metadata.twitter?.images ? Array.isArray(metadata.twitter.images) ? metadata.twitter.images : [metadata.twitter.images] : [];
|
|
266
|
+
const finalMetadata = {
|
|
267
|
+
...metadata,
|
|
268
|
+
openGraph: {
|
|
269
|
+
...metadata.openGraph,
|
|
270
|
+
images: [
|
|
271
|
+
...existingOgImages,
|
|
272
|
+
{
|
|
273
|
+
url: ogImageUrl,
|
|
274
|
+
width: 1200,
|
|
275
|
+
height: 630,
|
|
276
|
+
alt: imageAlt
|
|
277
|
+
}
|
|
278
|
+
]
|
|
279
|
+
},
|
|
280
|
+
twitter: {
|
|
281
|
+
...metadata.twitter,
|
|
282
|
+
card: "summary_large_image",
|
|
283
|
+
images: [
|
|
284
|
+
...existingTwitterImages,
|
|
285
|
+
{
|
|
286
|
+
url: ogImageUrl,
|
|
287
|
+
alt: imageAlt
|
|
288
|
+
}
|
|
289
|
+
]
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
if (!finalMetadata.metadataBase && siteUrl) {
|
|
293
|
+
if (siteUrl.startsWith("http://") || siteUrl.startsWith("https://")) {
|
|
294
|
+
try {
|
|
295
|
+
finalMetadata.metadataBase = new URL(siteUrl);
|
|
296
|
+
} catch (e) {
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return finalMetadata;
|
|
301
|
+
}
|
|
302
|
+
function createOgImageMetadataGenerator(options) {
|
|
303
|
+
return (metadata, ogImageParams) => {
|
|
304
|
+
return generateOgImageMetadata(metadata, ogImageParams, options);
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// src/og-image/components/DefaultTemplate.tsx
|
|
309
|
+
function DefaultTemplate({
|
|
310
|
+
title,
|
|
311
|
+
description,
|
|
312
|
+
siteName,
|
|
313
|
+
logo,
|
|
314
|
+
// Visibility flags
|
|
315
|
+
showLogo = true,
|
|
316
|
+
showSiteName = true,
|
|
317
|
+
// Background customization
|
|
318
|
+
backgroundType = "gradient",
|
|
319
|
+
gradientStart = "#667eea",
|
|
320
|
+
gradientEnd = "#764ba2",
|
|
321
|
+
backgroundColor = "#ffffff",
|
|
322
|
+
// Typography - Title
|
|
323
|
+
titleSize,
|
|
324
|
+
titleWeight = 800,
|
|
325
|
+
titleColor = "white",
|
|
326
|
+
// Typography - Description
|
|
327
|
+
descriptionSize = 32,
|
|
328
|
+
descriptionColor = "rgba(255, 255, 255, 0.85)",
|
|
329
|
+
// Typography - Site Name
|
|
330
|
+
siteNameSize = 28,
|
|
331
|
+
siteNameColor = "rgba(255, 255, 255, 0.95)",
|
|
332
|
+
// Layout
|
|
333
|
+
padding = 80,
|
|
334
|
+
logoSize = 48,
|
|
335
|
+
// Dev mode
|
|
336
|
+
devMode = false
|
|
337
|
+
}) {
|
|
338
|
+
const calculatedTitleSize = titleSize || (title.length > 60 ? 56 : 72);
|
|
339
|
+
const backgroundStyle = backgroundType === "gradient" ? `linear-gradient(135deg, ${gradientStart} 0%, ${gradientEnd} 100%)` : backgroundColor;
|
|
340
|
+
const gridOverlay = devMode ? /* @__PURE__ */ React.createElement(
|
|
341
|
+
"div",
|
|
342
|
+
{
|
|
343
|
+
style: {
|
|
344
|
+
position: "absolute",
|
|
345
|
+
top: 0,
|
|
346
|
+
left: 0,
|
|
347
|
+
right: 0,
|
|
348
|
+
bottom: 0,
|
|
349
|
+
backgroundImage: `
|
|
350
|
+
linear-gradient(rgba(0, 0, 0, 0.1) 1px, transparent 1px),
|
|
351
|
+
linear-gradient(90deg, rgba(0, 0, 0, 0.1) 1px, transparent 1px)
|
|
352
|
+
`,
|
|
353
|
+
backgroundSize: "20px 20px",
|
|
354
|
+
pointerEvents: "none",
|
|
355
|
+
zIndex: 10
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
) : null;
|
|
359
|
+
return /* @__PURE__ */ React.createElement(
|
|
360
|
+
"div",
|
|
361
|
+
{
|
|
362
|
+
style: {
|
|
363
|
+
height: "100%",
|
|
364
|
+
width: "100%",
|
|
365
|
+
display: "flex",
|
|
366
|
+
flexDirection: "column",
|
|
367
|
+
alignItems: "flex-start",
|
|
368
|
+
justifyContent: "space-between",
|
|
369
|
+
background: backgroundStyle,
|
|
370
|
+
padding: `${padding}px`,
|
|
371
|
+
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
372
|
+
position: "relative"
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
gridOverlay,
|
|
376
|
+
(showLogo && logo || showSiteName && siteName) && /* @__PURE__ */ React.createElement(
|
|
377
|
+
"div",
|
|
378
|
+
{
|
|
379
|
+
style: {
|
|
380
|
+
display: "flex",
|
|
381
|
+
alignItems: "center",
|
|
382
|
+
gap: "16px"
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
showLogo && logo && // eslint-disable-next-line @next/next/no-img-element
|
|
386
|
+
/* @__PURE__ */ React.createElement(
|
|
387
|
+
"img",
|
|
388
|
+
{
|
|
389
|
+
src: logo,
|
|
390
|
+
alt: "Logo",
|
|
391
|
+
width: logoSize,
|
|
392
|
+
height: logoSize,
|
|
393
|
+
style: {
|
|
394
|
+
borderRadius: "8px"
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
),
|
|
398
|
+
showSiteName && siteName && /* @__PURE__ */ React.createElement(
|
|
399
|
+
"div",
|
|
400
|
+
{
|
|
401
|
+
style: {
|
|
402
|
+
fontSize: siteNameSize,
|
|
403
|
+
fontWeight: 600,
|
|
404
|
+
color: siteNameColor,
|
|
405
|
+
letterSpacing: "-0.02em"
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
siteName
|
|
409
|
+
)
|
|
410
|
+
),
|
|
411
|
+
/* @__PURE__ */ React.createElement(
|
|
412
|
+
"div",
|
|
413
|
+
{
|
|
414
|
+
style: {
|
|
415
|
+
display: "flex",
|
|
416
|
+
flexDirection: "column",
|
|
417
|
+
gap: "24px",
|
|
418
|
+
flex: 1,
|
|
419
|
+
justifyContent: "center"
|
|
420
|
+
}
|
|
421
|
+
},
|
|
422
|
+
/* @__PURE__ */ React.createElement(
|
|
423
|
+
"div",
|
|
424
|
+
{
|
|
425
|
+
style: {
|
|
426
|
+
fontSize: calculatedTitleSize,
|
|
427
|
+
fontWeight: titleWeight,
|
|
428
|
+
color: titleColor,
|
|
429
|
+
lineHeight: 1.1,
|
|
430
|
+
letterSpacing: "-0.03em",
|
|
431
|
+
textShadow: backgroundType === "gradient" ? "0 2px 20px rgba(0, 0, 0, 0.2)" : "none",
|
|
432
|
+
maxWidth: "100%",
|
|
433
|
+
wordWrap: "break-word"
|
|
434
|
+
}
|
|
435
|
+
},
|
|
436
|
+
title
|
|
437
|
+
),
|
|
438
|
+
description && /* @__PURE__ */ React.createElement(
|
|
439
|
+
"div",
|
|
440
|
+
{
|
|
441
|
+
style: {
|
|
442
|
+
fontSize: descriptionSize,
|
|
443
|
+
fontWeight: 400,
|
|
444
|
+
color: descriptionColor,
|
|
445
|
+
lineHeight: 1.5,
|
|
446
|
+
letterSpacing: "-0.01em",
|
|
447
|
+
maxWidth: "90%",
|
|
448
|
+
display: "-webkit-box",
|
|
449
|
+
WebkitLineClamp: 2,
|
|
450
|
+
WebkitBoxOrient: "vertical",
|
|
451
|
+
overflow: "hidden"
|
|
452
|
+
}
|
|
453
|
+
},
|
|
454
|
+
description
|
|
455
|
+
)
|
|
456
|
+
),
|
|
457
|
+
/* @__PURE__ */ React.createElement(
|
|
458
|
+
"div",
|
|
459
|
+
{
|
|
460
|
+
style: {
|
|
461
|
+
display: "flex",
|
|
462
|
+
width: "100%",
|
|
463
|
+
height: "4px",
|
|
464
|
+
background: backgroundType === "gradient" ? `linear-gradient(90deg, ${gradientStart} 0%, ${gradientEnd} 100%)` : gradientStart,
|
|
465
|
+
borderRadius: "2px"
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
)
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
function LightTemplate({
|
|
472
|
+
title,
|
|
473
|
+
description,
|
|
474
|
+
siteName,
|
|
475
|
+
logo,
|
|
476
|
+
// Visibility flags
|
|
477
|
+
showLogo = true,
|
|
478
|
+
showSiteName = true,
|
|
479
|
+
// Background customization (defaults to light theme)
|
|
480
|
+
backgroundType = "solid",
|
|
481
|
+
gradientStart = "#667eea",
|
|
482
|
+
gradientEnd = "#764ba2",
|
|
483
|
+
backgroundColor = "#ffffff",
|
|
484
|
+
// Typography - Title
|
|
485
|
+
titleSize,
|
|
486
|
+
titleWeight = 800,
|
|
487
|
+
titleColor = "#111",
|
|
488
|
+
// Typography - Description
|
|
489
|
+
descriptionSize = 32,
|
|
490
|
+
descriptionColor = "#666",
|
|
491
|
+
// Typography - Site Name
|
|
492
|
+
siteNameSize = 28,
|
|
493
|
+
siteNameColor = "#111",
|
|
494
|
+
// Layout
|
|
495
|
+
padding = 80,
|
|
496
|
+
logoSize = 48,
|
|
497
|
+
// Dev mode
|
|
498
|
+
devMode = false
|
|
499
|
+
}) {
|
|
500
|
+
const calculatedTitleSize = titleSize || (title.length > 60 ? 56 : 72);
|
|
501
|
+
const backgroundStyle = backgroundType === "gradient" ? `linear-gradient(135deg, ${gradientStart} 0%, ${gradientEnd} 100%)` : backgroundColor;
|
|
502
|
+
const gridOverlay = devMode ? /* @__PURE__ */ React.createElement(
|
|
503
|
+
"div",
|
|
504
|
+
{
|
|
505
|
+
style: {
|
|
506
|
+
position: "absolute",
|
|
507
|
+
top: 0,
|
|
508
|
+
left: 0,
|
|
509
|
+
right: 0,
|
|
510
|
+
bottom: 0,
|
|
511
|
+
backgroundImage: `
|
|
512
|
+
linear-gradient(rgba(0, 0, 0, 0.1) 1px, transparent 1px),
|
|
513
|
+
linear-gradient(90deg, rgba(0, 0, 0, 0.1) 1px, transparent 1px)
|
|
514
|
+
`,
|
|
515
|
+
backgroundSize: "20px 20px",
|
|
516
|
+
pointerEvents: "none",
|
|
517
|
+
zIndex: 10
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
) : null;
|
|
521
|
+
return /* @__PURE__ */ React.createElement(
|
|
522
|
+
"div",
|
|
523
|
+
{
|
|
524
|
+
style: {
|
|
525
|
+
height: "100%",
|
|
526
|
+
width: "100%",
|
|
527
|
+
display: "flex",
|
|
528
|
+
flexDirection: "column",
|
|
529
|
+
alignItems: "flex-start",
|
|
530
|
+
justifyContent: "space-between",
|
|
531
|
+
background: backgroundStyle,
|
|
532
|
+
padding: `${padding}px`,
|
|
533
|
+
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
534
|
+
position: "relative"
|
|
535
|
+
}
|
|
536
|
+
},
|
|
537
|
+
gridOverlay,
|
|
538
|
+
(showLogo && logo || showSiteName && siteName) && /* @__PURE__ */ React.createElement(
|
|
539
|
+
"div",
|
|
540
|
+
{
|
|
541
|
+
style: {
|
|
542
|
+
display: "flex",
|
|
543
|
+
alignItems: "center",
|
|
544
|
+
gap: "16px"
|
|
545
|
+
}
|
|
546
|
+
},
|
|
547
|
+
showLogo && logo && // eslint-disable-next-line @next/next/no-img-element
|
|
548
|
+
/* @__PURE__ */ React.createElement(
|
|
549
|
+
"img",
|
|
550
|
+
{
|
|
551
|
+
src: logo,
|
|
552
|
+
alt: "Logo",
|
|
553
|
+
width: logoSize,
|
|
554
|
+
height: logoSize,
|
|
555
|
+
style: {
|
|
556
|
+
borderRadius: "8px"
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
),
|
|
560
|
+
showSiteName && siteName && /* @__PURE__ */ React.createElement(
|
|
561
|
+
"div",
|
|
562
|
+
{
|
|
563
|
+
style: {
|
|
564
|
+
fontSize: siteNameSize,
|
|
565
|
+
fontWeight: 600,
|
|
566
|
+
color: siteNameColor,
|
|
567
|
+
letterSpacing: "-0.02em"
|
|
568
|
+
}
|
|
569
|
+
},
|
|
570
|
+
siteName
|
|
571
|
+
)
|
|
572
|
+
),
|
|
573
|
+
/* @__PURE__ */ React.createElement(
|
|
574
|
+
"div",
|
|
575
|
+
{
|
|
576
|
+
style: {
|
|
577
|
+
display: "flex",
|
|
578
|
+
flexDirection: "column",
|
|
579
|
+
gap: "24px",
|
|
580
|
+
flex: 1,
|
|
581
|
+
justifyContent: "center"
|
|
582
|
+
}
|
|
583
|
+
},
|
|
584
|
+
/* @__PURE__ */ React.createElement(
|
|
585
|
+
"div",
|
|
586
|
+
{
|
|
587
|
+
style: {
|
|
588
|
+
fontSize: calculatedTitleSize,
|
|
589
|
+
fontWeight: titleWeight,
|
|
590
|
+
color: titleColor,
|
|
591
|
+
lineHeight: 1.1,
|
|
592
|
+
letterSpacing: "-0.03em",
|
|
593
|
+
maxWidth: "100%",
|
|
594
|
+
wordWrap: "break-word"
|
|
595
|
+
}
|
|
596
|
+
},
|
|
597
|
+
title
|
|
598
|
+
),
|
|
599
|
+
description && /* @__PURE__ */ React.createElement(
|
|
600
|
+
"div",
|
|
601
|
+
{
|
|
602
|
+
style: {
|
|
603
|
+
fontSize: descriptionSize,
|
|
604
|
+
fontWeight: 400,
|
|
605
|
+
color: descriptionColor,
|
|
606
|
+
lineHeight: 1.5,
|
|
607
|
+
letterSpacing: "-0.01em",
|
|
608
|
+
maxWidth: "90%"
|
|
609
|
+
}
|
|
610
|
+
},
|
|
611
|
+
description
|
|
612
|
+
)
|
|
613
|
+
),
|
|
614
|
+
/* @__PURE__ */ React.createElement(
|
|
615
|
+
"div",
|
|
616
|
+
{
|
|
617
|
+
style: {
|
|
618
|
+
display: "flex",
|
|
619
|
+
width: "100%",
|
|
620
|
+
height: "4px",
|
|
621
|
+
background: backgroundType === "gradient" ? `linear-gradient(90deg, ${gradientStart} 0%, ${gradientEnd} 100%)` : gradientStart,
|
|
622
|
+
borderRadius: "2px"
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
)
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// src/og-image/route.tsx
|
|
630
|
+
function createOgImageHandler(config) {
|
|
631
|
+
const {
|
|
632
|
+
template: Template = DefaultTemplate,
|
|
633
|
+
defaultProps = {},
|
|
634
|
+
fonts: fontConfig = [],
|
|
635
|
+
size = { width: 1200, height: 630 },
|
|
636
|
+
debug = false
|
|
637
|
+
} = config;
|
|
638
|
+
async function GET(req) {
|
|
639
|
+
let searchParams = new URLSearchParams();
|
|
640
|
+
if (req.nextUrl?.searchParams && req.nextUrl.searchParams.size > 0) {
|
|
641
|
+
searchParams = req.nextUrl.searchParams;
|
|
642
|
+
} else if (req.nextUrl?.search && req.nextUrl.search.length > 1) {
|
|
643
|
+
searchParams = new URLSearchParams(req.nextUrl.search);
|
|
644
|
+
} else {
|
|
645
|
+
try {
|
|
646
|
+
const url = new URL(req.url);
|
|
647
|
+
if (url.searchParams.size > 0) {
|
|
648
|
+
searchParams = url.searchParams;
|
|
649
|
+
}
|
|
650
|
+
} catch (error) {
|
|
651
|
+
}
|
|
652
|
+
if (searchParams.size === 0 && req.url) {
|
|
653
|
+
const queryIndex = req.url.indexOf("?");
|
|
654
|
+
if (queryIndex !== -1) {
|
|
655
|
+
const queryString = req.url.substring(queryIndex + 1);
|
|
656
|
+
searchParams = new URLSearchParams(queryString);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
if (searchParams.size === 0) {
|
|
660
|
+
const customParams = req.headers.get("x-og-search-params");
|
|
661
|
+
if (customParams) {
|
|
662
|
+
searchParams = new URLSearchParams(customParams);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
let title = defaultProps.title || "Untitled";
|
|
667
|
+
let subtitle = defaultProps.subtitle || "";
|
|
668
|
+
let description = defaultProps.description || subtitle;
|
|
669
|
+
const dataParam = searchParams.get("data");
|
|
670
|
+
let decodedParams = {};
|
|
671
|
+
if (dataParam) {
|
|
672
|
+
try {
|
|
673
|
+
const paramsObj = { data: dataParam };
|
|
674
|
+
for (const [key, value] of searchParams.entries()) {
|
|
675
|
+
if (key !== "data") {
|
|
676
|
+
paramsObj[key] = value;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
decodedParams = parseOgImageData(paramsObj);
|
|
680
|
+
if (decodedParams.title && typeof decodedParams.title === "string" && decodedParams.title.trim() !== "") {
|
|
681
|
+
title = decodedParams.title.trim();
|
|
682
|
+
}
|
|
683
|
+
if (decodedParams.subtitle && typeof decodedParams.subtitle === "string" && decodedParams.subtitle.trim() !== "") {
|
|
684
|
+
subtitle = decodedParams.subtitle.trim();
|
|
685
|
+
}
|
|
686
|
+
if (decodedParams.description && typeof decodedParams.description === "string" && decodedParams.description.trim() !== "") {
|
|
687
|
+
description = decodedParams.description.trim();
|
|
688
|
+
}
|
|
689
|
+
} catch (error) {
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
if (!title || title === "Untitled") {
|
|
693
|
+
const titleParam = searchParams.get("title");
|
|
694
|
+
if (titleParam) {
|
|
695
|
+
title = titleParam;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
if (!subtitle) {
|
|
699
|
+
const subtitleParam = searchParams.get("subtitle");
|
|
700
|
+
if (subtitleParam) {
|
|
701
|
+
subtitle = subtitleParam;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
if (!description || description === subtitle) {
|
|
705
|
+
const descParam = searchParams.get("description");
|
|
706
|
+
if (descParam) {
|
|
707
|
+
description = descParam;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
let fonts = [];
|
|
711
|
+
if (fontConfig.length > 0) {
|
|
712
|
+
fonts = await loadGoogleFonts(fontConfig);
|
|
713
|
+
}
|
|
714
|
+
const parseValue = (value, type = "string") => {
|
|
715
|
+
if (value === void 0 || value === null || value === "") {
|
|
716
|
+
return void 0;
|
|
717
|
+
}
|
|
718
|
+
if (type === "number") {
|
|
719
|
+
const num = Number(value);
|
|
720
|
+
return isNaN(num) ? void 0 : num;
|
|
721
|
+
}
|
|
722
|
+
if (type === "boolean") {
|
|
723
|
+
if (typeof value === "boolean") return value;
|
|
724
|
+
if (typeof value === "string") {
|
|
725
|
+
return value.toLowerCase() === "true" || value === "1";
|
|
726
|
+
}
|
|
727
|
+
return Boolean(value);
|
|
728
|
+
}
|
|
729
|
+
return String(value);
|
|
730
|
+
};
|
|
731
|
+
const templateProps = {
|
|
732
|
+
...defaultProps,
|
|
733
|
+
// Content
|
|
734
|
+
title,
|
|
735
|
+
subtitle,
|
|
736
|
+
description,
|
|
737
|
+
// Override with decoded params if present
|
|
738
|
+
siteName: decodedParams.siteName || defaultProps.siteName,
|
|
739
|
+
logo: decodedParams.logo || defaultProps.logo,
|
|
740
|
+
// Background
|
|
741
|
+
backgroundType: decodedParams.backgroundType || defaultProps.backgroundType,
|
|
742
|
+
gradientStart: decodedParams.gradientStart || defaultProps.gradientStart,
|
|
743
|
+
gradientEnd: decodedParams.gradientEnd || defaultProps.gradientEnd,
|
|
744
|
+
backgroundColor: decodedParams.backgroundColor || defaultProps.backgroundColor,
|
|
745
|
+
// Typography - Title
|
|
746
|
+
titleSize: parseValue(decodedParams.titleSize, "number") ?? defaultProps.titleSize,
|
|
747
|
+
titleWeight: parseValue(decodedParams.titleWeight, "number") ?? defaultProps.titleWeight,
|
|
748
|
+
titleColor: decodedParams.titleColor || defaultProps.titleColor,
|
|
749
|
+
// Typography - Description
|
|
750
|
+
descriptionSize: parseValue(decodedParams.descriptionSize, "number") ?? defaultProps.descriptionSize,
|
|
751
|
+
descriptionColor: decodedParams.descriptionColor || defaultProps.descriptionColor,
|
|
752
|
+
// Typography - Site Name
|
|
753
|
+
siteNameSize: parseValue(decodedParams.siteNameSize, "number") ?? defaultProps.siteNameSize,
|
|
754
|
+
siteNameColor: decodedParams.siteNameColor || defaultProps.siteNameColor,
|
|
755
|
+
// Layout
|
|
756
|
+
padding: parseValue(decodedParams.padding, "number") ?? defaultProps.padding,
|
|
757
|
+
logoSize: parseValue(decodedParams.logoSize, "number") ?? defaultProps.logoSize,
|
|
758
|
+
// Visibility flags
|
|
759
|
+
showLogo: parseValue(decodedParams.showLogo, "boolean") ?? defaultProps.showLogo,
|
|
760
|
+
showSiteName: parseValue(decodedParams.showSiteName, "boolean") ?? defaultProps.showSiteName
|
|
761
|
+
};
|
|
762
|
+
return new ImageResponse(
|
|
763
|
+
/* @__PURE__ */ React.createElement(Template, { ...templateProps }),
|
|
764
|
+
{
|
|
765
|
+
width: size.width,
|
|
766
|
+
height: size.height,
|
|
767
|
+
fonts,
|
|
768
|
+
debug: debug || process.env.NODE_ENV === "development"
|
|
769
|
+
}
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
return {
|
|
773
|
+
GET,
|
|
774
|
+
runtime: "edge"
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
function createOgImageDynamicRoute(config) {
|
|
778
|
+
const handler = createOgImageHandler(config);
|
|
779
|
+
const isStaticBuild = typeof process !== "undefined" && process.env.NEXT_PUBLIC_STATIC_BUILD === "true";
|
|
780
|
+
async function GET(request, context) {
|
|
781
|
+
if (isStaticBuild) {
|
|
782
|
+
return new Response("OG Image generation is not available in static export mode", {
|
|
783
|
+
status: 404,
|
|
784
|
+
headers: { "Content-Type": "text/plain" }
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
const params = await context.params;
|
|
788
|
+
const dataParam = params.data;
|
|
789
|
+
const url = new URL(request.url);
|
|
790
|
+
url.searchParams.set("data", dataParam);
|
|
791
|
+
const modifiedRequest = new NextRequest(url.toString(), {
|
|
792
|
+
method: request.method,
|
|
793
|
+
headers: request.headers
|
|
794
|
+
});
|
|
795
|
+
return handler.GET(modifiedRequest);
|
|
796
|
+
}
|
|
797
|
+
async function generateStaticParams() {
|
|
798
|
+
return [];
|
|
799
|
+
}
|
|
800
|
+
return {
|
|
801
|
+
GET,
|
|
802
|
+
generateStaticParams
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
export {
|
|
806
|
+
DefaultTemplate,
|
|
807
|
+
LightTemplate,
|
|
808
|
+
createFontLoader,
|
|
809
|
+
createOgImageDynamicRoute,
|
|
810
|
+
createOgImageHandler,
|
|
811
|
+
createOgImageMetadataGenerator,
|
|
812
|
+
createOgImageUrlBuilder,
|
|
813
|
+
decodeBase64,
|
|
814
|
+
encodeBase64,
|
|
815
|
+
generateOgImageMetadata,
|
|
816
|
+
generateOgImageUrl,
|
|
817
|
+
getAbsoluteOgImageUrl,
|
|
818
|
+
loadGoogleFont,
|
|
819
|
+
loadGoogleFonts,
|
|
820
|
+
parseOgImageData,
|
|
821
|
+
parseOgImageUrl
|
|
822
|
+
};
|
|
823
|
+
//# sourceMappingURL=index.mjs.map
|