-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathsidebars.ts
More file actions
113 lines (106 loc) · 3.91 KB
/
sidebars.ts
File metadata and controls
113 lines (106 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// @ts-check
import type { SidebarsConfig } from "@docusaurus/plugin-content-docs";
import apiVersions from "./docs/reference/versions.json";
import { openApiConfig } from "./openapi.config";
/* Single combined version dropdown: button shows the current version
inline, menu lists all versions with the current one marked active.
Replaces the plugin's split versionSelector + versionCrumb pair. */
function versionDropdown(currentVersion: string, versions: { label: string; baseUrl: string }[]) {
const items = versions
.map((v) => {
const active = v.label === currentVersion ? " dropdown__link--active" : "";
return `<li><a class="dropdown__link${active}" href="${v.baseUrl}">${v.label}</a></li>`;
})
.join("");
return `<div class="dropdown dropdown--hoverable dropdown--right">
<button class="button button--block button--sm button--secondary">
<span>API Version: <strong>${currentVersion}</strong></span>
</button>
<ul class="dropdown__menu">${items}</ul>
</div>`;
}
import guidesSidebar from "./docs/guides/sidebar";
import examplesSidebar from "./docs/examples/sidebar";
import referenceSidebar20250212 from "./docs/reference/2025-02-12/sidebar";
import referenceSidebar20250317 from "./docs/reference/2025-03-17/sidebar";
import referenceSidebar20250422 from "./docs/reference/2025-04-22/sidebar";
import referenceSidebar20250520 from "./docs/reference/2025-05-20/sidebar";
import referenceSidebar20251108 from "./docs/reference/2025-11-08/sidebar";
const { latestVersion, showVersions, versions } = openApiConfig;
const referenceSidebarsByVersion: Record<string, SidebarsConfig[string]> = {
"2025-02-12": referenceSidebar20250212,
"2025-03-17": referenceSidebar20250317,
"2025-04-22": referenceSidebar20250422,
"2025-05-20": referenceSidebar20250520,
"2025-11-08": referenceSidebar20251108,
};
const missingReferenceSidebars = showVersions.filter((v) => !referenceSidebarsByVersion[v]);
if (missingReferenceSidebars.length > 0) {
throw new Error(
`Missing reference sidebars for versions: ${missingReferenceSidebars.join(", ")}. ` +
`Add './docs/reference/<version>/sidebar.ts' and import it in 'sidebars.ts'.`
);
}
function buildApiSidebar(version: string) {
return [
{
type: "html",
defaultStyle: true,
value: versionDropdown(version, apiVersions),
className: "version-button",
},
{
type: "category",
label: "Reference",
link: {
type: "generated-index",
title: "Reference",
description:
"Access a detailed guide to the Anytype API. Learn how to query, retrieve, and update spaces, objects, properties, types, and templates to build powerful extensions.",
slug: version === latestVersion ? "/reference" : `/reference/${version}`,
},
items: referenceSidebarsByVersion[version] ?? [],
},
{
type: "ref",
label: "Changelog",
id: "reference/changelog",
},
];
}
const sidebars: SidebarsConfig = {
tutorialSidebar: [
{
type: "category",
label: "Guides",
link: {
type: "generated-index",
title: "Guides",
description: "Explore a collection of guides that provide step-by-step instructions and best practices for using the Anytype API.",
slug: "/guides",
},
items: guidesSidebar,
},
],
...Object.fromEntries(
Object.keys(versions).map((version) => [
`openApiSidebar${version.replace(/-/g, "")}`,
showVersions.includes(version) ? buildApiSidebar(version) : [],
])
),
exampleSidebar: [
{
type: "category",
label: "Examples",
link: {
type: "generated-index",
title: "Examples",
description:
"Browse real-world examples that showcase the potential of the Anytype API. Get inspired to create custom integrations and workflows.",
slug: "/examples",
},
items: examplesSidebar,
},
],
};
export default sidebars;