Skip to content

Commit 2c25ba1

Browse files
mnenciagbartolini
andauthored
feat(sidebar): use autogenerated sidebar configuration (#31)
Replace manual sidebar entries with Docusaurus autogenerated sidebar using document metadata and category files, simplifying maintenance and reducing manual configuration overhead. The sidebar works immediately with category files added to website/docs, and will continue working after future imports when cloudnative-pg/cloudnative-pg#9773 is merged. The import script now creates autogenerated sidebar config for new versions on first import, preserving any later customizations. Closes #20 Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com> Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com> Co-authored-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
1 parent ea3525a commit 2c25ba1

4 files changed

Lines changed: 47 additions & 82 deletions

File tree

scripts/import_docs.sh

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
set -euo pipefail
2323

2424
SOURCE_REPO="https://github.com/cloudnative-pg/cloudnative-pg.git"
25+
ROOT_DIR=$(cd "$(dirname "$0")/../"; pwd)
26+
WEBSITE_DIR=${ROOT_DIR}/website
2527
SOURCE_DOCS_PATH="docs/src"
2628
TMP_BASE="$(mktemp -d)"
2729
trap 'rm -rf "$TMP_BASE"' EXIT
@@ -106,24 +108,44 @@ fi
106108
# ===== MAIN BRANCH =====
107109
if [[ "$IS_MAIN" == true ]]; then
108110
echo "Copying imported docs -> ./website/docs"
109-
mkdir -p ./website/docs
110-
rsync -av --delete "$SOURCE_PATH/" --exclude "css" ./website/docs/
111+
mkdir -p ${WEBSITE_DIR}/docs
112+
rsync -av --delete "$SOURCE_PATH/" --exclude "css" ${WEBSITE_DIR}/docs/
113+
111114
echo "Updated ./docs from main — import completed."
112115
exit 0
113116
fi
114117
# ===== VERSION TAG =====
115-
VERSIONS_JSON="./website/versions.json"
116-
VERSIONS_CONFIG="./website/versions_config.json"
117-
DOCUSAURUS_CONFIG="./website/docusaurus.config.ts"
118-
TARGET_DIRECTORY="./website/versioned_docs/version-${VERSION_DIR}"
118+
VERSIONS_JSON="${WEBSITE_DIR}/versions.json"
119+
VERSIONS_CONFIG="${WEBSITE_DIR}/versions_config.json"
120+
DOCUSAURUS_CONFIG="${WEBSITE_DIR}/docusaurus.config.ts"
121+
TARGET_DIRECTORY="${WEBSITE_DIR}/versioned_docs/version-${VERSION_DIR}"
119122

120123
echo "Copying imported docs -> ${TARGET_DIRECTORY}"
121124
rsync -av --delete "$SOURCE_PATH/" --exclude "css" "${TARGET_DIRECTORY}"
122125

126+
# Create autogenerated sidebar configuration for this version if it doesn't exist
127+
SIDEBAR_TARGET_DIR="${WEBSITE_DIR}/versioned_sidebars"
128+
SIDEBAR_TARGET_FILE="$SIDEBAR_TARGET_DIR/version-${VERSION_DIR}-sidebars.json"
129+
130+
if [[ ! -f "$SIDEBAR_TARGET_FILE" ]]; then
131+
echo "Creating autogenerated sidebar config for version ${VERSION_DIR}"
132+
mkdir -p "$SIDEBAR_TARGET_DIR"
133+
cat > "$SIDEBAR_TARGET_FILE" <<'SIDEBAR_EOF'
134+
{
135+
"docs": [
136+
{
137+
"type": "autogenerated",
138+
"dirName": "."
139+
}
140+
]
141+
}
142+
SIDEBAR_EOF
143+
else
144+
echo "Sidebar config for version ${VERSION_DIR} already exists, keeping it"
145+
fi
146+
123147
# Add the new version to versions.json if not already present
124-
if ! grep -q "\"${VERSION_DIR}\"" versions.json 2>/dev/null; then
125-
# Import the new version in the correct folder
126-
cp "./website/sidebar_config.json" "./website/versioned_sidebars/version-${VERSION_DIR}-sidebars.json"
148+
if ! grep -q "\"${VERSION_DIR}\"" "$VERSIONS_JSON" 2>/dev/null; then
127149
jq --arg version "$VERSION_DIR" \
128150
'. = [$version] + . | unique' \
129151
"$VERSIONS_JSON" > "${VERSIONS_JSON}.tmp" && \
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"label": "Appendixes",
3+
"position": 600,
4+
"link": {
5+
"type": "generated-index"
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"label": "CNCF Projects Integrations",
3+
"position": 590,
4+
"link": {
5+
"type": "generated-index"
6+
}
7+
}

website/sidebar_config.json

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,8 @@
11
{
22
"docs": [
3-
"index",
4-
"before_you_start",
5-
"use_cases",
6-
"architecture",
7-
"installation_upgrade",
8-
"quickstart",
9-
"image_catalog",
10-
"bootstrap",
11-
"database_import",
12-
"security",
13-
"instance_manager",
14-
"scheduling",
15-
"resource_management",
16-
"failure_modes",
17-
"rolling_update",
18-
"replication",
19-
"logical_replication",
20-
"backup",
21-
"wal_archiving",
22-
"recovery",
23-
"service_management",
24-
"postgresql_conf",
25-
"declarative_role_management",
26-
"declarative_database_management",
27-
"tablespaces",
28-
"operator_conf",
29-
"cluster_conf",
30-
"storage",
31-
"labels_annotations",
32-
"monitoring",
33-
"logging",
34-
"certificates",
35-
"ssl_connections",
36-
"applications",
37-
"connection_pooling",
38-
"replica_cluster",
39-
"kubernetes_upgrade",
40-
"postgres_upgrades",
41-
"kubectl-plugin",
42-
"failover",
43-
"troubleshooting",
44-
"fencing",
45-
"declarative_hibernation",
46-
"postgis",
47-
"e2e",
48-
"container_images",
49-
"imagevolume_extensions",
50-
"cnpg_i",
51-
"operator_capability_levels",
52-
"controller",
53-
"samples",
54-
"networking",
55-
"benchmarking",
56-
"faq",
57-
"cloudnative-pg.v1",
58-
"supported_releases",
59-
"preview_version",
60-
"release_notes",
613
{
62-
"type": "category",
63-
"label": "CNCF Projects Integrations",
64-
"items": [
65-
"cncf-projects/external-secrets",
66-
"cncf-projects/cilium"
67-
]
68-
},
69-
{
70-
"type": "category",
71-
"label": "Appendixes",
72-
"items": [
73-
"appendixes/backup_volumesnapshot",
74-
"appendixes/backup_barmanobjectstore",
75-
"appendixes/object_stores"
76-
]
4+
"type": "autogenerated",
5+
"dirName": "."
776
}
787
]
798
}

0 commit comments

Comments
 (0)