@leadcms/sdk 1.2.85-pre
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/LICENSE +21 -0
- package/README.md +261 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +205 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/cms.d.ts +104 -0
- package/dist/lib/cms.d.ts.map +1 -0
- package/dist/lib/cms.js +532 -0
- package/dist/lib/cms.js.map +1 -0
- package/dist/lib/config.d.ts +45 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +194 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/scripts/fetch-leadcms-content.mjs +361 -0
- package/dist/scripts/generate-env-js.mjs +24 -0
- package/dist/scripts/leadcms-helpers.mjs +208 -0
- package/dist/scripts/sse-watcher.mjs +325 -0
- package/dist/templates/docker/Dockerfile +34 -0
- package/dist/templates/docker/nginx.conf +70 -0
- package/dist/templates/docker/preview/Dockerfile +75 -0
- package/dist/templates/docker/preview/nginx.conf +128 -0
- package/dist/templates/docker/preview/supervisord.conf +63 -0
- package/dist/templates/scripts/inject-runtime-env.sh +33 -0
- package/leadcms.config.json.sample +8 -0
- package/package.json +76 -0
package/dist/lib/cms.js
ADDED
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DEFAULT_LANGUAGE = void 0;
|
|
7
|
+
exports.getAvailableLanguages = getAvailableLanguages;
|
|
8
|
+
exports.getContentDirForLocale = getContentDirForLocale;
|
|
9
|
+
exports.getAllContentSlugsForLocale = getAllContentSlugsForLocale;
|
|
10
|
+
exports.getCMSContentBySlugForLocaleWithDraftSupport = getCMSContentBySlugForLocaleWithDraftSupport;
|
|
11
|
+
exports.getCMSContentBySlugForLocale = getCMSContentBySlugForLocale;
|
|
12
|
+
exports.getContentTranslations = getContentTranslations;
|
|
13
|
+
exports.getAllContentRoutes = getAllContentRoutes;
|
|
14
|
+
exports.extractUserUidFromSlug = extractUserUidFromSlug;
|
|
15
|
+
exports.getAllContentSlugs = getAllContentSlugs;
|
|
16
|
+
exports.getCMSContentBySlug = getCMSContentBySlug;
|
|
17
|
+
exports.getHeaderConfig = getHeaderConfig;
|
|
18
|
+
exports.getFooterConfig = getFooterConfig;
|
|
19
|
+
exports.getLocaleFromPath = getLocaleFromPath;
|
|
20
|
+
exports.makeLocaleAwareLink = makeLocaleAwareLink;
|
|
21
|
+
const fs_1 = __importDefault(require("fs"));
|
|
22
|
+
const path_1 = __importDefault(require("path"));
|
|
23
|
+
const gray_matter_1 = __importDefault(require("gray-matter"));
|
|
24
|
+
const config_1 = require("./config");
|
|
25
|
+
// Default language - now configurable via configuration system
|
|
26
|
+
exports.DEFAULT_LANGUAGE = "en";
|
|
27
|
+
/**
|
|
28
|
+
* Helper to get configuration with fallbacks
|
|
29
|
+
*/
|
|
30
|
+
function getConfigWithDefaults(configOptions) {
|
|
31
|
+
try {
|
|
32
|
+
return (0, config_1.getConfig)(configOptions);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
// If config loading fails, return minimal config with environment fallbacks
|
|
36
|
+
return {
|
|
37
|
+
url: process.env.LEADCMS_URL || process.env.NEXT_PUBLIC_LEADCMS_URL || "",
|
|
38
|
+
apiKey: process.env.LEADCMS_API_KEY || "",
|
|
39
|
+
defaultLanguage: process.env.LEADCMS_DEFAULT_LANGUAGE || process.env.NEXT_PUBLIC_LEADCMS_DEFAULT_LANGUAGE || exports.DEFAULT_LANGUAGE,
|
|
40
|
+
contentDir: ".leadcms/content",
|
|
41
|
+
mediaDir: "public/media",
|
|
42
|
+
enableDrafts: false,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get all available languages from the content directory structure
|
|
48
|
+
*/
|
|
49
|
+
function getAvailableLanguages(contentDir, configOptions) {
|
|
50
|
+
const config = getConfigWithDefaults(configOptions);
|
|
51
|
+
const defaultLanguage = config.defaultLanguage || exports.DEFAULT_LANGUAGE;
|
|
52
|
+
const actualContentDir = contentDir || config.contentDir;
|
|
53
|
+
if (!actualContentDir) {
|
|
54
|
+
return [defaultLanguage];
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const entries = fs_1.default.readdirSync(actualContentDir, { withFileTypes: true });
|
|
58
|
+
const languages = [defaultLanguage]; // Always include default language
|
|
59
|
+
for (const entry of entries) {
|
|
60
|
+
if (entry.isDirectory() && entry.name.length === 2) {
|
|
61
|
+
// Assume 2-character directory names are language codes
|
|
62
|
+
if (!languages.includes(entry.name)) {
|
|
63
|
+
languages.push(entry.name);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return languages.sort();
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return [defaultLanguage];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get content directory for a specific locale
|
|
75
|
+
*/
|
|
76
|
+
function getContentDirForLocale(contentDir, locale, configOptions) {
|
|
77
|
+
const config = getConfigWithDefaults(configOptions);
|
|
78
|
+
const defaultLanguage = config.defaultLanguage || exports.DEFAULT_LANGUAGE;
|
|
79
|
+
if (locale === defaultLanguage) {
|
|
80
|
+
return contentDir;
|
|
81
|
+
}
|
|
82
|
+
return path_1.default.join(contentDir, locale);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get all content slugs for a specific locale with draft filtering options
|
|
86
|
+
* @param contentDir - Content directory path
|
|
87
|
+
* @param locale - Locale code
|
|
88
|
+
* @param contentTypes - Optional array of content types to filter
|
|
89
|
+
* @param includeDrafts - Whether to include draft content (default: null = false)
|
|
90
|
+
* @param draftUserUid - Specific user UID for draft content (only relevant if includeDrafts is true)
|
|
91
|
+
*/
|
|
92
|
+
function getAllContentSlugsForLocale(contentDir, locale, contentTypes, includeDrafts, draftUserUid) {
|
|
93
|
+
const localeContentDir = getContentDirForLocale(contentDir, locale);
|
|
94
|
+
let slugs;
|
|
95
|
+
if (locale === exports.DEFAULT_LANGUAGE) {
|
|
96
|
+
// For default language, we need to exclude language subdirectories
|
|
97
|
+
slugs = getAllContentSlugsExcludingLanguageDirs(localeContentDir, contentTypes, contentDir);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// For other languages, just get all content from their directory
|
|
101
|
+
slugs = getAllContentSlugs(localeContentDir, contentTypes);
|
|
102
|
+
}
|
|
103
|
+
// Apply draft filtering logic
|
|
104
|
+
return applyDraftFiltering(slugs, includeDrafts, draftUserUid);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Apply draft filtering logic to a list of slugs
|
|
108
|
+
* @param slugs - Array of all slugs
|
|
109
|
+
* @param includeDrafts - Whether to include draft content (null/false = filter out drafts)
|
|
110
|
+
* @param draftUserUid - Specific user UID for draft content (only relevant if includeDrafts is true)
|
|
111
|
+
*/
|
|
112
|
+
function applyDraftFiltering(slugs, includeDrafts, draftUserUid) {
|
|
113
|
+
// If includeDrafts is false or null, filter out all draft content
|
|
114
|
+
if (!includeDrafts) {
|
|
115
|
+
return filterOutDraftSlugs(slugs);
|
|
116
|
+
}
|
|
117
|
+
// If includeDrafts is true but no specific user UID, return all slugs as-is
|
|
118
|
+
if (!draftUserUid) {
|
|
119
|
+
return slugs;
|
|
120
|
+
}
|
|
121
|
+
// If includeDrafts is true and draftUserUid is specified,
|
|
122
|
+
// return base content with user's drafts overriding the originals
|
|
123
|
+
return getBaseContentWithUserDraftOverrides(slugs, draftUserUid);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Filter out draft slugs (those that have a corresponding base slug)
|
|
127
|
+
* Uses GUID pattern detection since userUid is always a GUID
|
|
128
|
+
*/
|
|
129
|
+
function filterOutDraftSlugs(slugs) {
|
|
130
|
+
// GUID pattern: 8-4-4-4-12 hexadecimal characters with a preceding dash
|
|
131
|
+
// Example: some-slug-550e8400-e29b-41d4-a716-446655440000
|
|
132
|
+
const draftSlugPattern = /-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
133
|
+
return slugs.filter(slug => {
|
|
134
|
+
const isDraft = draftSlugPattern.test(slug);
|
|
135
|
+
return !isDraft;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get base content slugs with user-specific draft overrides
|
|
140
|
+
* Returns only the user's draft versions when they exist, otherwise the base content
|
|
141
|
+
*/
|
|
142
|
+
function getBaseContentWithUserDraftOverrides(slugs, draftUserUid) {
|
|
143
|
+
// First, get all base slugs (non-draft)
|
|
144
|
+
const baseSlugs = filterOutDraftSlugs(slugs);
|
|
145
|
+
// For each base slug, check if user has a draft version and prefer it
|
|
146
|
+
const result = [];
|
|
147
|
+
for (const baseSlug of baseSlugs) {
|
|
148
|
+
const userDraftSlug = `${baseSlug}-${draftUserUid}`;
|
|
149
|
+
// If user has a draft version, use it; otherwise use the base version
|
|
150
|
+
if (slugs.includes(userDraftSlug)) {
|
|
151
|
+
result.push(userDraftSlug);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
result.push(baseSlug);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
function getAllContentSlugsExcludingLanguageDirs(contentDir, contentTypes, rootContentDir) {
|
|
160
|
+
// Get available languages from the root content directory to know which directories to exclude
|
|
161
|
+
const availableLanguages = rootContentDir
|
|
162
|
+
? getAvailableLanguages(rootContentDir)
|
|
163
|
+
: [exports.DEFAULT_LANGUAGE];
|
|
164
|
+
function walk(dir, prefix = "") {
|
|
165
|
+
const entries = fs_1.default.readdirSync(dir, { withFileTypes: true });
|
|
166
|
+
const slugs = [];
|
|
167
|
+
for (const entry of entries) {
|
|
168
|
+
if (entry.isDirectory()) {
|
|
169
|
+
// Skip language directories when we're in the root content directory
|
|
170
|
+
if (prefix === "" &&
|
|
171
|
+
availableLanguages.includes(entry.name) &&
|
|
172
|
+
entry.name !== exports.DEFAULT_LANGUAGE) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const subSlugs = walk(path_1.default.join(dir, entry.name), prefix ? `${prefix}/${entry.name}` : entry.name);
|
|
176
|
+
slugs.push(...subSlugs);
|
|
177
|
+
}
|
|
178
|
+
else if (entry.isFile() && (entry.name.endsWith(".mdx") || entry.name.endsWith(".json"))) {
|
|
179
|
+
const ext = entry.name.endsWith(".mdx") ? ".mdx" : ".json";
|
|
180
|
+
const slug = (prefix ? `${prefix}/` : "") + entry.name.replace(new RegExp(`\\${ext}$`), "");
|
|
181
|
+
// If content types filter is provided, check the file's type
|
|
182
|
+
if (contentTypes && contentTypes.length > 0) {
|
|
183
|
+
const filePath = path_1.default.join(dir, entry.name);
|
|
184
|
+
try {
|
|
185
|
+
const fileType = getFileTypeOptimized(filePath, ext);
|
|
186
|
+
// Only include if the type matches the filter
|
|
187
|
+
if (fileType && contentTypes.includes(fileType)) {
|
|
188
|
+
slugs.push(slug);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
// Skip files that can't be parsed
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
// No filter, include all files
|
|
198
|
+
slugs.push(slug);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return slugs;
|
|
203
|
+
}
|
|
204
|
+
return walk(contentDir);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get content by slug for a specific locale with optional draft support
|
|
208
|
+
* @param slug - Content slug
|
|
209
|
+
* @param contentDir - Content directory path
|
|
210
|
+
* @param locale - Locale code
|
|
211
|
+
* @param userUid - Optional user UID for draft content
|
|
212
|
+
*/
|
|
213
|
+
function getCMSContentBySlugForLocaleWithDraftSupport(slug, contentDir, locale, userUid) {
|
|
214
|
+
// If userUid is provided and this isn't already a draft slug, try draft version first
|
|
215
|
+
if (userUid && !extractUserUidFromSlug(slug)) {
|
|
216
|
+
const draftSlug = `${slug}-${userUid}`;
|
|
217
|
+
const draftContent = getCMSContentBySlugForLocale(draftSlug, contentDir, locale);
|
|
218
|
+
if (draftContent) {
|
|
219
|
+
return draftContent;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// Fall back to regular content
|
|
223
|
+
return getCMSContentBySlugForLocale(slug, contentDir, locale);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Get content by slug for a specific locale
|
|
227
|
+
*/
|
|
228
|
+
function getCMSContentBySlugForLocale(slug, contentDir, locale) {
|
|
229
|
+
const localeContentDir = getContentDirForLocale(contentDir, locale);
|
|
230
|
+
const content = getCMSContentBySlug(slug, localeContentDir);
|
|
231
|
+
if (content) {
|
|
232
|
+
// Ensure the locale is set on the content object
|
|
233
|
+
content.language = content.language || locale;
|
|
234
|
+
}
|
|
235
|
+
return content;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Get all translations of a content item by translationKey
|
|
239
|
+
*/
|
|
240
|
+
function getContentTranslations(translationKey, contentDir) {
|
|
241
|
+
const languages = getAvailableLanguages(contentDir);
|
|
242
|
+
const translations = [];
|
|
243
|
+
for (const locale of languages) {
|
|
244
|
+
const localeContentDir = getContentDirForLocale(contentDir, locale);
|
|
245
|
+
// Search for content with matching translationKey
|
|
246
|
+
try {
|
|
247
|
+
const slugs = getAllContentSlugs(localeContentDir);
|
|
248
|
+
for (const slug of slugs) {
|
|
249
|
+
const content = getCMSContentBySlug(slug, localeContentDir);
|
|
250
|
+
if (content && content.translationKey === translationKey) {
|
|
251
|
+
content.language = content.language || locale;
|
|
252
|
+
translations.push({ locale, content });
|
|
253
|
+
break; // Found the translation for this locale
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
// Skip if locale directory doesn't exist or can't be read
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return translations;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Get all content routes for all locales in a framework-agnostic format
|
|
266
|
+
* Returns an array of route objects with locale and slug information
|
|
267
|
+
*/
|
|
268
|
+
function getAllContentRoutes(contentDir, contentTypes, includeDrafts, draftUserUid) {
|
|
269
|
+
const languages = getAvailableLanguages(contentDir);
|
|
270
|
+
const allRoutes = [];
|
|
271
|
+
for (const locale of languages) {
|
|
272
|
+
const slugs = getAllContentSlugsForLocale(contentDir, locale, contentTypes, includeDrafts, draftUserUid);
|
|
273
|
+
for (const slug of slugs) {
|
|
274
|
+
const isDefaultLocale = locale === exports.DEFAULT_LANGUAGE;
|
|
275
|
+
const slugParts = slug.split("/");
|
|
276
|
+
const path = isDefaultLocale ? `/${slug}` : `/${locale}/${slug}`;
|
|
277
|
+
allRoutes.push({
|
|
278
|
+
locale,
|
|
279
|
+
slug,
|
|
280
|
+
slugParts,
|
|
281
|
+
isDefaultLocale,
|
|
282
|
+
path
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return allRoutes;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Extract userUid from a draft slug if it exists
|
|
290
|
+
* @param slug - The slug to check for userUid
|
|
291
|
+
* @returns userUid if found, null otherwise
|
|
292
|
+
*/
|
|
293
|
+
function extractUserUidFromSlug(slug) {
|
|
294
|
+
// GUID pattern: 8-4-4-4-12 hexadecimal characters with a preceding dash
|
|
295
|
+
const draftSlugPattern = /-([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/i;
|
|
296
|
+
const match = slug.match(draftSlugPattern);
|
|
297
|
+
return match ? match[1] : null;
|
|
298
|
+
}
|
|
299
|
+
function getAllContentSlugs(contentDir, contentTypes) {
|
|
300
|
+
function walk(dir, prefix = "") {
|
|
301
|
+
const entries = fs_1.default.readdirSync(dir, { withFileTypes: true });
|
|
302
|
+
const slugs = [];
|
|
303
|
+
for (const entry of entries) {
|
|
304
|
+
if (entry.isDirectory()) {
|
|
305
|
+
const subSlugs = walk(path_1.default.join(dir, entry.name), prefix ? `${prefix}/${entry.name}` : entry.name);
|
|
306
|
+
slugs.push(...subSlugs);
|
|
307
|
+
}
|
|
308
|
+
else if (entry.isFile() && (entry.name.endsWith(".mdx") || entry.name.endsWith(".json"))) {
|
|
309
|
+
const ext = entry.name.endsWith(".mdx") ? ".mdx" : ".json";
|
|
310
|
+
const slug = (prefix ? `${prefix}/` : "") + entry.name.replace(new RegExp(`\\${ext}$`), "");
|
|
311
|
+
// If content types filter is provided, check the file's type
|
|
312
|
+
if (contentTypes && contentTypes.length > 0) {
|
|
313
|
+
const filePath = path_1.default.join(dir, entry.name);
|
|
314
|
+
try {
|
|
315
|
+
const fileType = getFileTypeOptimized(filePath, ext);
|
|
316
|
+
// Only include if the type matches the filter
|
|
317
|
+
if (fileType && contentTypes.includes(fileType)) {
|
|
318
|
+
slugs.push(slug);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
// Skip files that can't be parsed
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
// No filter, include all files
|
|
328
|
+
slugs.push(slug);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return slugs;
|
|
333
|
+
}
|
|
334
|
+
return walk(contentDir);
|
|
335
|
+
}
|
|
336
|
+
function getCMSContentBySlug(slug, contentDir) {
|
|
337
|
+
// Try both .mdx and .json extensions
|
|
338
|
+
const mdxPath = path_1.default.join(contentDir, `${slug}.mdx`);
|
|
339
|
+
const jsonPath = path_1.default.join(contentDir, `${slug}.json`);
|
|
340
|
+
try {
|
|
341
|
+
// Try MDX first - combine existence check with read operation
|
|
342
|
+
try {
|
|
343
|
+
const file = fs_1.default.readFileSync(mdxPath, "utf8");
|
|
344
|
+
const { data, content } = (0, gray_matter_1.default)(file);
|
|
345
|
+
return {
|
|
346
|
+
...data,
|
|
347
|
+
slug,
|
|
348
|
+
body: content,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
catch (mdxError) {
|
|
352
|
+
// If MDX doesn't exist or can't be read, try JSON
|
|
353
|
+
if (mdxError.code !== "ENOENT") {
|
|
354
|
+
// If it's not a "file not found" error, rethrow
|
|
355
|
+
throw mdxError;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
// Try JSON
|
|
359
|
+
try {
|
|
360
|
+
const file = fs_1.default.readFileSync(jsonPath, "utf8");
|
|
361
|
+
const data = JSON.parse(file);
|
|
362
|
+
return {
|
|
363
|
+
...data,
|
|
364
|
+
slug,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
catch (jsonError) {
|
|
368
|
+
// If JSON doesn't exist or can't be read, return null
|
|
369
|
+
if (jsonError.code === "ENOENT") {
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
// If it's a parse error or other issue, rethrow
|
|
373
|
+
throw jsonError;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
catch {
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Optimized function to extract file type without reading the entire file content.
|
|
382
|
+
* For MDX files, it reads only the frontmatter section.
|
|
383
|
+
* For JSON files, it attempts to read just enough to find the type field.
|
|
384
|
+
*/
|
|
385
|
+
function getFileTypeOptimized(filePath, ext) {
|
|
386
|
+
if (ext === ".mdx") {
|
|
387
|
+
return extractTypeFromMDXFrontmatter(filePath);
|
|
388
|
+
}
|
|
389
|
+
else if (ext === ".json") {
|
|
390
|
+
return extractTypeFromJSON(filePath);
|
|
391
|
+
}
|
|
392
|
+
return undefined;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Reads only the frontmatter section of an MDX file to extract the type.
|
|
396
|
+
* This is much more efficient than parsing the entire file.
|
|
397
|
+
*/
|
|
398
|
+
function extractTypeFromMDXFrontmatter(filePath) {
|
|
399
|
+
try {
|
|
400
|
+
const file = fs_1.default.readFileSync(filePath, "utf8");
|
|
401
|
+
// Quick check if file starts with frontmatter
|
|
402
|
+
if (!file.startsWith("---\n") && !file.startsWith("---\r\n")) {
|
|
403
|
+
return undefined;
|
|
404
|
+
}
|
|
405
|
+
// Find the end of frontmatter
|
|
406
|
+
let endIndex = file.indexOf("\n---\n", 4);
|
|
407
|
+
if (endIndex === -1) {
|
|
408
|
+
endIndex = file.indexOf("\r\n---\r\n", 4);
|
|
409
|
+
}
|
|
410
|
+
if (endIndex === -1) {
|
|
411
|
+
return undefined;
|
|
412
|
+
}
|
|
413
|
+
// Extract and parse only the frontmatter
|
|
414
|
+
const frontmatterContent = file.slice(4, endIndex);
|
|
415
|
+
const { data } = (0, gray_matter_1.default)(`---\n${frontmatterContent}\n---`);
|
|
416
|
+
return data.type;
|
|
417
|
+
}
|
|
418
|
+
catch {
|
|
419
|
+
return undefined;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Attempts to extract the type field from a JSON file without parsing the entire content.
|
|
424
|
+
* Uses streaming approach for large files.
|
|
425
|
+
*/
|
|
426
|
+
function extractTypeFromJSON(filePath) {
|
|
427
|
+
try {
|
|
428
|
+
const file = fs_1.default.readFileSync(filePath, "utf8");
|
|
429
|
+
// For small files, just parse normally
|
|
430
|
+
if (file.length < 100) {
|
|
431
|
+
const data = JSON.parse(file);
|
|
432
|
+
return data.type;
|
|
433
|
+
}
|
|
434
|
+
// For larger files, try to find the type field early in the content
|
|
435
|
+
// This is a simple optimization - look for "type": in the first part of the file
|
|
436
|
+
const typeMatch = file.match(/"type"\s*:\s*"([^"]+)"/);
|
|
437
|
+
if (typeMatch) {
|
|
438
|
+
return typeMatch[1];
|
|
439
|
+
}
|
|
440
|
+
// Fallback to full parsing if quick match fails
|
|
441
|
+
const data = JSON.parse(file);
|
|
442
|
+
return data.type;
|
|
443
|
+
}
|
|
444
|
+
catch {
|
|
445
|
+
return undefined;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Generic helper function to load configuration JSON files with draft support
|
|
450
|
+
* @param contentDir - Content directory path
|
|
451
|
+
* @param locale - Locale code
|
|
452
|
+
* @param configName - Name of the config file (e.g., 'header', 'footer', 'contact')
|
|
453
|
+
* @param userUid - Optional user UID for draft content
|
|
454
|
+
* @returns Parsed config object or null if not found
|
|
455
|
+
*/
|
|
456
|
+
function loadConfigWithDraftSupport(contentDir, locale, configName, userUid) {
|
|
457
|
+
try {
|
|
458
|
+
const localeContentDir = getContentDirForLocale(contentDir, locale);
|
|
459
|
+
// If userUid is provided, try draft version first
|
|
460
|
+
if (userUid) {
|
|
461
|
+
const draftConfigPath = path_1.default.join(localeContentDir, `${configName}-${userUid}.json`);
|
|
462
|
+
if (fs_1.default.existsSync(draftConfigPath)) {
|
|
463
|
+
const draftConfigContent = fs_1.default.readFileSync(draftConfigPath, "utf-8");
|
|
464
|
+
return JSON.parse(draftConfigContent);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
// Fall back to regular config file
|
|
468
|
+
const configPath = path_1.default.join(localeContentDir, `${configName}.json`);
|
|
469
|
+
if (!fs_1.default.existsSync(configPath)) {
|
|
470
|
+
return null;
|
|
471
|
+
}
|
|
472
|
+
const configContent = fs_1.default.readFileSync(configPath, "utf-8");
|
|
473
|
+
return JSON.parse(configContent);
|
|
474
|
+
}
|
|
475
|
+
catch (error) {
|
|
476
|
+
console.error(`Error loading ${configName} config for locale ${locale}:`, error);
|
|
477
|
+
return null;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Load header configuration for a specific locale with optional draft support
|
|
482
|
+
* @param contentDir - Content directory path
|
|
483
|
+
* @param locale - Locale code
|
|
484
|
+
* @param userUid - Optional user UID for draft content
|
|
485
|
+
*/
|
|
486
|
+
function getHeaderConfig(contentDir, locale, userUid) {
|
|
487
|
+
return loadConfigWithDraftSupport(contentDir, locale, 'header', userUid);
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Load footer configuration for a specific locale with optional draft support
|
|
491
|
+
* @param contentDir - Content directory path
|
|
492
|
+
* @param locale - Locale code
|
|
493
|
+
* @param userUid - Optional user UID for draft content
|
|
494
|
+
*/
|
|
495
|
+
function getFooterConfig(contentDir, locale, userUid) {
|
|
496
|
+
return loadConfigWithDraftSupport(contentDir, locale, 'footer', userUid);
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Get the current locale from a path
|
|
500
|
+
*/
|
|
501
|
+
function getLocaleFromPath(pathname) {
|
|
502
|
+
const segments = pathname.split("/").filter(Boolean);
|
|
503
|
+
if (segments.length > 0) {
|
|
504
|
+
const firstSegment = segments[0];
|
|
505
|
+
// Check if the first segment is a known locale
|
|
506
|
+
const knownLocales = ["en", "ru", "cs"]; // Add more locales as needed
|
|
507
|
+
if (knownLocales.includes(firstSegment)) {
|
|
508
|
+
return firstSegment;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return exports.DEFAULT_LANGUAGE;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Make a link locale-aware by adding the current locale prefix
|
|
515
|
+
*/
|
|
516
|
+
function makeLocaleAwareLink(href, currentLocale) {
|
|
517
|
+
// Don't modify external links or anchors
|
|
518
|
+
if (href.startsWith("http") || href.startsWith("#")) {
|
|
519
|
+
return href;
|
|
520
|
+
}
|
|
521
|
+
// If it's the default language, don't add prefix
|
|
522
|
+
if (currentLocale === exports.DEFAULT_LANGUAGE) {
|
|
523
|
+
return href;
|
|
524
|
+
}
|
|
525
|
+
// If the href already starts with the locale, don't double-add it
|
|
526
|
+
if (href.startsWith(`/${currentLocale}/`)) {
|
|
527
|
+
return href;
|
|
528
|
+
}
|
|
529
|
+
// Add locale prefix
|
|
530
|
+
return `/${currentLocale}${href.startsWith("/") ? "" : "/"}${href}`;
|
|
531
|
+
}
|
|
532
|
+
//# sourceMappingURL=cms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cms.js","sourceRoot":"","sources":["../../src/lib/cms.ts"],"names":[],"mappings":";;;;;;AAuDA,sDA0BC;AAKD,wDAQC;AAUD,kEAoBC;AAoID,oGAiBC;AAKD,oEAcC;AAKD,wDA4BC;AAMD,kDA4BC;AAOD,wDAMC;AAED,gDAqCC;AAED,kDA0CC;AA0HD,0CAEC;AAQD,0CAEC;AAKD,8CAWC;AAKD,kDAkBC;AApnBD,4CAAoB;AACpB,gDAAwB;AACxB,8DAAiC;AACjC,qCAAoF;AAMpF,+DAA+D;AAClD,QAAA,gBAAgB,GAAG,IAAI,CAAC;AAErC;;GAEG;AACH,SAAS,qBAAqB,CAAC,aAAoC;IACjE,IAAI,CAAC;QACH,OAAO,IAAA,kBAAS,EAAC,aAAa,CAAC,CAAC;IAClC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,4EAA4E;QAC5E,OAAO;YACL,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,EAAE;YACzE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,EAAE;YACzC,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,OAAO,CAAC,GAAG,CAAC,oCAAoC,IAAI,wBAAgB;YAC7H,UAAU,EAAE,kBAAkB;YAC9B,QAAQ,EAAE,cAAc;YACxB,YAAY,EAAE,KAAK;SACpB,C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GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,6BAA6B;QACtE,IAAI,YAAY,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;YACxC,OAAO,YAAY,CAAC;QACtB,CAAC;IACH,CAAC;IACD,OAAO,wBAAgB,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CAAC,IAAY,EAAE,aAAqB;IACrE,yCAAyC;IACzC,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACpD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iDAAiD;IACjD,IAAI,aAAa,KAAK,wBAAgB,EAAE,CAAC;QACvC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,kEAAkE;IAClE,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,oBAAoB;IACpB,OAAO,IAAI,aAAa,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,EAAE,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export interface LeadCMSConfig {
|
|
2
|
+
/** LeadCMS instance URL */
|
|
3
|
+
url: string;
|
|
4
|
+
/** LeadCMS API key */
|
|
5
|
+
apiKey: string;
|
|
6
|
+
/** Default language for content */
|
|
7
|
+
defaultLanguage?: string;
|
|
8
|
+
/** Content directory path (relative to project root) */
|
|
9
|
+
contentDir?: string;
|
|
10
|
+
/** Media directory path (relative to project root) */
|
|
11
|
+
mediaDir?: string;
|
|
12
|
+
/** Enable draft content support */
|
|
13
|
+
enableDrafts?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface LeadCMSConfigOptions extends Partial<LeadCMSConfig> {
|
|
16
|
+
/** Custom config file path */
|
|
17
|
+
configPath?: string;
|
|
18
|
+
/** Working directory for resolving paths */
|
|
19
|
+
cwd?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Load configuration from multiple sources in priority order:
|
|
23
|
+
* 1. Programmatically set config (via configure())
|
|
24
|
+
* 2. Config file (leadcms.config.js/json)
|
|
25
|
+
* 3. Environment variables
|
|
26
|
+
* 4. Default values
|
|
27
|
+
*/
|
|
28
|
+
export declare function loadConfig(options?: LeadCMSConfigOptions): LeadCMSConfig;
|
|
29
|
+
/**
|
|
30
|
+
* Set configuration programmatically
|
|
31
|
+
*/
|
|
32
|
+
export declare function configure(config: Partial<LeadCMSConfig>): void;
|
|
33
|
+
/**
|
|
34
|
+
* Reset configuration (useful for testing)
|
|
35
|
+
*/
|
|
36
|
+
export declare function resetConfig(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Get current configuration
|
|
39
|
+
*/
|
|
40
|
+
export declare function getConfig(options?: LeadCMSConfigOptions): LeadCMSConfig;
|
|
41
|
+
/**
|
|
42
|
+
* Generate a sample configuration file
|
|
43
|
+
*/
|
|
44
|
+
export declare function generateConfigFile(filePath?: string): string;
|
|
45
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,aAAa;IAC5B,2BAA2B;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,mCAAmC;IACnC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,wDAAwD;IACxD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,oBAAqB,SAAQ,OAAO,CAAC,aAAa,CAAC;IAClE,8BAA8B;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4CAA4C;IAC5C,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAcD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAE,oBAAyB,GAAG,aAAa,CA8B5E;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAE9D;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAElC;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,aAAa,CAEvE;AAwHD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,GAAE,MAA8B,GAAG,MAAM,CAanF"}
|