@seed-hypermedia/client 0.0.88 → 0.0.89
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.
|
@@ -485,10 +485,31 @@ async function contentToResolvedMarkdown(content, options) {
|
|
|
485
485
|
}
|
|
486
486
|
async function documentToResolvedMarkdownWithContext(doc, ctx) {
|
|
487
487
|
const lines = [emitFrontmatter(doc.metadata || {})];
|
|
488
|
-
const body = await blockNodesToResolvedMarkdown(doc
|
|
488
|
+
const body = await blockNodesToResolvedMarkdown(resolvedDocumentContent(doc), ctx);
|
|
489
489
|
if (body) lines.push(body);
|
|
490
490
|
return lines.join("\n");
|
|
491
491
|
}
|
|
492
|
+
function resolvedDocumentContent(doc) {
|
|
493
|
+
var _a, _b;
|
|
494
|
+
const content = doc.content || [];
|
|
495
|
+
const root = content[0];
|
|
496
|
+
if (!doc.account || content.length !== 1 || (root == null ? void 0 : root.block.type) !== "Query") return content;
|
|
497
|
+
const query = (_a = root.block.attributes) == null ? void 0 : _a.query;
|
|
498
|
+
const include = (_b = query == null ? void 0 : query.includes) == null ? void 0 : _b[0];
|
|
499
|
+
if ((query == null ? void 0 : query.includes.length) !== 1 || !include || include.space || include.path) return content;
|
|
500
|
+
return [
|
|
501
|
+
{
|
|
502
|
+
...root,
|
|
503
|
+
block: {
|
|
504
|
+
...root.block,
|
|
505
|
+
attributes: {
|
|
506
|
+
...root.block.attributes,
|
|
507
|
+
query: { ...query, includes: [{ ...include, space: doc.account, path: doc.path }] }
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
];
|
|
512
|
+
}
|
|
492
513
|
async function blockNodesToResolvedMarkdown(nodes, ctx) {
|
|
493
514
|
const lines = [];
|
|
494
515
|
for (const node of nodes) {
|
|
@@ -590,7 +611,7 @@ async function resolveBlockEmbed(block, depth, ctx) {
|
|
|
590
611
|
}
|
|
591
612
|
}
|
|
592
613
|
async function resolveQuery(block, depth, ctx) {
|
|
593
|
-
var _a;
|
|
614
|
+
var _a, _b;
|
|
594
615
|
const ind = resolvedIndent(depth);
|
|
595
616
|
try {
|
|
596
617
|
const attrs = block.attributes;
|
|
@@ -599,6 +620,7 @@ async function resolveQuery(block, depth, ctx) {
|
|
|
599
620
|
let sort;
|
|
600
621
|
let limit;
|
|
601
622
|
if (queryConfig == null ? void 0 : queryConfig.includes) {
|
|
623
|
+
if (!((_a = queryConfig.includes[0]) == null ? void 0 : _a.space)) return ind + "<!-- Query: no space specified -->";
|
|
602
624
|
includes = queryConfig.includes.map((inc) => ({
|
|
603
625
|
space: inc.space,
|
|
604
626
|
path: inc.path,
|
|
@@ -623,10 +645,10 @@ async function resolveQuery(block, depth, ctx) {
|
|
|
623
645
|
sort: (sort == null ? void 0 : sort.length) ? sort : [{ term: "updated", reverse: true }],
|
|
624
646
|
limit: limit || 10
|
|
625
647
|
});
|
|
626
|
-
if (!((
|
|
648
|
+
if (!((_b = results == null ? void 0 : results.results) == null ? void 0 : _b.length)) return ind + "<!-- Query: no results -->";
|
|
627
649
|
return results.results.map((doc) => {
|
|
628
|
-
var _a2,
|
|
629
|
-
const name = ((_a2 = doc.metadata) == null ? void 0 : _a2.name) || ((
|
|
650
|
+
var _a2, _b2;
|
|
651
|
+
const name = ((_a2 = doc.metadata) == null ? void 0 : _a2.name) || ((_b2 = doc.id.path) == null ? void 0 : _b2.join("/")) || doc.id.uid;
|
|
630
652
|
return ind + `- [${name}](${doc.id.id})`;
|
|
631
653
|
}).join("\n");
|
|
632
654
|
} catch (error) {
|
|
@@ -716,7 +738,7 @@ async function resolveEmbeddedResource(link, ctx) {
|
|
|
716
738
|
resolved = {
|
|
717
739
|
label: ((_a = resource.document.metadata) == null ? void 0 : _a.name) || fallbackDocLabel(id),
|
|
718
740
|
type: "document",
|
|
719
|
-
content: resource.document
|
|
741
|
+
content: resolvedDocumentContent(resource.document),
|
|
720
742
|
version: id.version || resource.document.version,
|
|
721
743
|
latestVersion: resource.document.version
|
|
722
744
|
};
|
package/dist/index.mjs
CHANGED