@blaaiz/docs-core 0.3.0 → 0.5.0

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.
@@ -1544,6 +1544,20 @@ function dirname(file) {
1544
1544
  const i = file.lastIndexOf("/");
1545
1545
  return i === -1 ? "" : file.slice(0, i);
1546
1546
  }
1547
+ function firstDocFile(items) {
1548
+ for (const item of items) {
1549
+ if (item.kind === "doc") {
1550
+ return item.file;
1551
+ }
1552
+ if (item.kind === "group") {
1553
+ const found = firstDocFile(item.items);
1554
+ if (found !== void 0) {
1555
+ return found;
1556
+ }
1557
+ }
1558
+ }
1559
+ return void 0;
1560
+ }
1547
1561
  function planDocsTree(navigation, options = {}) {
1548
1562
  const apiDir = options.apiDir ?? "api";
1549
1563
  const specs = [];
@@ -1551,6 +1565,9 @@ function planDocsTree(navigation, options = {}) {
1551
1565
  const apiGroups = [];
1552
1566
  const metas = [];
1553
1567
  const rootPages = [];
1568
+ const apiDocLinks = [];
1569
+ const apiTabs = navigation.filter((tab) => hasOpenApi(tab.items));
1570
+ const soleApiTab = apiTabs.length === 1;
1554
1571
  for (const tab of navigation) {
1555
1572
  if (hasOpenApi(tab.items)) {
1556
1573
  planApiTab(tab);
@@ -1559,38 +1576,53 @@ function planDocsTree(navigation, options = {}) {
1559
1576
  planDocTab(tab);
1560
1577
  }
1561
1578
  metas.unshift({ path: "meta.json", content: { pages: rootPages } });
1562
- return { specs, apiPages, apiGroups, metas };
1579
+ return { specs, apiPages, apiGroups, metas, apiDocLinks };
1563
1580
  function planApiTab(tab) {
1564
- rootPages.push(apiDir);
1565
- const groupDirs = [];
1566
- for (const item of tab.items) {
1567
- if (item.kind !== "group") {
1581
+ const tabDir = soleApiTab ? apiDir : slugify(tab.title);
1582
+ rootPages.push(tabDir);
1583
+ const at = apiGroups.length;
1584
+ const children = planApiItems(tab.items, tabDir);
1585
+ apiGroups.splice(at, 0, {
1586
+ dir: tabDir,
1587
+ title: tab.title,
1588
+ root: true,
1589
+ ...tab.icon ? { icon: tab.icon } : {},
1590
+ children
1591
+ });
1592
+ }
1593
+ function planApiItems(items, dir) {
1594
+ const children = [];
1595
+ const takenFolders = /* @__PURE__ */ new Set();
1596
+ let order = 0;
1597
+ for (const item of items) {
1598
+ if (item.kind === "group") {
1599
+ const folder = slugify(item.title);
1600
+ if (takenFolders.has(folder)) {
1601
+ throw new Error(
1602
+ `[docs-core] Two sibling groups under '${dir}' share the folder name '${folder}'. Rename one of the groups in docs.json.`
1603
+ );
1604
+ }
1605
+ takenFolders.add(folder);
1606
+ const childDir = `${dir}/${folder}`;
1607
+ const at = apiGroups.length;
1608
+ const sub = planApiItems(item.items, childDir);
1609
+ apiGroups.splice(at, 0, { dir: childDir, title: item.title, children: sub });
1610
+ children.push({ order, folder });
1611
+ order += 1;
1568
1612
  continue;
1569
1613
  }
1570
- const dir = `${apiDir}/${slugify(item.title)}`;
1571
- groupDirs.push(slugify(item.title));
1572
- apiGroups.push({ dir, title: item.title });
1573
- let order = 0;
1574
- for (const page of item.items) {
1575
- if (page.kind !== "openapi") {
1576
- continue;
1577
- }
1578
- if (!specs.includes(page.file)) {
1579
- specs.push(page.file);
1614
+ if (item.kind === "openapi") {
1615
+ if (!specs.includes(item.file)) {
1616
+ specs.push(item.file);
1580
1617
  }
1581
- apiPages.push({ file: page.file, method: page.method, apiPath: page.apiPath, dir, order });
1618
+ apiPages.push({ file: item.file, method: item.method, apiPath: item.apiPath, dir, order });
1582
1619
  order += 1;
1620
+ continue;
1583
1621
  }
1622
+ apiDocLinks.push({ file: item.file, dir, order });
1623
+ order += 1;
1584
1624
  }
1585
- metas.push({
1586
- path: `${apiDir}/meta.json`,
1587
- content: {
1588
- title: tab.title,
1589
- root: true,
1590
- ...tab.icon ? { icon: tab.icon } : {},
1591
- pages: groupDirs
1592
- }
1593
- });
1625
+ return children;
1594
1626
  }
1595
1627
  function planDocTab(tab) {
1596
1628
  const directPages = tab.items.filter((item) => item.kind === "doc");
@@ -1601,36 +1633,58 @@ function planDocsTree(navigation, options = {}) {
1601
1633
  }
1602
1634
  return;
1603
1635
  }
1604
- const firstFile = directPages[0]?.file ?? groups.flatMap((g) => g.items).find((item) => item.kind === "doc")?.file;
1636
+ const firstFile = firstDocFile(tab.items);
1605
1637
  if (firstFile === void 0) {
1606
1638
  return;
1607
1639
  }
1608
1640
  const tabDir = firstFile.split("/")[0] ?? "";
1609
1641
  rootPages.push(tabDir);
1610
- const tabPages = directPages.map((page) => basename(page.file));
1611
- for (const group of groups) {
1612
- const pages = group.items.filter((item) => item.kind === "doc");
1613
- const groupDir = dirname(pages[0]?.file ?? "");
1614
- const folder = groupDir.split("/").slice(1).join("/");
1615
- if (folder === "") {
1616
- tabPages.push(...pages.map((page) => basename(page.file)));
1617
- continue;
1618
- }
1619
- tabPages.push(folder);
1620
- metas.push({
1621
- path: `${groupDir}/meta.json`,
1622
- content: { title: group.title, pages: pages.map((page) => basename(page.file)) }
1623
- });
1624
- }
1625
1642
  metas.push({
1626
1643
  path: `${tabDir}/meta.json`,
1627
1644
  content: {
1628
1645
  title: tab.title,
1629
1646
  root: true,
1630
1647
  ...tab.icon ? { icon: tab.icon } : {},
1631
- pages: tabPages
1648
+ pages: planDocItems(tab.items, tabDir)
1649
+ }
1650
+ });
1651
+ }
1652
+ function planDocItems(items, dir) {
1653
+ const entries = [];
1654
+ for (const item of items) {
1655
+ if (item.kind === "doc") {
1656
+ entries.push(basename(item.file));
1657
+ continue;
1658
+ }
1659
+ if (item.kind !== "group") {
1660
+ continue;
1632
1661
  }
1662
+ const groupDir = planDocGroup(item, dir);
1663
+ if (groupDir === null) {
1664
+ continue;
1665
+ }
1666
+ if (groupDir === dir) {
1667
+ entries.push(...planDocItems(item.items, dir));
1668
+ continue;
1669
+ }
1670
+ entries.push(groupDir.slice(dir.length + 1));
1671
+ }
1672
+ return entries;
1673
+ }
1674
+ function planDocGroup(group, dir) {
1675
+ const firstFile = firstDocFile(group.items);
1676
+ if (firstFile === void 0) {
1677
+ return null;
1678
+ }
1679
+ const groupDir = dirname(firstFile);
1680
+ if (groupDir === dir || groupDir === "") {
1681
+ return dir;
1682
+ }
1683
+ metas.push({
1684
+ path: `${groupDir}/meta.json`,
1685
+ content: { title: group.title, pages: planDocItems(group.items, groupDir) }
1633
1686
  });
1687
+ return groupDir;
1634
1688
  }
1635
1689
  }
1636
1690
 
@@ -3066,5 +3120,5 @@ function mergeOpenApiDocuments(inputs, options) {
3066
3120
  }
3067
3121
 
3068
3122
  export { AI_PROVIDER_MODELS, AI_PROVIDER_NAMES, AiConfigError, DocsConfigError, InvalidNavigationError, OpenApiMergeError, ProxyTargetError, SESSION_COOKIE, assertAllowedTarget, buildMetadata, buildRobots, buildSearchIndex, buildSessionCookie, buildSitemap, buildThemeCss, clearSessionCookie, createAskAiRoute, createAuthGate, createEmailSignIn, createGoogleAuth, createMarkdownRoute, createSecretSignIn, createSignOut, createSiteAuth, createTryItProxy, createTryItProxyRoute, defineDocsConfig, isAllowedEmail, mdxToMarkdown, mergeOpenApiDocuments, openApiOperationToMarkdown, parseNavigation, planDocsTree, readCookie, resolveAiConfig, searchIndex, signSession, unwrapProxyTarget, validateDocsConfig, verifySession };
3069
- //# sourceMappingURL=chunk-ICDBGTIJ.js.map
3070
- //# sourceMappingURL=chunk-ICDBGTIJ.js.map
3123
+ //# sourceMappingURL=chunk-ZWDLAW5M.js.map
3124
+ //# sourceMappingURL=chunk-ZWDLAW5M.js.map