Skip to content

Commit 10c1210

Browse files
authored
Merge pull request #3275 from Blargian/autogen-toc
Generate table of contents file for system settings
2 parents 472637f + 40015fb commit 10c1210

File tree

9 files changed

+84
-18
lines changed

9 files changed

+84
-18
lines changed

contribute/contrib-writing-guide.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ Backup and restore are very different across Cloud and Self-managed as the targe
233233
---
234234
sidebar_label: Backups
235235
sidebar_position: 1
236-
slug: /en/manage/backups
236+
slug: /manage/backups
237237
---
238238

239239
import Tabs from '@theme/Tabs';
@@ -261,7 +261,7 @@ Sometimes most of the content is the same across operating systems. For example
261261

262262
```md
263263
---
264-
slug: /en/integrations/sql-clients/clickhouse-client-local
264+
slug: /integrations/sql-clients/clickhouse-client-local
265265
sidebar_label: clickhouse-client
266266
title: clickhouse-client and clickhouse-local
267267
---
@@ -548,7 +548,7 @@ If a search is not finding the page that you expect, then have a look at the Mar
548548

549549
```md
550550
---
551-
slug: /en/sql-reference/statements/create/function
551+
slug: /sql-reference/statements/create/function
552552
sidebar_position: 38
553553
sidebar_label: FUNCTION
554554
---
@@ -562,7 +562,7 @@ And this was the change to improve the search results (add the expected search t
562562

563563
```md
564564
---
565-
slug: /en/sql-reference/statements/create/function
565+
slug: /sql-reference/statements/create/function
566566
sidebar_position: 38
567567
sidebar_label: FUNCTION
568568
---

docs/guides/sre/index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
slug: /security-and-authentication
3+
title: "Security and Authentication"
4+
description: "Landing page for Security and Authentication"
5+
---
6+
7+
| Page | Description |
8+
|------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
9+
| [Users and Roles](/docs/operations/access-rights) | Learn more about how ClickHouse supports access control management based on RBAC approach. |
10+
| [External Authenticators](/docs/operations/external-authenticators) | Learn more about how OSS ClickHouse supports authenticating and managing users using external services. |

docs/migrations/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
slug: en/migrations
2+
slug: migrations
33
title: Migrations
44
pagination_prev: null
55
pagination_next: null

docs/migrations/postgres/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
slug: en/migrations/postgresql
2+
slug: migrations/postgresql
33
pagination_prev: null
44
pagination_next: null
55
title: PostgreSQL

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"autogen_needed_files": "src/Core/FormatFactorySettings.h src/Core/Settings.cpp CHANGELOG.md"
88
},
99
"scripts": {
10-
"build": "yarn copy-clickhouse-repo-docs && yarn run-markdown-linter && yarn generate-changelog && yarn autogenerate-settings && yarn build-api-doc && yarn build-swagger && docusaurus build",
10+
"build": "yarn copy-clickhouse-repo-docs && yarn run-markdown-linter && yarn generate-changelog && yarn autogenerate-settings && yarn autogenerate-table-of-contents && yarn build-api-doc && yarn build-swagger && GENERATE_SOURCEMAP=false docusaurus build",
1111
"clear": "docusaurus clear && bash ./placeholderReset.sh",
1212
"deploy": "docusaurus deploy",
1313
"docusaurus": "docusaurus",
@@ -17,6 +17,7 @@
1717
"build-swagger": "npx @redocly/cli build-docs https://api.clickhouse.cloud/v1 --output build/cloud/manage/api/swagger.html",
1818
"prep-from-local": "bash ./scripts/copy-clickhouse-repo-docs.sh -l $1",
1919
"autogenerate-settings": "bash ./scripts/settings/autogenerate-settings.sh",
20+
"autogenerate-table-of-contents": "bash ./scripts/autogenerate-table-of-contents.sh",
2021
"generate-changelog": "bash ./scripts/generate-changelog.sh",
2122
"start": "docusaurus start",
2223
"swizzle": "docusaurus swizzle",

scripts/autogenerate-table-of-contents.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@ pip install -r scripts/table-of-contents-generator/requirements.txt
1616

1717
# Add runs of the script below for any table of contents files that need to be generated
1818
# You can run toc_gen.py --help for descriptions of the parameters
19+
20+
# TO DO: add a batch mode option to the script so that it takes in a file with the arguments
21+
# instead of having to repeat the script each time
22+
1923
python3 scripts/table-of-contents-generator/toc_gen.py --dir="knowledgebase" --single-toc --out="static" --ignore images
24+
python3 scripts/table-of-contents-generator/toc_gen.py --single-toc --dir="docs/operations/system-tables" --md="docs/operations/system-tables/index.md"
25+
python3 scripts/table-of-contents-generator/toc_gen.py --single-toc --dir="docs/operations/settings" --md="docs/operations/settings/index.md"
26+
python3 scripts/table-of-contents-generator/toc_gen.py --single-toc --dir="docs/engines/database-engines" --md="docs/engines/database-engines/index.md"
27+
python3 scripts/table-of-contents-generator/toc_gen.py --single-toc --dir="docs/engines/table-engines/mergetree-family" --md="docs/engines/table-engines/mergetree-family/index.md"
28+
python3 scripts/table-of-contents-generator/toc_gen.py --single-toc --dir="docs/engines/table-engines/integrations" --md="docs/engines/table-engines/integrations/index.md"
29+
python3 scripts/table-of-contents-generator/toc_gen.py --single-toc --dir="docs/engines/table-engines/special" --md="docs/engines/table-engines/special/index.md"
30+
python3 scripts/table-of-contents-generator/toc_gen.py --single-toc --dir="docs/getting-started/example-datasets" --md="docs/getting-started/index.md" --ignore images
2031

2132
deactivate
2233
rm -r venv

scripts/table-of-contents-generator/toc_gen.py

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import sys
1212
from collections import defaultdict
1313
import yaml
14+
import re
1415

1516
def parse_args() -> argparse.Namespace:
1617
parser = argparse.ArgumentParser(
@@ -27,6 +28,11 @@ def parse_args() -> argparse.Namespace:
2728
default=None,
2829
help="Path to output the resulting table of contents file to (by default it is output to the provided directory - file is named according to --dir)"
2930
)
31+
parser.add_argument(
32+
"--md",
33+
default=None,
34+
help="Path to markdown file to append the table of contents to"
35+
)
3036
parser.add_argument(
3137
"--dir",
3238
help="Path to a folder containing markdown (.md, .mdx) documents containing YAML with title, description, slug."
@@ -69,10 +75,35 @@ def extract_title_description_slug(filename):
6975
def walk_dirs(root_dir, ignore_dirs=[]):
7076
for root, dirs, files in os.walk(root_dir):
7177
# Modify the 'dirs' list in-place to remove ignored directories
72-
dirs[:] = [d for d in dirs if d not in ignore_dirs
73-
and not any(d.startswith(ig) for ig in ignore_dirs)]
78+
if (ignore_dirs is not None):
79+
dirs[:] = [d for d in dirs if d not in ignore_dirs
80+
and not any(d.startswith(ig) for ig in ignore_dirs)]
7481
yield root
7582

83+
def write_md_to_file(json_items, path_to_md_file):
84+
try:
85+
with open(path_to_md_file, encoding='utf-8') as pre_check:
86+
existing_content = pre_check.read()
87+
if "| Page | Description |" in existing_content:
88+
print(f"Markdown table already exists in {path_to_md_file}. Skipping.")
89+
return
90+
91+
with open(path_to_md_file, 'a', encoding='utf-8') as f:
92+
93+
f.write("| Page | Description |\n")
94+
f.write("|-----|-----|\n")
95+
96+
for item in json_items:
97+
title = item.get('title', '')
98+
slug = item.get('slug', '')
99+
description = item.get('description','')
100+
link = f"[{title}](/docs{slug})" if slug else title
101+
f.write(f"| {link} | {description} |\n")
102+
103+
print(f"Markdown table appended to {path_to_md_file}")
104+
105+
except Exception as e:
106+
print(f"An error occurred: {e}")
76107
def write_to_file(json_items, directory, output=None):
77108

78109
if output is not None:
@@ -94,10 +125,21 @@ def write_to_file(json_items, directory, output=None):
94125
print(f"An error occurred creating directory: {e}")
95126
def write_file(json_items, args, directory):
96127
print(args)
97-
if args.out is not None:
128+
if (args.out is not None) and (args.md is None):
98129
write_to_file(json_items, directory+"/toc.json", args.out)
99-
elif args.out is None:
130+
elif (args.out is None) and (args.md is None):
100131
write_to_file(json_items, directory+"/toc.json")
132+
elif (args.out is None) and (args.md is not None):
133+
write_md_to_file(json_items, args.md)
134+
def sort_by_title_before_underscore(json_items):
135+
def sort_key(item):
136+
title = item.get("title", "")
137+
if "_" in title:
138+
return title.lower().split("_")[0] # Sort by part before underscore
139+
else:
140+
return title.lower() # Sort by whole title if no underscore
141+
142+
return sorted(json_items, key=sort_key)
101143

102144
def main():
103145

@@ -131,7 +173,7 @@ def main():
131173
if args.single_toc is False:
132174
# don't write toc.json for empty folders
133175
if len(json_items) != 0:
134-
json_items = sorted(json_items, key=lambda x: x.get("title"))
176+
json_items = sort_by_title_before_underscore(json_items)
135177
# output to the specified directory if arg --out is provided
136178
write_file(json_items, args, directory)
137179
else:
@@ -140,7 +182,7 @@ def main():
140182
if args.single_toc is True:
141183
# don't write toc.json for empty folders
142184
if len(json_items) != 0:
143-
json_array = sorted(json_items, key=lambda x: x.get("title"))
185+
json_array = sort_by_title_before_underscore(json_items)
144186
# output to the specified directory if arg --out is provided
145187
write_file(json_items, args, directory)
146188
sys.exit(0)

sidebars.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ const sidebars = {
149149
className: "top-nav-item",
150150
collapsed: true,
151151
collapsible: true,
152+
link: {type: "doc", id: "getting-started/index"},
152153
items: [
153-
"getting-started/index",
154154
"getting-started/example-datasets/amazon-reviews",
155155
"getting-started/example-datasets/amplab-benchmark",
156156
"getting-started/example-datasets/brown-benchmark",
@@ -508,13 +508,14 @@ const sidebars = {
508508
label: "Functions",
509509
collapsed: false,
510510
collapsible: false,
511+
link: {type: "doc", id: "sql-reference/functions/index"},
511512
items: [
512513
{
513514
type: "category",
514515
label: "Regular Functions",
515516
collapsed: true,
516517
collapsible: true,
517-
link: {type: "doc", id: "sql-reference/functions/index"},
518+
link: {type: "doc", id: "sql-reference/functions/regular-functions-index"},
518519
items: [
519520
{
520521
type: "autogenerated",
@@ -1359,6 +1360,7 @@ const sidebars = {
13591360
label: "Security and Authentication",
13601361
collapsed: false,
13611362
collapsible: false,
1363+
link: {type: "doc", id: "guides/sre/index"},
13621364
items: [
13631365
"guides/sre/user-management/index",
13641366
{
@@ -1576,7 +1578,7 @@ const sidebars = {
15761578
type: "link",
15771579
label: "Migration Guides",
15781580
description: "Migrate your database to ClickHouse",
1579-
href: "/migrations/en/migrations"
1581+
href: "/migrations/migrations"
15801582
},
15811583
{
15821584
type: "link",
@@ -1699,13 +1701,13 @@ const sidebars = {
16991701
type: "link",
17001702
label: "Deployments and Scaling",
17011703
description: "How to deploy ClickHouse",
1702-
href: "/architecture/introduction"
1704+
href: "/deployment-guides/index"
17031705
},
17041706
{
17051707
type: "link",
17061708
label: "Security and Authentication",
17071709
description: "Secure your ClickHouse deployment",
1708-
href: "/operations/external-authenticators"
1710+
href: "/security-and-authentication"
17091711
},
17101712
{
17111713
type: "link",

table-of-contents-files/docs_en_interfaces_formats_toc.json

Whitespace-only changes.

0 commit comments

Comments
 (0)