@constela/start 1.8.3 → 1.8.5
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/{chunk-65BRCBTK.js → chunk-PT6FDT6M.js} +42 -12
- package/dist/cli/index.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/package.json +3 -3
|
@@ -938,6 +938,18 @@ function loadComponentDefinitions(baseDir, componentsPath) {
|
|
|
938
938
|
throw new Error(`Invalid JSON in MDX components file: ${fullPath}`);
|
|
939
939
|
}
|
|
940
940
|
}
|
|
941
|
+
function extractGlobBasePath(pattern) {
|
|
942
|
+
const starIndex = pattern.indexOf("*");
|
|
943
|
+
if (starIndex === -1) {
|
|
944
|
+
return "";
|
|
945
|
+
}
|
|
946
|
+
const beforeStar = pattern.substring(0, starIndex);
|
|
947
|
+
const lastSlash = beforeStar.lastIndexOf("/");
|
|
948
|
+
if (lastSlash === -1) {
|
|
949
|
+
return "";
|
|
950
|
+
}
|
|
951
|
+
return beforeStar.substring(0, lastSlash + 1);
|
|
952
|
+
}
|
|
941
953
|
async function transformMdx(content, file, options) {
|
|
942
954
|
const match = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
|
|
943
955
|
let frontmatter = {};
|
|
@@ -957,12 +969,14 @@ async function transformMdx(content, file, options) {
|
|
|
957
969
|
if (typeof fmSlug === "string") {
|
|
958
970
|
slug = fmSlug;
|
|
959
971
|
} else {
|
|
960
|
-
const
|
|
972
|
+
const basePath = options?.basePath ?? "";
|
|
973
|
+
const relativePath = file.startsWith(basePath) ? file.substring(basePath.length) : file;
|
|
974
|
+
const filename = basename(relativePath, extname2(relativePath));
|
|
961
975
|
if (filename === "index") {
|
|
962
|
-
const dir = dirname(
|
|
963
|
-
slug = dir === "." ? "index" :
|
|
976
|
+
const dir = dirname(relativePath);
|
|
977
|
+
slug = dir === "." ? "index" : dir;
|
|
964
978
|
} else {
|
|
965
|
-
const dir = dirname(
|
|
979
|
+
const dir = dirname(relativePath);
|
|
966
980
|
slug = dir === "." ? filename : `${dir}/${filename}`;
|
|
967
981
|
}
|
|
968
982
|
}
|
|
@@ -1035,11 +1049,15 @@ function applyTransform(content, transform, filename) {
|
|
|
1035
1049
|
async function loadGlob(baseDir, pattern, transform, options) {
|
|
1036
1050
|
const files = await fg2(pattern, { cwd: baseDir });
|
|
1037
1051
|
if (transform === "mdx") {
|
|
1052
|
+
const basePath = extractGlobBasePath(pattern);
|
|
1038
1053
|
const results2 = [];
|
|
1039
1054
|
for (const file of files) {
|
|
1040
1055
|
const fullPath = join3(baseDir, file);
|
|
1041
1056
|
const content = readFileSync(fullPath, "utf-8");
|
|
1042
|
-
const transformed = await transformMdx(content, file,
|
|
1057
|
+
const transformed = await transformMdx(content, file, {
|
|
1058
|
+
...options,
|
|
1059
|
+
basePath
|
|
1060
|
+
});
|
|
1043
1061
|
results2.push(transformed);
|
|
1044
1062
|
}
|
|
1045
1063
|
return results2;
|
|
@@ -2506,7 +2524,7 @@ function matchRoute2(url, routes) {
|
|
|
2506
2524
|
function escapeHtml(str) {
|
|
2507
2525
|
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
2508
2526
|
}
|
|
2509
|
-
function
|
|
2527
|
+
function extractMdxContentSlotWithData(loadedData, dataSourceName, routeParams) {
|
|
2510
2528
|
const dataSource = loadedData[dataSourceName];
|
|
2511
2529
|
if (!Array.isArray(dataSource)) {
|
|
2512
2530
|
return void 0;
|
|
@@ -2518,7 +2536,10 @@ function extractMdxContentSlot(loadedData, dataSourceName, routeParams) {
|
|
|
2518
2536
|
if (!item || typeof item !== "object" || !("content" in item)) {
|
|
2519
2537
|
return void 0;
|
|
2520
2538
|
}
|
|
2521
|
-
return {
|
|
2539
|
+
return {
|
|
2540
|
+
slot: { "mdx-content": item.content },
|
|
2541
|
+
matchedItem: item
|
|
2542
|
+
};
|
|
2522
2543
|
}
|
|
2523
2544
|
async function createDevServer(options = {}) {
|
|
2524
2545
|
const {
|
|
@@ -2605,6 +2626,7 @@ async function createDevServer(options = {}) {
|
|
|
2605
2626
|
const program = await convertToCompiledProgram(pageInfo);
|
|
2606
2627
|
let composedProgram = program;
|
|
2607
2628
|
const widgets = pageInfo.widgets.map((w) => ({ id: w.id, program: w.program }));
|
|
2629
|
+
const mdxResult = extractMdxContentSlotWithData(pageInfo.loadedData, "docs", match.params);
|
|
2608
2630
|
if (program.route?.layout && layoutResolver) {
|
|
2609
2631
|
const layoutProgram = await layoutResolver.getLayout(program.route.layout);
|
|
2610
2632
|
if (layoutProgram) {
|
|
@@ -2612,7 +2634,7 @@ async function createDevServer(options = {}) {
|
|
|
2612
2634
|
if (analysis.ok) {
|
|
2613
2635
|
const compiledLayout = transformLayoutPass(layoutProgram, analysis.context);
|
|
2614
2636
|
const layoutParams = program.route?.layoutParams;
|
|
2615
|
-
const slots =
|
|
2637
|
+
const slots = mdxResult?.slot;
|
|
2616
2638
|
composedProgram = composeLayoutWithPage(
|
|
2617
2639
|
compiledLayout,
|
|
2618
2640
|
program,
|
|
@@ -2629,6 +2651,14 @@ async function createDevServer(options = {}) {
|
|
|
2629
2651
|
}
|
|
2630
2652
|
}
|
|
2631
2653
|
}
|
|
2654
|
+
if (mdxResult?.matchedItem) {
|
|
2655
|
+
const existingImportData = composedProgram.importData ?? {};
|
|
2656
|
+
composedProgram.importData = {
|
|
2657
|
+
...existingImportData,
|
|
2658
|
+
docs: mdxResult.matchedItem
|
|
2659
|
+
// Bind single matched item instead of array
|
|
2660
|
+
};
|
|
2661
|
+
}
|
|
2632
2662
|
const cookies = parseCookies(req.headers.cookie ?? null);
|
|
2633
2663
|
const ssrContext = {
|
|
2634
2664
|
url: pathname,
|
|
@@ -3111,7 +3141,7 @@ async function loadLayout2(layoutName, layoutsDir) {
|
|
|
3111
3141
|
function applyLayout(pageView, layoutView, namedSlots) {
|
|
3112
3142
|
return replaceSlot(layoutView, pageView, namedSlots);
|
|
3113
3143
|
}
|
|
3114
|
-
function
|
|
3144
|
+
function extractMdxContentSlot(loadedData, dataSourceName, routeParams) {
|
|
3115
3145
|
const dataSource = loadedData[dataSourceName];
|
|
3116
3146
|
if (dataSource && typeof dataSource === "object" && !Array.isArray(dataSource)) {
|
|
3117
3147
|
if ("content" in dataSource) {
|
|
@@ -3363,7 +3393,7 @@ async function processLayouts(pageInfo, layoutsDir, routeParams = {}) {
|
|
|
3363
3393
|
}
|
|
3364
3394
|
if (pageInfo.loadedData && Object.keys(pageInfo.loadedData).length > 0) {
|
|
3365
3395
|
for (const dataSourceName of Object.keys(pageInfo.loadedData)) {
|
|
3366
|
-
const slots =
|
|
3396
|
+
const slots = extractMdxContentSlot(pageInfo.loadedData, dataSourceName, effectiveRouteParams);
|
|
3367
3397
|
if (slots) {
|
|
3368
3398
|
namedSlots = namedSlots ? { ...namedSlots, ...slots } : slots;
|
|
3369
3399
|
break;
|
|
@@ -3372,7 +3402,7 @@ async function processLayouts(pageInfo, layoutsDir, routeParams = {}) {
|
|
|
3372
3402
|
}
|
|
3373
3403
|
if (!namedSlots && pageInfo.resolvedImports && Object.keys(pageInfo.resolvedImports).length > 0) {
|
|
3374
3404
|
for (const importName of Object.keys(pageInfo.resolvedImports)) {
|
|
3375
|
-
const slots =
|
|
3405
|
+
const slots = extractMdxContentSlot(
|
|
3376
3406
|
pageInfo.resolvedImports,
|
|
3377
3407
|
importName,
|
|
3378
3408
|
effectiveRouteParams
|
|
@@ -3386,7 +3416,7 @@ async function processLayouts(pageInfo, layoutsDir, routeParams = {}) {
|
|
|
3386
3416
|
const pageWithImportData = pageInfo.page;
|
|
3387
3417
|
if (!namedSlots && pageWithImportData.importData && Object.keys(pageWithImportData.importData).length > 0) {
|
|
3388
3418
|
for (const importName of Object.keys(pageWithImportData.importData)) {
|
|
3389
|
-
const slots =
|
|
3419
|
+
const slots = extractMdxContentSlot(
|
|
3390
3420
|
pageWithImportData.importData,
|
|
3391
3421
|
importName,
|
|
3392
3422
|
effectiveRouteParams
|
package/dist/cli/index.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -476,6 +476,7 @@ declare function loadComponentDefinitions(baseDir: string, componentsPath: strin
|
|
|
476
476
|
*/
|
|
477
477
|
declare function transformMdx(content: string, file: string, options?: {
|
|
478
478
|
components?: Record<string, ComponentDef>;
|
|
479
|
+
basePath?: string;
|
|
479
480
|
}): Promise<MdxGlobResult>;
|
|
480
481
|
/**
|
|
481
482
|
* Transform YAML content
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constela/start",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.5",
|
|
4
4
|
"description": "Meta-framework for Constela applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"tailwindcss": "^4.0.0",
|
|
46
46
|
"ws": "^8.18.0",
|
|
47
47
|
"@constela/compiler": "0.12.0",
|
|
48
|
+
"@constela/runtime": "0.16.5",
|
|
48
49
|
"@constela/core": "0.13.0",
|
|
49
50
|
"@constela/router": "15.0.0",
|
|
50
|
-
"@constela/server": "9.0.0"
|
|
51
|
-
"@constela/runtime": "0.16.5"
|
|
51
|
+
"@constela/server": "9.0.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@types/ws": "^8.5.0",
|