@opinly/next 0.0.0-alpha-20260707133941
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/config.cjs +134 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +50 -0
- package/dist/config.d.ts +50 -0
- package/dist/config.js +110 -0
- package/dist/config.js.map +1 -0
- package/dist/index.cjs +53 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/json-ld.cjs +61 -0
- package/dist/json-ld.cjs.map +1 -0
- package/dist/json-ld.d.cts +17 -0
- package/dist/json-ld.d.ts +17 -0
- package/dist/json-ld.js +38 -0
- package/dist/json-ld.js.map +1 -0
- package/dist/utils/dates.cjs +33 -0
- package/dist/utils/dates.cjs.map +1 -0
- package/dist/utils/dates.d.cts +3 -0
- package/dist/utils/dates.d.ts +3 -0
- package/dist/utils/dates.js +9 -0
- package/dist/utils/dates.js.map +1 -0
- package/dist/utils/generate-metadata.cjs +54 -0
- package/dist/utils/generate-metadata.cjs.map +1 -0
- package/dist/utils/generate-metadata.d.cts +15 -0
- package/dist/utils/generate-metadata.d.ts +15 -0
- package/dist/utils/generate-metadata.js +30 -0
- package/dist/utils/generate-metadata.js.map +1 -0
- package/dist/utils/generate-sitemap-xml.cjs +42 -0
- package/dist/utils/generate-sitemap-xml.cjs.map +1 -0
- package/dist/utils/generate-sitemap-xml.d.cts +7 -0
- package/dist/utils/generate-sitemap-xml.d.ts +7 -0
- package/dist/utils/generate-sitemap-xml.js +18 -0
- package/dist/utils/generate-sitemap-xml.js.map +1 -0
- package/dist/utils/merge.cjs +33 -0
- package/dist/utils/merge.cjs.map +1 -0
- package/dist/utils/merge.d.cts +5 -0
- package/dist/utils/merge.d.ts +5 -0
- package/dist/utils/merge.js +9 -0
- package/dist/utils/merge.js.map +1 -0
- package/dist/utils/sdk-config.cjs +59 -0
- package/dist/utils/sdk-config.cjs.map +1 -0
- package/dist/utils/sdk-config.d.cts +29 -0
- package/dist/utils/sdk-config.d.ts +29 -0
- package/dist/utils/sdk-config.js +34 -0
- package/dist/utils/sdk-config.js.map +1 -0
- package/package.json +72 -0
package/dist/config.cjs
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var config_exports = {};
|
|
20
|
+
__export(config_exports, {
|
|
21
|
+
withOpinlyConfig: () => withOpinlyConfig
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(config_exports);
|
|
24
|
+
var import_zod = require("zod");
|
|
25
|
+
const opinlyOptionsSchema = import_zod.z.object({
|
|
26
|
+
imagesPath: import_zod.z.string({}).refine(
|
|
27
|
+
(val) => val.startsWith("/") || import_zod.z.string().url().safeParse(val).success,
|
|
28
|
+
{
|
|
29
|
+
message: "imagesPath must start with a leading slash (e.g. '/images')"
|
|
30
|
+
}
|
|
31
|
+
),
|
|
32
|
+
blogPath: import_zod.z.string({}).startsWith("/", {
|
|
33
|
+
message: "blogPath must start with a leading slash i.e. `/blog`"
|
|
34
|
+
}),
|
|
35
|
+
companyName: import_zod.z.string({
|
|
36
|
+
required_error: "companyName is required",
|
|
37
|
+
invalid_type_error: "companyName must be a string"
|
|
38
|
+
}),
|
|
39
|
+
cdnNamespace: import_zod.z.string().min(21, "CDN namespace must be 21 characters long").max(21, "CDN namespace must be 21 characters long"),
|
|
40
|
+
siteUrl: import_zod.z.string().url({
|
|
41
|
+
message: "siteUrl must be a valid URL"
|
|
42
|
+
}),
|
|
43
|
+
unoptimizedImages: import_zod.z.boolean().optional(),
|
|
44
|
+
categoryPrefix: import_zod.z.string().optional(),
|
|
45
|
+
authorPrefix: import_zod.z.string().optional(),
|
|
46
|
+
tagPrefix: import_zod.z.string().optional(),
|
|
47
|
+
cdnDomain: import_zod.z.string({
|
|
48
|
+
description: "INTERNAL USE ONLY: The domain of the CDN. If not provided, the default domain will be used."
|
|
49
|
+
}).url({
|
|
50
|
+
message: "cdnDomain must be a valid URL"
|
|
51
|
+
}).optional(),
|
|
52
|
+
pagesRouter: import_zod.z.boolean().optional()
|
|
53
|
+
});
|
|
54
|
+
const validateOpinlyOptions = (opinlyOptions) => {
|
|
55
|
+
if (!opinlyOptions) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
"[@opinly/next] `opts` is required. Please provide the options object."
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
const parsedOpinlyOptions = opinlyOptionsSchema.safeParse(opinlyOptions);
|
|
61
|
+
if (!parsedOpinlyOptions.success) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
`[@opinly/next] Invalid options provided in next.config.js: ${parsedOpinlyOptions.error.message}`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const processRewrites = (userNextConfig, opinlyOptions) => {
|
|
68
|
+
const imagesPath = opinlyOptions.imagesPath;
|
|
69
|
+
if (!imagesPath.startsWith("/")) {
|
|
70
|
+
console.warn(
|
|
71
|
+
`[@opinly/next] You have provided a url for imagesPath. This is only valid for internal testing and rewrites will be skipped.`
|
|
72
|
+
);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const originalRewrites = userNextConfig.rewrites;
|
|
76
|
+
userNextConfig.rewrites = async () => {
|
|
77
|
+
const opinlyRewrite = {
|
|
78
|
+
source: `${opinlyOptions.imagesPath}/:path*`,
|
|
79
|
+
destination: `${opinlyOptions.cdnDomain || "https://cdn.opinly.ai"}/${opinlyOptions.cdnNamespace}/:path*`
|
|
80
|
+
};
|
|
81
|
+
const newRewrites = [opinlyRewrite];
|
|
82
|
+
if (opinlyOptions.pagesRouter) {
|
|
83
|
+
newRewrites.push({
|
|
84
|
+
source: "/sitemap.xml",
|
|
85
|
+
destination: "/sitemap"
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (typeof originalRewrites !== "function") {
|
|
89
|
+
return newRewrites;
|
|
90
|
+
}
|
|
91
|
+
const resolvedRewrites = await originalRewrites();
|
|
92
|
+
if (Array.isArray(resolvedRewrites)) {
|
|
93
|
+
return [...resolvedRewrites, opinlyRewrite];
|
|
94
|
+
} else {
|
|
95
|
+
return {
|
|
96
|
+
...resolvedRewrites,
|
|
97
|
+
beforeFiles: [...resolvedRewrites.beforeFiles || [], ...newRewrites]
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
function addEnvVars(userNextConfig, opinlyOptions) {
|
|
103
|
+
const opinlyEnvVars = {
|
|
104
|
+
OPINLY_IMAGES_PREFIX: opinlyOptions.imagesPath,
|
|
105
|
+
OPINLY_BLOG_PREFIX: opinlyOptions.blogPath,
|
|
106
|
+
OPINLY_SITE_NAME: opinlyOptions.companyName,
|
|
107
|
+
OPINLY_SITE_URL: opinlyOptions.siteUrl,
|
|
108
|
+
OPINLY_UNOPTIMIZED_IMAGES: opinlyOptions.unoptimizedImages ? "true" : void 0,
|
|
109
|
+
OPINLY_PAGES_ROUTER: opinlyOptions.pagesRouter ? "true" : void 0,
|
|
110
|
+
OPINLY_CATEGORY_PREFIX: opinlyOptions.categoryPrefix,
|
|
111
|
+
OPINLY_AUTHOR_PREFIX: opinlyOptions.authorPrefix,
|
|
112
|
+
OPINLY_TAG_PREFIX: opinlyOptions.tagPrefix
|
|
113
|
+
};
|
|
114
|
+
userNextConfig.env = {
|
|
115
|
+
...userNextConfig.env || {},
|
|
116
|
+
...opinlyEnvVars
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const withOpinlyConfig = (opinlyOptions) => (
|
|
120
|
+
// Generic over the config type so this composes with any Next version's
|
|
121
|
+
// `NextConfig` (the consumer's next may differ from the one this package was
|
|
122
|
+
// built against). We only read/write `env` and `rewrites` internally.
|
|
123
|
+
(nextConfig) => {
|
|
124
|
+
validateOpinlyOptions(opinlyOptions);
|
|
125
|
+
addEnvVars(nextConfig, opinlyOptions);
|
|
126
|
+
processRewrites(nextConfig, opinlyOptions);
|
|
127
|
+
return nextConfig;
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
131
|
+
0 && (module.exports = {
|
|
132
|
+
withOpinlyConfig
|
|
133
|
+
});
|
|
134
|
+
//# sourceMappingURL=config.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config.ts"],"sourcesContent":["import { NextConfig } from \"next\";\nimport { Rewrite } from \"next/dist/lib/load-custom-routes\";\nimport type { OpinlyEnvVars } from \"./utils/sdk-config\";\nimport { z } from \"zod\";\n\ninterface WithOpinlyOptions {\n imagesPath: `/${string}`;\n blogPath: `/${string}`;\n companyName: string;\n cdnNamespace: string;\n siteUrl: string;\n unoptimizedImages?: boolean;\n /** URL segment categories live under (relative to blogPath). Default: bare. */\n categoryPrefix?: string;\n /** URL segment authors live under (relative to blogPath). Default: \"authors\". */\n authorPrefix?: string;\n /** URL segment tags live under (relative to blogPath). Default: \"tag\". */\n tagPrefix?: string;\n}\n\ntype ResolvedRewrites = ReturnType<\n NonNullable<Awaited<NextConfig[\"rewrites\"]>>\n>;\n\nconst opinlyOptionsSchema = z.object({\n imagesPath: z\n .string({})\n .refine(\n (val) => val.startsWith(\"/\") || z.string().url().safeParse(val).success,\n {\n message: \"imagesPath must start with a leading slash (e.g. '/images')\",\n }\n ),\n blogPath: z.string({}).startsWith(\"/\", {\n message: \"blogPath must start with a leading slash i.e. `/blog`\",\n }),\n companyName: z.string({\n required_error: \"companyName is required\",\n invalid_type_error: \"companyName must be a string\",\n }),\n cdnNamespace: z\n .string()\n .min(21, \"CDN namespace must be 21 characters long\")\n .max(21, \"CDN namespace must be 21 characters long\"),\n siteUrl: z.string().url({\n message: \"siteUrl must be a valid URL\",\n }),\n unoptimizedImages: z.boolean().optional(),\n categoryPrefix: z.string().optional(),\n authorPrefix: z.string().optional(),\n tagPrefix: z.string().optional(),\n cdnDomain: z\n .string({\n description:\n \"INTERNAL USE ONLY: The domain of the CDN. If not provided, the default domain will be used.\",\n })\n .url({\n message: \"cdnDomain must be a valid URL\",\n })\n .optional(),\n pagesRouter: z.boolean().optional(),\n});\n\ntype OpinlyOptions = z.infer<typeof opinlyOptionsSchema>;\n\nconst validateOpinlyOptions = (opinlyOptions: OpinlyOptions) => {\n if (!opinlyOptions) {\n throw new Error(\n \"[@opinly/next] `opts` is required. Please provide the options object.\"\n );\n }\n\n const parsedOpinlyOptions = opinlyOptionsSchema.safeParse(opinlyOptions);\n\n if (!parsedOpinlyOptions.success) {\n throw new Error(\n `[@opinly/next] Invalid options provided in next.config.js: ${parsedOpinlyOptions.error.message}`\n );\n }\n};\n\nconst processRewrites = (\n userNextConfig: NextConfig,\n opinlyOptions: OpinlyOptions\n): void => {\n const imagesPath = opinlyOptions.imagesPath;\n\n if (!imagesPath.startsWith(\"/\")) {\n console.warn(\n `[@opinly/next] You have provided a url for imagesPath. This is only valid for internal testing and rewrites will be skipped.`\n );\n\n return;\n }\n\n const originalRewrites = userNextConfig.rewrites;\n\n userNextConfig.rewrites = async () => {\n const opinlyRewrite = {\n source: `${opinlyOptions.imagesPath}/:path*`,\n destination: `${opinlyOptions.cdnDomain || \"https://cdn.opinly.ai\"}/${\n opinlyOptions.cdnNamespace\n }/:path*`,\n };\n\n const newRewrites = [opinlyRewrite];\n\n if (opinlyOptions.pagesRouter) {\n newRewrites.push({\n source: \"/sitemap.xml\",\n destination: \"/sitemap\",\n });\n }\n\n if (typeof originalRewrites !== \"function\") {\n return newRewrites;\n }\n\n const resolvedRewrites = await originalRewrites();\n\n if (Array.isArray(resolvedRewrites)) {\n return [...resolvedRewrites, opinlyRewrite];\n } else {\n return {\n ...resolvedRewrites,\n beforeFiles: [...(resolvedRewrites.beforeFiles || []), ...newRewrites],\n };\n }\n };\n};\n\nfunction addEnvVars(userNextConfig: NextConfig, opinlyOptions: OpinlyOptions) {\n const opinlyEnvVars: OpinlyEnvVars = {\n OPINLY_IMAGES_PREFIX: opinlyOptions.imagesPath,\n OPINLY_BLOG_PREFIX: opinlyOptions.blogPath,\n OPINLY_SITE_NAME: opinlyOptions.companyName,\n OPINLY_SITE_URL: opinlyOptions.siteUrl,\n OPINLY_UNOPTIMIZED_IMAGES: opinlyOptions.unoptimizedImages\n ? \"true\"\n : undefined,\n OPINLY_PAGES_ROUTER: opinlyOptions.pagesRouter ? \"true\" : undefined,\n OPINLY_CATEGORY_PREFIX: opinlyOptions.categoryPrefix,\n OPINLY_AUTHOR_PREFIX: opinlyOptions.authorPrefix,\n OPINLY_TAG_PREFIX: opinlyOptions.tagPrefix,\n };\n\n userNextConfig.env = {\n ...(userNextConfig.env || {}),\n ...opinlyEnvVars,\n };\n}\n\n/**\n * Modifies the passed in Next.js configuration with image rewrites and environment variables.\n *\n * @param nextConfig A Next.js configuration object, as usually exported in `next.config.js` or `next.config.mjs`.\n * @param opinlyOptions Additional options to configure Opinly.\n * @returns The modified config to be exported\n */\nexport const withOpinlyConfig =\n (opinlyOptions: OpinlyOptions) =>\n // Generic over the config type so this composes with any Next version's\n // `NextConfig` (the consumer's next may differ from the one this package was\n // built against). We only read/write `env` and `rewrites` internally.\n <T extends object>(nextConfig: T): T => {\n validateOpinlyOptions(opinlyOptions);\n\n addEnvVars(nextConfig as NextConfig, opinlyOptions);\n\n processRewrites(nextConfig as NextConfig, opinlyOptions);\n\n return nextConfig;\n };\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const opinlyOptionsSchema: z.ZodObject<{
|
|
4
|
+
imagesPath: z.ZodEffects<z.ZodString, string, string>;
|
|
5
|
+
blogPath: z.ZodString;
|
|
6
|
+
companyName: z.ZodString;
|
|
7
|
+
cdnNamespace: z.ZodString;
|
|
8
|
+
siteUrl: z.ZodString;
|
|
9
|
+
unoptimizedImages: z.ZodOptional<z.ZodBoolean>;
|
|
10
|
+
categoryPrefix: z.ZodOptional<z.ZodString>;
|
|
11
|
+
authorPrefix: z.ZodOptional<z.ZodString>;
|
|
12
|
+
tagPrefix: z.ZodOptional<z.ZodString>;
|
|
13
|
+
cdnDomain: z.ZodOptional<z.ZodString>;
|
|
14
|
+
pagesRouter: z.ZodOptional<z.ZodBoolean>;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
imagesPath: string;
|
|
17
|
+
blogPath: string;
|
|
18
|
+
companyName: string;
|
|
19
|
+
cdnNamespace: string;
|
|
20
|
+
siteUrl: string;
|
|
21
|
+
unoptimizedImages?: boolean | undefined;
|
|
22
|
+
categoryPrefix?: string | undefined;
|
|
23
|
+
authorPrefix?: string | undefined;
|
|
24
|
+
tagPrefix?: string | undefined;
|
|
25
|
+
cdnDomain?: string | undefined;
|
|
26
|
+
pagesRouter?: boolean | undefined;
|
|
27
|
+
}, {
|
|
28
|
+
imagesPath: string;
|
|
29
|
+
blogPath: string;
|
|
30
|
+
companyName: string;
|
|
31
|
+
cdnNamespace: string;
|
|
32
|
+
siteUrl: string;
|
|
33
|
+
unoptimizedImages?: boolean | undefined;
|
|
34
|
+
categoryPrefix?: string | undefined;
|
|
35
|
+
authorPrefix?: string | undefined;
|
|
36
|
+
tagPrefix?: string | undefined;
|
|
37
|
+
cdnDomain?: string | undefined;
|
|
38
|
+
pagesRouter?: boolean | undefined;
|
|
39
|
+
}>;
|
|
40
|
+
type OpinlyOptions = z.infer<typeof opinlyOptionsSchema>;
|
|
41
|
+
/**
|
|
42
|
+
* Modifies the passed in Next.js configuration with image rewrites and environment variables.
|
|
43
|
+
*
|
|
44
|
+
* @param nextConfig A Next.js configuration object, as usually exported in `next.config.js` or `next.config.mjs`.
|
|
45
|
+
* @param opinlyOptions Additional options to configure Opinly.
|
|
46
|
+
* @returns The modified config to be exported
|
|
47
|
+
*/
|
|
48
|
+
declare const withOpinlyConfig: (opinlyOptions: OpinlyOptions) => <T extends object>(nextConfig: T) => T;
|
|
49
|
+
|
|
50
|
+
export { withOpinlyConfig };
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const opinlyOptionsSchema: z.ZodObject<{
|
|
4
|
+
imagesPath: z.ZodEffects<z.ZodString, string, string>;
|
|
5
|
+
blogPath: z.ZodString;
|
|
6
|
+
companyName: z.ZodString;
|
|
7
|
+
cdnNamespace: z.ZodString;
|
|
8
|
+
siteUrl: z.ZodString;
|
|
9
|
+
unoptimizedImages: z.ZodOptional<z.ZodBoolean>;
|
|
10
|
+
categoryPrefix: z.ZodOptional<z.ZodString>;
|
|
11
|
+
authorPrefix: z.ZodOptional<z.ZodString>;
|
|
12
|
+
tagPrefix: z.ZodOptional<z.ZodString>;
|
|
13
|
+
cdnDomain: z.ZodOptional<z.ZodString>;
|
|
14
|
+
pagesRouter: z.ZodOptional<z.ZodBoolean>;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
imagesPath: string;
|
|
17
|
+
blogPath: string;
|
|
18
|
+
companyName: string;
|
|
19
|
+
cdnNamespace: string;
|
|
20
|
+
siteUrl: string;
|
|
21
|
+
unoptimizedImages?: boolean | undefined;
|
|
22
|
+
categoryPrefix?: string | undefined;
|
|
23
|
+
authorPrefix?: string | undefined;
|
|
24
|
+
tagPrefix?: string | undefined;
|
|
25
|
+
cdnDomain?: string | undefined;
|
|
26
|
+
pagesRouter?: boolean | undefined;
|
|
27
|
+
}, {
|
|
28
|
+
imagesPath: string;
|
|
29
|
+
blogPath: string;
|
|
30
|
+
companyName: string;
|
|
31
|
+
cdnNamespace: string;
|
|
32
|
+
siteUrl: string;
|
|
33
|
+
unoptimizedImages?: boolean | undefined;
|
|
34
|
+
categoryPrefix?: string | undefined;
|
|
35
|
+
authorPrefix?: string | undefined;
|
|
36
|
+
tagPrefix?: string | undefined;
|
|
37
|
+
cdnDomain?: string | undefined;
|
|
38
|
+
pagesRouter?: boolean | undefined;
|
|
39
|
+
}>;
|
|
40
|
+
type OpinlyOptions = z.infer<typeof opinlyOptionsSchema>;
|
|
41
|
+
/**
|
|
42
|
+
* Modifies the passed in Next.js configuration with image rewrites and environment variables.
|
|
43
|
+
*
|
|
44
|
+
* @param nextConfig A Next.js configuration object, as usually exported in `next.config.js` or `next.config.mjs`.
|
|
45
|
+
* @param opinlyOptions Additional options to configure Opinly.
|
|
46
|
+
* @returns The modified config to be exported
|
|
47
|
+
*/
|
|
48
|
+
declare const withOpinlyConfig: (opinlyOptions: OpinlyOptions) => <T extends object>(nextConfig: T) => T;
|
|
49
|
+
|
|
50
|
+
export { withOpinlyConfig };
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const opinlyOptionsSchema = z.object({
|
|
3
|
+
imagesPath: z.string({}).refine(
|
|
4
|
+
(val) => val.startsWith("/") || z.string().url().safeParse(val).success,
|
|
5
|
+
{
|
|
6
|
+
message: "imagesPath must start with a leading slash (e.g. '/images')"
|
|
7
|
+
}
|
|
8
|
+
),
|
|
9
|
+
blogPath: z.string({}).startsWith("/", {
|
|
10
|
+
message: "blogPath must start with a leading slash i.e. `/blog`"
|
|
11
|
+
}),
|
|
12
|
+
companyName: z.string({
|
|
13
|
+
required_error: "companyName is required",
|
|
14
|
+
invalid_type_error: "companyName must be a string"
|
|
15
|
+
}),
|
|
16
|
+
cdnNamespace: z.string().min(21, "CDN namespace must be 21 characters long").max(21, "CDN namespace must be 21 characters long"),
|
|
17
|
+
siteUrl: z.string().url({
|
|
18
|
+
message: "siteUrl must be a valid URL"
|
|
19
|
+
}),
|
|
20
|
+
unoptimizedImages: z.boolean().optional(),
|
|
21
|
+
categoryPrefix: z.string().optional(),
|
|
22
|
+
authorPrefix: z.string().optional(),
|
|
23
|
+
tagPrefix: z.string().optional(),
|
|
24
|
+
cdnDomain: z.string({
|
|
25
|
+
description: "INTERNAL USE ONLY: The domain of the CDN. If not provided, the default domain will be used."
|
|
26
|
+
}).url({
|
|
27
|
+
message: "cdnDomain must be a valid URL"
|
|
28
|
+
}).optional(),
|
|
29
|
+
pagesRouter: z.boolean().optional()
|
|
30
|
+
});
|
|
31
|
+
const validateOpinlyOptions = (opinlyOptions) => {
|
|
32
|
+
if (!opinlyOptions) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
"[@opinly/next] `opts` is required. Please provide the options object."
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
const parsedOpinlyOptions = opinlyOptionsSchema.safeParse(opinlyOptions);
|
|
38
|
+
if (!parsedOpinlyOptions.success) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`[@opinly/next] Invalid options provided in next.config.js: ${parsedOpinlyOptions.error.message}`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const processRewrites = (userNextConfig, opinlyOptions) => {
|
|
45
|
+
const imagesPath = opinlyOptions.imagesPath;
|
|
46
|
+
if (!imagesPath.startsWith("/")) {
|
|
47
|
+
console.warn(
|
|
48
|
+
`[@opinly/next] You have provided a url for imagesPath. This is only valid for internal testing and rewrites will be skipped.`
|
|
49
|
+
);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const originalRewrites = userNextConfig.rewrites;
|
|
53
|
+
userNextConfig.rewrites = async () => {
|
|
54
|
+
const opinlyRewrite = {
|
|
55
|
+
source: `${opinlyOptions.imagesPath}/:path*`,
|
|
56
|
+
destination: `${opinlyOptions.cdnDomain || "https://cdn.opinly.ai"}/${opinlyOptions.cdnNamespace}/:path*`
|
|
57
|
+
};
|
|
58
|
+
const newRewrites = [opinlyRewrite];
|
|
59
|
+
if (opinlyOptions.pagesRouter) {
|
|
60
|
+
newRewrites.push({
|
|
61
|
+
source: "/sitemap.xml",
|
|
62
|
+
destination: "/sitemap"
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (typeof originalRewrites !== "function") {
|
|
66
|
+
return newRewrites;
|
|
67
|
+
}
|
|
68
|
+
const resolvedRewrites = await originalRewrites();
|
|
69
|
+
if (Array.isArray(resolvedRewrites)) {
|
|
70
|
+
return [...resolvedRewrites, opinlyRewrite];
|
|
71
|
+
} else {
|
|
72
|
+
return {
|
|
73
|
+
...resolvedRewrites,
|
|
74
|
+
beforeFiles: [...resolvedRewrites.beforeFiles || [], ...newRewrites]
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
function addEnvVars(userNextConfig, opinlyOptions) {
|
|
80
|
+
const opinlyEnvVars = {
|
|
81
|
+
OPINLY_IMAGES_PREFIX: opinlyOptions.imagesPath,
|
|
82
|
+
OPINLY_BLOG_PREFIX: opinlyOptions.blogPath,
|
|
83
|
+
OPINLY_SITE_NAME: opinlyOptions.companyName,
|
|
84
|
+
OPINLY_SITE_URL: opinlyOptions.siteUrl,
|
|
85
|
+
OPINLY_UNOPTIMIZED_IMAGES: opinlyOptions.unoptimizedImages ? "true" : void 0,
|
|
86
|
+
OPINLY_PAGES_ROUTER: opinlyOptions.pagesRouter ? "true" : void 0,
|
|
87
|
+
OPINLY_CATEGORY_PREFIX: opinlyOptions.categoryPrefix,
|
|
88
|
+
OPINLY_AUTHOR_PREFIX: opinlyOptions.authorPrefix,
|
|
89
|
+
OPINLY_TAG_PREFIX: opinlyOptions.tagPrefix
|
|
90
|
+
};
|
|
91
|
+
userNextConfig.env = {
|
|
92
|
+
...userNextConfig.env || {},
|
|
93
|
+
...opinlyEnvVars
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const withOpinlyConfig = (opinlyOptions) => (
|
|
97
|
+
// Generic over the config type so this composes with any Next version's
|
|
98
|
+
// `NextConfig` (the consumer's next may differ from the one this package was
|
|
99
|
+
// built against). We only read/write `env` and `rewrites` internally.
|
|
100
|
+
(nextConfig) => {
|
|
101
|
+
validateOpinlyOptions(opinlyOptions);
|
|
102
|
+
addEnvVars(nextConfig, opinlyOptions);
|
|
103
|
+
processRewrites(nextConfig, opinlyOptions);
|
|
104
|
+
return nextConfig;
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
export {
|
|
108
|
+
withOpinlyConfig
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config.ts"],"sourcesContent":["import { NextConfig } from \"next\";\nimport { Rewrite } from \"next/dist/lib/load-custom-routes\";\nimport type { OpinlyEnvVars } from \"./utils/sdk-config\";\nimport { z } from \"zod\";\n\ninterface WithOpinlyOptions {\n imagesPath: `/${string}`;\n blogPath: `/${string}`;\n companyName: string;\n cdnNamespace: string;\n siteUrl: string;\n unoptimizedImages?: boolean;\n /** URL segment categories live under (relative to blogPath). Default: bare. */\n categoryPrefix?: string;\n /** URL segment authors live under (relative to blogPath). Default: \"authors\". */\n authorPrefix?: string;\n /** URL segment tags live under (relative to blogPath). Default: \"tag\". */\n tagPrefix?: string;\n}\n\ntype ResolvedRewrites = ReturnType<\n NonNullable<Awaited<NextConfig[\"rewrites\"]>>\n>;\n\nconst opinlyOptionsSchema = z.object({\n imagesPath: z\n .string({})\n .refine(\n (val) => val.startsWith(\"/\") || z.string().url().safeParse(val).success,\n {\n message: \"imagesPath must start with a leading slash (e.g. '/images')\",\n }\n ),\n blogPath: z.string({}).startsWith(\"/\", {\n message: \"blogPath must start with a leading slash i.e. `/blog`\",\n }),\n companyName: z.string({\n required_error: \"companyName is required\",\n invalid_type_error: \"companyName must be a string\",\n }),\n cdnNamespace: z\n .string()\n .min(21, \"CDN namespace must be 21 characters long\")\n .max(21, \"CDN namespace must be 21 characters long\"),\n siteUrl: z.string().url({\n message: \"siteUrl must be a valid URL\",\n }),\n unoptimizedImages: z.boolean().optional(),\n categoryPrefix: z.string().optional(),\n authorPrefix: z.string().optional(),\n tagPrefix: z.string().optional(),\n cdnDomain: z\n .string({\n description:\n \"INTERNAL USE ONLY: The domain of the CDN. If not provided, the default domain will be used.\",\n })\n .url({\n message: \"cdnDomain must be a valid URL\",\n })\n .optional(),\n pagesRouter: z.boolean().optional(),\n});\n\ntype OpinlyOptions = z.infer<typeof opinlyOptionsSchema>;\n\nconst validateOpinlyOptions = (opinlyOptions: OpinlyOptions) => {\n if (!opinlyOptions) {\n throw new Error(\n \"[@opinly/next] `opts` is required. Please provide the options object.\"\n );\n }\n\n const parsedOpinlyOptions = opinlyOptionsSchema.safeParse(opinlyOptions);\n\n if (!parsedOpinlyOptions.success) {\n throw new Error(\n `[@opinly/next] Invalid options provided in next.config.js: ${parsedOpinlyOptions.error.message}`\n );\n }\n};\n\nconst processRewrites = (\n userNextConfig: NextConfig,\n opinlyOptions: OpinlyOptions\n): void => {\n const imagesPath = opinlyOptions.imagesPath;\n\n if (!imagesPath.startsWith(\"/\")) {\n console.warn(\n `[@opinly/next] You have provided a url for imagesPath. This is only valid for internal testing and rewrites will be skipped.`\n );\n\n return;\n }\n\n const originalRewrites = userNextConfig.rewrites;\n\n userNextConfig.rewrites = async () => {\n const opinlyRewrite = {\n source: `${opinlyOptions.imagesPath}/:path*`,\n destination: `${opinlyOptions.cdnDomain || \"https://cdn.opinly.ai\"}/${\n opinlyOptions.cdnNamespace\n }/:path*`,\n };\n\n const newRewrites = [opinlyRewrite];\n\n if (opinlyOptions.pagesRouter) {\n newRewrites.push({\n source: \"/sitemap.xml\",\n destination: \"/sitemap\",\n });\n }\n\n if (typeof originalRewrites !== \"function\") {\n return newRewrites;\n }\n\n const resolvedRewrites = await originalRewrites();\n\n if (Array.isArray(resolvedRewrites)) {\n return [...resolvedRewrites, opinlyRewrite];\n } else {\n return {\n ...resolvedRewrites,\n beforeFiles: [...(resolvedRewrites.beforeFiles || []), ...newRewrites],\n };\n }\n };\n};\n\nfunction addEnvVars(userNextConfig: NextConfig, opinlyOptions: OpinlyOptions) {\n const opinlyEnvVars: OpinlyEnvVars = {\n OPINLY_IMAGES_PREFIX: opinlyOptions.imagesPath,\n OPINLY_BLOG_PREFIX: opinlyOptions.blogPath,\n OPINLY_SITE_NAME: opinlyOptions.companyName,\n OPINLY_SITE_URL: opinlyOptions.siteUrl,\n OPINLY_UNOPTIMIZED_IMAGES: opinlyOptions.unoptimizedImages\n ? \"true\"\n : undefined,\n OPINLY_PAGES_ROUTER: opinlyOptions.pagesRouter ? \"true\" : undefined,\n OPINLY_CATEGORY_PREFIX: opinlyOptions.categoryPrefix,\n OPINLY_AUTHOR_PREFIX: opinlyOptions.authorPrefix,\n OPINLY_TAG_PREFIX: opinlyOptions.tagPrefix,\n };\n\n userNextConfig.env = {\n ...(userNextConfig.env || {}),\n ...opinlyEnvVars,\n };\n}\n\n/**\n * Modifies the passed in Next.js configuration with image rewrites and environment variables.\n *\n * @param nextConfig A Next.js configuration object, as usually exported in `next.config.js` or `next.config.mjs`.\n * @param opinlyOptions Additional options to configure Opinly.\n * @returns The modified config to be exported\n */\nexport const withOpinlyConfig =\n (opinlyOptions: OpinlyOptions) =>\n // Generic over the config type so this composes with any Next version's\n // `NextConfig` (the consumer's next may differ from the one this package was\n // built against). We only read/write `env` and `rewrites` internally.\n <T extends object>(nextConfig: T): T => {\n validateOpinlyOptions(opinlyOptions);\n\n addEnvVars(nextConfig as NextConfig, opinlyOptions);\n\n processRewrites(nextConfig as NextConfig, opinlyOptions);\n\n return nextConfig;\n };\n"],"mappings":"AAGA,SAAS,SAAS;AAqBlB,MAAM,sBAAsB,EAAE,OAAO;AAAA,EACnC,YAAY,EACT,OAAO,CAAC,CAAC,EACT;AAAA,IACC,CAAC,QAAQ,IAAI,WAAW,GAAG,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,GAAG,EAAE;AAAA,IAChE;AAAA,MACE,SAAS;AAAA,IACX;AAAA,EACF;AAAA,EACF,UAAU,EAAE,OAAO,CAAC,CAAC,EAAE,WAAW,KAAK;AAAA,IACrC,SAAS;AAAA,EACX,CAAC;AAAA,EACD,aAAa,EAAE,OAAO;AAAA,IACpB,gBAAgB;AAAA,IAChB,oBAAoB;AAAA,EACtB,CAAC;AAAA,EACD,cAAc,EACX,OAAO,EACP,IAAI,IAAI,0CAA0C,EAClD,IAAI,IAAI,0CAA0C;AAAA,EACrD,SAAS,EAAE,OAAO,EAAE,IAAI;AAAA,IACtB,SAAS;AAAA,EACX,CAAC;AAAA,EACD,mBAAmB,EAAE,QAAQ,EAAE,SAAS;AAAA,EACxC,gBAAgB,EAAE,OAAO,EAAE,SAAS;AAAA,EACpC,cAAc,EAAE,OAAO,EAAE,SAAS;AAAA,EAClC,WAAW,EAAE,OAAO,EAAE,SAAS;AAAA,EAC/B,WAAW,EACR,OAAO;AAAA,IACN,aACE;AAAA,EACJ,CAAC,EACA,IAAI;AAAA,IACH,SAAS;AAAA,EACX,CAAC,EACA,SAAS;AAAA,EACZ,aAAa,EAAE,QAAQ,EAAE,SAAS;AACpC,CAAC;AAID,MAAM,wBAAwB,CAAC,kBAAiC;AAC9D,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,sBAAsB,oBAAoB,UAAU,aAAa;AAEvE,MAAI,CAAC,oBAAoB,SAAS;AAChC,UAAM,IAAI;AAAA,MACR,8DAA8D,oBAAoB,MAAM,OAAO;AAAA,IACjG;AAAA,EACF;AACF;AAEA,MAAM,kBAAkB,CACtB,gBACA,kBACS;AACT,QAAM,aAAa,cAAc;AAEjC,MAAI,CAAC,WAAW,WAAW,GAAG,GAAG;AAC/B,YAAQ;AAAA,MACN;AAAA,IACF;AAEA;AAAA,EACF;AAEA,QAAM,mBAAmB,eAAe;AAExC,iBAAe,WAAW,YAAY;AACpC,UAAM,gBAAgB;AAAA,MACpB,QAAQ,GAAG,cAAc,UAAU;AAAA,MACnC,aAAa,GAAG,cAAc,aAAa,uBAAuB,IAChE,cAAc,YAChB;AAAA,IACF;AAEA,UAAM,cAAc,CAAC,aAAa;AAElC,QAAI,cAAc,aAAa;AAC7B,kBAAY,KAAK;AAAA,QACf,QAAQ;AAAA,QACR,aAAa;AAAA,MACf,CAAC;AAAA,IACH;AAEA,QAAI,OAAO,qBAAqB,YAAY;AAC1C,aAAO;AAAA,IACT;AAEA,UAAM,mBAAmB,MAAM,iBAAiB;AAEhD,QAAI,MAAM,QAAQ,gBAAgB,GAAG;AACnC,aAAO,CAAC,GAAG,kBAAkB,aAAa;AAAA,IAC5C,OAAO;AACL,aAAO;AAAA,QACL,GAAG;AAAA,QACH,aAAa,CAAC,GAAI,iBAAiB,eAAe,CAAC,GAAI,GAAG,WAAW;AAAA,MACvE;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,WAAW,gBAA4B,eAA8B;AAC5E,QAAM,gBAA+B;AAAA,IACnC,sBAAsB,cAAc;AAAA,IACpC,oBAAoB,cAAc;AAAA,IAClC,kBAAkB,cAAc;AAAA,IAChC,iBAAiB,cAAc;AAAA,IAC/B,2BAA2B,cAAc,oBACrC,SACA;AAAA,IACJ,qBAAqB,cAAc,cAAc,SAAS;AAAA,IAC1D,wBAAwB,cAAc;AAAA,IACtC,sBAAsB,cAAc;AAAA,IACpC,mBAAmB,cAAc;AAAA,EACnC;AAEA,iBAAe,MAAM;AAAA,IACnB,GAAI,eAAe,OAAO,CAAC;AAAA,IAC3B,GAAG;AAAA,EACL;AACF;AASO,MAAM,mBACX,CAAC;AAAA;AAAA;AAAA;AAAA,EAID,CAAmB,eAAqB;AACtC,0BAAsB,aAAa;AAEnC,eAAW,YAA0B,aAAa;AAElD,oBAAgB,YAA0B,aAAa;AAEvD,WAAO;AAAA,EACT;AAAA;","names":[]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var index_exports = {};
|
|
20
|
+
__export(index_exports, {
|
|
21
|
+
OpinlyJsonLd: () => import_json_ld.OpinlyJsonLd,
|
|
22
|
+
buildBlogPostingJsonLd: () => import_json_ld.buildBlogPostingJsonLd,
|
|
23
|
+
buildFaqJsonLd: () => import_json_ld.buildFaqJsonLd,
|
|
24
|
+
cn: () => import_merge.cn,
|
|
25
|
+
formatDate: () => import_dates.formatDate,
|
|
26
|
+
generateOpinlyMetadata: () => import_generate_metadata.generateOpinlyMetadata,
|
|
27
|
+
generateSiteMapXML: () => import_generate_sitemap_xml.generateSiteMapXML,
|
|
28
|
+
opinlyConfig: () => import_sdk_config.opinlyConfig,
|
|
29
|
+
setOpinlyConfig: () => import_sdk_config.setOpinlyConfig,
|
|
30
|
+
withOpinlyConfig: () => import_config.withOpinlyConfig
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(index_exports);
|
|
33
|
+
var import_config = require("./config");
|
|
34
|
+
var import_generate_metadata = require("./utils/generate-metadata");
|
|
35
|
+
var import_json_ld = require("./json-ld");
|
|
36
|
+
var import_sdk_config = require("./utils/sdk-config");
|
|
37
|
+
var import_generate_sitemap_xml = require("./utils/generate-sitemap-xml");
|
|
38
|
+
var import_dates = require("./utils/dates");
|
|
39
|
+
var import_merge = require("./utils/merge");
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
OpinlyJsonLd,
|
|
43
|
+
buildBlogPostingJsonLd,
|
|
44
|
+
buildFaqJsonLd,
|
|
45
|
+
cn,
|
|
46
|
+
formatDate,
|
|
47
|
+
generateOpinlyMetadata,
|
|
48
|
+
generateSiteMapXML,
|
|
49
|
+
opinlyConfig,
|
|
50
|
+
setOpinlyConfig,
|
|
51
|
+
withOpinlyConfig
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { withOpinlyConfig } from \"./config\";\nexport { generateOpinlyMetadata } from \"./utils/generate-metadata\";\nexport {\n OpinlyJsonLd,\n buildBlogPostingJsonLd,\n buildFaqJsonLd,\n} from \"./json-ld\";\nexport {\n opinlyConfig,\n setOpinlyConfig,\n type OpinlyEnvVars,\n} from \"./utils/sdk-config\";\nexport { generateSiteMapXML } from \"./utils/generate-sitemap-xml\";\nexport { formatDate } from \"./utils/dates\";\nexport { cn } from \"./utils/merge\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AACjC,+BAAuC;AACvC,qBAIO;AACP,wBAIO;AACP,kCAAmC;AACnC,mBAA2B;AAC3B,mBAAmB;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { withOpinlyConfig } from './config.cjs';
|
|
2
|
+
export { generateOpinlyMetadata } from './utils/generate-metadata.cjs';
|
|
3
|
+
export { OpinlyJsonLd, buildBlogPostingJsonLd, buildFaqJsonLd } from './json-ld.cjs';
|
|
4
|
+
export { OpinlyEnvVars, opinlyConfig, setOpinlyConfig } from './utils/sdk-config.cjs';
|
|
5
|
+
export { generateSiteMapXML } from './utils/generate-sitemap-xml.cjs';
|
|
6
|
+
export { formatDate } from './utils/dates.cjs';
|
|
7
|
+
export { cn } from './utils/merge.cjs';
|
|
8
|
+
import 'zod';
|
|
9
|
+
import 'next';
|
|
10
|
+
import '@opinly/shared';
|
|
11
|
+
import 'schema-dts';
|
|
12
|
+
import 'react/jsx-runtime';
|
|
13
|
+
import '@opinly/backend';
|
|
14
|
+
import 'clsx';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { withOpinlyConfig } from './config.js';
|
|
2
|
+
export { generateOpinlyMetadata } from './utils/generate-metadata.js';
|
|
3
|
+
export { OpinlyJsonLd, buildBlogPostingJsonLd, buildFaqJsonLd } from './json-ld.js';
|
|
4
|
+
export { OpinlyEnvVars, opinlyConfig, setOpinlyConfig } from './utils/sdk-config.js';
|
|
5
|
+
export { generateSiteMapXML } from './utils/generate-sitemap-xml.js';
|
|
6
|
+
export { formatDate } from './utils/dates.js';
|
|
7
|
+
export { cn } from './utils/merge.js';
|
|
8
|
+
import 'zod';
|
|
9
|
+
import 'next';
|
|
10
|
+
import '@opinly/shared';
|
|
11
|
+
import 'schema-dts';
|
|
12
|
+
import 'react/jsx-runtime';
|
|
13
|
+
import '@opinly/backend';
|
|
14
|
+
import 'clsx';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { withOpinlyConfig } from "./config";
|
|
2
|
+
import { generateOpinlyMetadata } from "./utils/generate-metadata";
|
|
3
|
+
import {
|
|
4
|
+
OpinlyJsonLd,
|
|
5
|
+
buildBlogPostingJsonLd,
|
|
6
|
+
buildFaqJsonLd
|
|
7
|
+
} from "./json-ld";
|
|
8
|
+
import {
|
|
9
|
+
opinlyConfig,
|
|
10
|
+
setOpinlyConfig
|
|
11
|
+
} from "./utils/sdk-config";
|
|
12
|
+
import { generateSiteMapXML } from "./utils/generate-sitemap-xml";
|
|
13
|
+
import { formatDate } from "./utils/dates";
|
|
14
|
+
import { cn } from "./utils/merge";
|
|
15
|
+
export {
|
|
16
|
+
OpinlyJsonLd,
|
|
17
|
+
buildBlogPostingJsonLd,
|
|
18
|
+
buildFaqJsonLd,
|
|
19
|
+
cn,
|
|
20
|
+
formatDate,
|
|
21
|
+
generateOpinlyMetadata,
|
|
22
|
+
generateSiteMapXML,
|
|
23
|
+
opinlyConfig,
|
|
24
|
+
setOpinlyConfig,
|
|
25
|
+
withOpinlyConfig
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { withOpinlyConfig } from \"./config\";\nexport { generateOpinlyMetadata } from \"./utils/generate-metadata\";\nexport {\n OpinlyJsonLd,\n buildBlogPostingJsonLd,\n buildFaqJsonLd,\n} from \"./json-ld\";\nexport {\n opinlyConfig,\n setOpinlyConfig,\n type OpinlyEnvVars,\n} from \"./utils/sdk-config\";\nexport { generateSiteMapXML } from \"./utils/generate-sitemap-xml\";\nexport { formatDate } from \"./utils/dates\";\nexport { cn } from \"./utils/merge\";\n"],"mappings":"AAAA,SAAS,wBAAwB;AACjC,SAAS,8BAA8B;AACvC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,0BAA0B;AACnC,SAAS,kBAAkB;AAC3B,SAAS,UAAU;","names":[]}
|
package/dist/json-ld.cjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var json_ld_exports = {};
|
|
20
|
+
__export(json_ld_exports, {
|
|
21
|
+
OpinlyJsonLd: () => OpinlyJsonLd,
|
|
22
|
+
buildBlogPostingJsonLd: () => buildBlogPostingJsonLd,
|
|
23
|
+
buildFaqJsonLd: () => buildFaqJsonLd
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(json_ld_exports);
|
|
26
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
27
|
+
var import_shared = require("@opinly/shared");
|
|
28
|
+
var import_sdk_config = require("./utils/sdk-config");
|
|
29
|
+
const rendererConfig = () => ({
|
|
30
|
+
imagesPrefix: import_sdk_config.opinlyConfig.imagesPrefix,
|
|
31
|
+
siteUrl: import_sdk_config.opinlyConfig.siteUrl,
|
|
32
|
+
blogPrefix: import_sdk_config.opinlyConfig.blogPrefix,
|
|
33
|
+
siteName: import_sdk_config.opinlyConfig.siteName
|
|
34
|
+
});
|
|
35
|
+
const OpinlyJsonLd = ({ data }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
36
|
+
"script",
|
|
37
|
+
{
|
|
38
|
+
type: "application/ld+json",
|
|
39
|
+
dangerouslySetInnerHTML: { __html: JSON.stringify(data) }
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
const buildBlogPostingJsonLd = (post) => (0, import_shared.buildBlogPostingJsonLd)(
|
|
43
|
+
{
|
|
44
|
+
title: post.title,
|
|
45
|
+
description: post.description,
|
|
46
|
+
content: post.content,
|
|
47
|
+
firstPublishedAt: post.firstPublishedAt,
|
|
48
|
+
modifiedAt: post.modifiedAt,
|
|
49
|
+
author: post.author ? { name: post.author.name } : null,
|
|
50
|
+
imageFileKey: post.titleFile?.fileKey
|
|
51
|
+
},
|
|
52
|
+
rendererConfig()
|
|
53
|
+
);
|
|
54
|
+
const buildFaqJsonLd = import_shared.buildFaqJsonLd;
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
OpinlyJsonLd,
|
|
58
|
+
buildBlogPostingJsonLd,
|
|
59
|
+
buildFaqJsonLd
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=json-ld.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/json-ld.tsx"],"sourcesContent":["import React from \"react\";\nimport {\n buildBlogPostingJsonLd as coreBlogPostingJsonLd,\n buildFaqJsonLd as coreFaqJsonLd,\n type OpinlyNode,\n type OpinlyConfig,\n} from \"@opinly/shared\";\nimport type { FullPost } from \"@opinly/backend\";\nimport { opinlyConfig } from \"./utils/sdk-config\";\n\nconst rendererConfig = (): OpinlyConfig => ({\n imagesPrefix: opinlyConfig.imagesPrefix,\n siteUrl: opinlyConfig.siteUrl,\n blogPrefix: opinlyConfig.blogPrefix,\n siteName: opinlyConfig.siteName,\n});\n\n/** Renders a JSON-LD `<script>` tag (the Next-specific bit). */\nexport const OpinlyJsonLd = ({ data }: { data: object }) => (\n <script\n type=\"application/ld+json\"\n dangerouslySetInnerHTML={{ __html: JSON.stringify(data) }}\n />\n);\n\n/** BlogPosting structured data from a resolved post. Delegates to @opinly/shared. */\nexport const buildBlogPostingJsonLd = (post: FullPost) =>\n coreBlogPostingJsonLd(\n {\n title: post.title,\n description: post.description,\n content: post.content as OpinlyNode,\n firstPublishedAt: post.firstPublishedAt,\n modifiedAt: post.modifiedAt,\n author: post.author ? { name: post.author.name } : null,\n imageFileKey: post.titleFile?.fileKey,\n },\n rendererConfig(),\n );\n\n/** FAQPage structured data. Re-exported from @opinly/shared. */\nexport const buildFaqJsonLd = coreFaqJsonLd;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBE;AAlBF,oBAKO;AAEP,wBAA6B;AAE7B,MAAM,iBAAiB,OAAqB;AAAA,EAC1C,cAAc,+BAAa;AAAA,EAC3B,SAAS,+BAAa;AAAA,EACtB,YAAY,+BAAa;AAAA,EACzB,UAAU,+BAAa;AACzB;AAGO,MAAM,eAAe,CAAC,EAAE,KAAK,MAClC;AAAA,EAAC;AAAA;AAAA,IACC,MAAK;AAAA,IACL,yBAAyB,EAAE,QAAQ,KAAK,UAAU,IAAI,EAAE;AAAA;AAC1D;AAIK,MAAM,yBAAyB,CAAC,aACrC,cAAAA;AAAA,EACE;AAAA,IACE,OAAO,KAAK;AAAA,IACZ,aAAa,KAAK;AAAA,IAClB,SAAS,KAAK;AAAA,IACd,kBAAkB,KAAK;AAAA,IACvB,YAAY,KAAK;AAAA,IACjB,QAAQ,KAAK,SAAS,EAAE,MAAM,KAAK,OAAO,KAAK,IAAI;AAAA,IACnD,cAAc,KAAK,WAAW;AAAA,EAChC;AAAA,EACA,eAAe;AACjB;AAGK,MAAM,iBAAiB,cAAAC;","names":["coreBlogPostingJsonLd","coreFaqJsonLd"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as schema_dts from 'schema-dts';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
import { FullPost } from '@opinly/backend';
|
|
4
|
+
|
|
5
|
+
/** Renders a JSON-LD `<script>` tag (the Next-specific bit). */
|
|
6
|
+
declare const OpinlyJsonLd: ({ data }: {
|
|
7
|
+
data: object;
|
|
8
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
9
|
+
/** BlogPosting structured data from a resolved post. Delegates to @opinly/shared. */
|
|
10
|
+
declare const buildBlogPostingJsonLd: (post: FullPost) => schema_dts.WithContext<schema_dts.BlogPosting>;
|
|
11
|
+
/** FAQPage structured data. Re-exported from @opinly/shared. */
|
|
12
|
+
declare const buildFaqJsonLd: (faqs: {
|
|
13
|
+
question: string;
|
|
14
|
+
answer: string;
|
|
15
|
+
}[]) => schema_dts.WithContext<schema_dts.FAQPage>;
|
|
16
|
+
|
|
17
|
+
export { OpinlyJsonLd, buildBlogPostingJsonLd, buildFaqJsonLd };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as schema_dts from 'schema-dts';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
import { FullPost } from '@opinly/backend';
|
|
4
|
+
|
|
5
|
+
/** Renders a JSON-LD `<script>` tag (the Next-specific bit). */
|
|
6
|
+
declare const OpinlyJsonLd: ({ data }: {
|
|
7
|
+
data: object;
|
|
8
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
9
|
+
/** BlogPosting structured data from a resolved post. Delegates to @opinly/shared. */
|
|
10
|
+
declare const buildBlogPostingJsonLd: (post: FullPost) => schema_dts.WithContext<schema_dts.BlogPosting>;
|
|
11
|
+
/** FAQPage structured data. Re-exported from @opinly/shared. */
|
|
12
|
+
declare const buildFaqJsonLd: (faqs: {
|
|
13
|
+
question: string;
|
|
14
|
+
answer: string;
|
|
15
|
+
}[]) => schema_dts.WithContext<schema_dts.FAQPage>;
|
|
16
|
+
|
|
17
|
+
export { OpinlyJsonLd, buildBlogPostingJsonLd, buildFaqJsonLd };
|
package/dist/json-ld.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
buildBlogPostingJsonLd as coreBlogPostingJsonLd,
|
|
4
|
+
buildFaqJsonLd as coreFaqJsonLd
|
|
5
|
+
} from "@opinly/shared";
|
|
6
|
+
import { opinlyConfig } from "./utils/sdk-config";
|
|
7
|
+
const rendererConfig = () => ({
|
|
8
|
+
imagesPrefix: opinlyConfig.imagesPrefix,
|
|
9
|
+
siteUrl: opinlyConfig.siteUrl,
|
|
10
|
+
blogPrefix: opinlyConfig.blogPrefix,
|
|
11
|
+
siteName: opinlyConfig.siteName
|
|
12
|
+
});
|
|
13
|
+
const OpinlyJsonLd = ({ data }) => /* @__PURE__ */ jsx(
|
|
14
|
+
"script",
|
|
15
|
+
{
|
|
16
|
+
type: "application/ld+json",
|
|
17
|
+
dangerouslySetInnerHTML: { __html: JSON.stringify(data) }
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
const buildBlogPostingJsonLd = (post) => coreBlogPostingJsonLd(
|
|
21
|
+
{
|
|
22
|
+
title: post.title,
|
|
23
|
+
description: post.description,
|
|
24
|
+
content: post.content,
|
|
25
|
+
firstPublishedAt: post.firstPublishedAt,
|
|
26
|
+
modifiedAt: post.modifiedAt,
|
|
27
|
+
author: post.author ? { name: post.author.name } : null,
|
|
28
|
+
imageFileKey: post.titleFile?.fileKey
|
|
29
|
+
},
|
|
30
|
+
rendererConfig()
|
|
31
|
+
);
|
|
32
|
+
const buildFaqJsonLd = coreFaqJsonLd;
|
|
33
|
+
export {
|
|
34
|
+
OpinlyJsonLd,
|
|
35
|
+
buildBlogPostingJsonLd,
|
|
36
|
+
buildFaqJsonLd
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=json-ld.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/json-ld.tsx"],"sourcesContent":["import React from \"react\";\nimport {\n buildBlogPostingJsonLd as coreBlogPostingJsonLd,\n buildFaqJsonLd as coreFaqJsonLd,\n type OpinlyNode,\n type OpinlyConfig,\n} from \"@opinly/shared\";\nimport type { FullPost } from \"@opinly/backend\";\nimport { opinlyConfig } from \"./utils/sdk-config\";\n\nconst rendererConfig = (): OpinlyConfig => ({\n imagesPrefix: opinlyConfig.imagesPrefix,\n siteUrl: opinlyConfig.siteUrl,\n blogPrefix: opinlyConfig.blogPrefix,\n siteName: opinlyConfig.siteName,\n});\n\n/** Renders a JSON-LD `<script>` tag (the Next-specific bit). */\nexport const OpinlyJsonLd = ({ data }: { data: object }) => (\n <script\n type=\"application/ld+json\"\n dangerouslySetInnerHTML={{ __html: JSON.stringify(data) }}\n />\n);\n\n/** BlogPosting structured data from a resolved post. Delegates to @opinly/shared. */\nexport const buildBlogPostingJsonLd = (post: FullPost) =>\n coreBlogPostingJsonLd(\n {\n title: post.title,\n description: post.description,\n content: post.content as OpinlyNode,\n firstPublishedAt: post.firstPublishedAt,\n modifiedAt: post.modifiedAt,\n author: post.author ? { name: post.author.name } : null,\n imageFileKey: post.titleFile?.fileKey,\n },\n rendererConfig(),\n );\n\n/** FAQPage structured data. Re-exported from @opinly/shared. */\nexport const buildFaqJsonLd = coreFaqJsonLd;\n"],"mappings":"AAmBE;AAlBF;AAAA,EACE,0BAA0B;AAAA,EAC1B,kBAAkB;AAAA,OAGb;AAEP,SAAS,oBAAoB;AAE7B,MAAM,iBAAiB,OAAqB;AAAA,EAC1C,cAAc,aAAa;AAAA,EAC3B,SAAS,aAAa;AAAA,EACtB,YAAY,aAAa;AAAA,EACzB,UAAU,aAAa;AACzB;AAGO,MAAM,eAAe,CAAC,EAAE,KAAK,MAClC;AAAA,EAAC;AAAA;AAAA,IACC,MAAK;AAAA,IACL,yBAAyB,EAAE,QAAQ,KAAK,UAAU,IAAI,EAAE;AAAA;AAC1D;AAIK,MAAM,yBAAyB,CAAC,SACrC;AAAA,EACE;AAAA,IACE,OAAO,KAAK;AAAA,IACZ,aAAa,KAAK;AAAA,IAClB,SAAS,KAAK;AAAA,IACd,kBAAkB,KAAK;AAAA,IACvB,YAAY,KAAK;AAAA,IACjB,QAAQ,KAAK,SAAS,EAAE,MAAM,KAAK,OAAO,KAAK,IAAI;AAAA,IACnD,cAAc,KAAK,WAAW;AAAA,EAChC;AAAA,EACA,eAAe;AACjB;AAGK,MAAM,iBAAiB;","names":[]}
|