-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsidebars-query-library.js
More file actions
50 lines (44 loc) · 1.77 KB
/
Copy pathsidebars-query-library.js
File metadata and controls
50 lines (44 loc) · 1.77 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
// Sidebar for the query-library docs-plugin instance: Overview (the landing
// page), then one category per provider whose label links to the provider
// page (generated <provider>.mdx stub) and whose children autogenerate from
// queries/<provider>/, grouping by service. Provider directories are read
// from the filesystem so a new provider's first merged query adds its
// section with no manual step; display labels come from
// src/configs/providers-data.json with a capitalization fallback.
const fs = require('fs');
const path = require('path');
const providersData = require('./src/configs/providers-data.json');
const queriesDir = path.join(__dirname, 'query-library', 'queries');
const providerIds = fs.existsSync(queriesDir)
? fs
.readdirSync(queriesDir)
.filter((name) => fs.statSync(path.join(queriesDir, name)).isDirectory())
.sort()
: [];
function labelFor(id) {
const cfg = providersData.find((p) => p.name === id);
return cfg ? cfg.title : id.charAt(0).toUpperCase() + id.slice(1).replace(/_/g, ' ');
}
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
const sidebars = {
queryLibrarySidebar: [
// Escape hatch back to the main stackql.io docs. '/docs' resolves under
// baseUrl to the redirect stub at src/pages/docs/index.js, so the link
// renders as internal (no external-link icon) and forwards to
// stackql.io/docs.
{
type: 'link',
href: '/docs',
label: 'Back to docs',
className: 'ql-sidebar-back-link',
},
{type: 'doc', id: 'index', label: 'Overview'},
...providerIds.map((id) => ({
type: 'category',
label: labelFor(id),
link: {type: 'doc', id},
items: [{type: 'autogenerated', dirName: `queries/${id}`}],
})),
],
};
module.exports = sidebars;