-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathsidebars.ts
More file actions
163 lines (152 loc) · 5.43 KB
/
Copy pathsidebars.ts
File metadata and controls
163 lines (152 loc) · 5.43 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// @ts-check
import type { SidebarsConfig } from "@docusaurus/plugin-content-docs";
import { getVersionGroups, openApiConfig, openApiV2Config } from "./openapi.config";
/* Single combined version dropdown: button shows the current version
inline, menu lists all versions grouped by major with the current one
marked active. Replaces the plugin's split versionSelector + versionCrumb
pair. Groups come from openapi.config rather than the plugin-generated
docs/reference/versions.json, which is a flat array and cannot say which
major a version belongs to. */
function versionDropdown(currentVersion: string) {
const groups = getVersionGroups();
const current = groups.flatMap((group) => group.items).find((v) => v.version === currentVersion);
const items = groups
.map((group) => {
const links = group.items
.map((v) => {
const active = v.version === currentVersion ? " dropdown__link--active" : "";
return `<li><a class="dropdown__link${active}" href="${v.href}">${v.label}</a></li>`;
})
.join("");
/* Group titles are plain list items, not dropdown__link — not focusable,
not clickable. */
return `<li class="version-dropdown__group">${group.title}</li>${links}`;
})
.join("");
return `<div class="dropdown dropdown--hoverable dropdown--right">
<button class="button button--block button--sm button--secondary">
<span>API Version: <strong>${current?.display ?? 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";
import referenceSidebarV2 from "./docs/reference/v2/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'.`
);
}
if (!referenceSidebarV2 || referenceSidebarV2.length === 0) {
throw new Error(
`Missing reference sidebar for API v2. Run 'bun run make-reference' to generate ` +
`'./docs/reference/v2/sidebar.ts'.`
);
}
function buildApiSidebar(version: string) {
return [
{
type: "html",
defaultStyle: true,
value: versionDropdown(version),
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",
},
];
}
/* v2 differs from v1 in one place: the Reference category links to a
hand-written landing page rather than a generated-index, because a
pre-release needs framing the spec description cannot give it. */
function buildV2Sidebar(): SidebarsConfig[string] {
return [
{
type: "html",
defaultStyle: true,
value: versionDropdown(openApiV2Config.label),
className: "version-button",
},
{
type: "category",
label: "Reference",
link: {
type: "doc",
id: "reference/v2-overview",
},
items: referenceSidebarV2,
},
{
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) : [],
])
),
openApiSidebarV2: buildV2Sidebar(),
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;