-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathsidebars.ts
More file actions
101 lines (95 loc) · 3.29 KB
/
sidebars.ts
File metadata and controls
101 lines (95 loc) · 3.29 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
// @ts-check
import type { SidebarsConfig } from "@docusaurus/plugin-content-docs";
import apiVersions from "./docs/reference/versions.json";
import { versionCrumb, versionSelector } from "docusaurus-plugin-openapi-docs/lib/sidebars/utils";
import { openApiConfig } from "./openapi.config";
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: versionSelector(apiVersions),
className: "version-button",
},
{
type: "html",
defaultStyle: true,
value: versionCrumb(version),
},
{
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;