Skip to content

Commit f3a41da

Browse files
authored
refactor: restructure docs into website subdirectory (#6)
Reorganize the documentation repository structure to consolidate all documentation files under the website/ directory for better organization and build consistency. Changes include: - Move all docs/ content to website/docs/ - Add .dockerignore to exclude node_modules from Docker context - Update Dockerfile to work with new structure - Remove obsolete version 1.25 - Update import_docs.sh script for new paths - Extract json config from ts files for easier jq updates - Use the 1.28 as the default documentation page - Avoid marking 1.27 as unsupported Signed-off-by: Francesco Canovai <[email protected]>
1 parent 87002a5 commit f3a41da

File tree

802 files changed

+322
-30126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

802 files changed

+322
-30126
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: Build containers
22

33
on:
44
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
58

69
env:
710
REGISTRY: "ghcr.io"

.github/workflows/sync_docs.yml

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,39 @@ name: Import CloudNativePG Docs
33
on:
44
repository_dispatch:
55
types: [cnpg-docs-release]
6+
workflow_dispatch:
7+
inputs:
8+
tag:
9+
description: 'The tag of the CloudNativePG release to import docs for'
10+
required: true
11+
type: string
612

713
permissions:
814
contents: write
915

1016
jobs:
1117
import:
1218
runs-on: ubuntu-latest
13-
19+
env:
20+
VERSION: ${{ github.event.client_payload.tag || github.event.inputs.tag }}
1421
steps:
15-
# -----------------------------
16-
# CHECKOUT CNPG DOCS REPO
17-
# -----------------------------
1822
- name: Checkout docs repo
19-
uses: actions/checkout@v4
23+
uses: actions/checkout@v6
2024
with:
2125
fetch-depth: 0
22-
2326
- name: Setup Node.js
24-
uses: actions/setup-node@v4
27+
uses: actions/setup-node@v6
2528
with:
26-
node-version: 20
2729
cache: 'yarn'
28-
2930
- name: Install dependencies
3031
run: yarn install --frozen-lockfile
31-
32-
# -----------------------------
33-
# RUN IMPORT SCRIPT
34-
# -----------------------------
3532
- name: Import docs
36-
env:
37-
VERSION: ${{ github.event.client_payload.tag }}
3833
run: |
39-
echo "Importing CloudNativePG docs for version: $VERSION"
40-
./scripts/import_docs.sh "$VERSION"
41-
42-
# -----------------------------
43-
# COMMIT CHANGES
44-
# -----------------------------
45-
- name: Commit changes
46-
run: |
47-
git config user.name "github-actions"
48-
git config user.email "[email protected]"
49-
git add .
50-
git commit -m "docs: import CloudNativePG $VERSION" || echo "No changes to commit"
51-
52-
# -----------------------------
53-
# PUSH CHANGES
54-
# -----------------------------
55-
- name: Push changes
56-
run: git push
34+
echo "Importing CloudNativePG docs for version: ${{ env.VERSION }}"
35+
./scripts/import_docs.sh "${{ env.VERSION }}"
36+
- name: Commit and push changes
37+
uses: EndBug/add-and-commit@v9
38+
with:
39+
message: "docs: import CloudNativePG ${{ env.VERSION }}"
40+
# The token is required to trigger build_containers on pushes
41+
github_token: '${{ secrets.REPO_PAT }}'

Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
FROM node:lts-trixie-slim
1+
FROM node:lts-alpine
22

3-
RUN apt update && \
4-
apt install -y git && \
5-
git clone https://github.com/cloudnative-pg/docs /website
3+
COPY website /website
64

75
WORKDIR /website
86
RUN yarn

convert-frontmatter.js

Lines changed: 0 additions & 61 deletions
This file was deleted.

scripts/import_docs.sh

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -98,50 +98,62 @@ if [[ ! -d "$SOURCE_PATH" ]]; then
9898
exit 1
9999
fi
100100

101-
# Install node modules if missing
102-
if ! command -v yarn >/dev/null 2>&1; then
103-
echo "ERROR: yarn not found. Install Yarn."
101+
if ! command -v jq >/dev/null 2>&1; then
102+
echo "ERROR: jq not found. Install jq for JSON processing."
104103
exit 1
105104
fi
106105

107-
if [[ ! -d "node_modules" ]]; then
108-
echo "node_modules missing: running yarn install"
109-
yarn install --silent
110-
fi
111-
112106
# ===== MAIN BRANCH =====
113107
if [[ "$IS_MAIN" == true ]]; then
114-
echo "Copying imported docs -> ./docs"
115-
mkdir -p ./docs
116-
rsync -av --delete "$SOURCE_PATH/" --exclude "css" ./docs/
117-
108+
echo "Copying imported docs -> ./website/docs"
109+
mkdir -p ./website/docs
110+
rsync -av --delete "$SOURCE_PATH/" --exclude "css" ./website/docs/
118111
echo "Updated ./docs from main — import completed."
119112
exit 0
120113
fi
121-
122114
# ===== VERSION TAG =====
123-
if grep -q "\"${VERSION_DIR}\"" versions.json 2>/dev/null; then
124-
# Import the new version in the correct folder
125-
TARGET_DIRECTORY="./versioned_docs/version-${VERSION_DIR}"
126-
echo "Copying imported docs -> ${TARGET_DIRECTORY}"
127-
rsync -av --delete "$SOURCE_PATH/" --exclude "css" "${TARGET_DIRECTORY}"
128-
else
129-
# Create Docusaurus version
130-
echo "Running: yarn docusaurus docs:version ${VERSION_DIR}"
131-
yarn docusaurus docs:version "${VERSION_DIR}"
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}"
132119

133-
# Import the new version in the correct folder
134-
TARGET_DIRECTORY="./versioned_docs/version-${VERSION_DIR}"
135-
echo "Copying imported docs -> ${TARGET_DIRECTORY}"
136-
rsync -av --delete "$SOURCE_PATH/" --exclude "css" "${TARGET_DIRECTORY}"
120+
echo "Copying imported docs -> ${TARGET_DIRECTORY}"
121+
rsync -av --delete "$SOURCE_PATH/" --exclude "css" "${TARGET_DIRECTORY}"
137122

138-
echo "=== Done: Docusaurus version ${VERSION_DIR} created ==="
123+
# 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"
127+
jq --arg version "$VERSION_DIR" \
128+
'. = [$version] + . | unique' \
129+
"$VERSIONS_JSON" > "${VERSIONS_JSON}.tmp" && \
130+
mv "${VERSIONS_JSON}.tmp" "$VERSIONS_JSON"
139131
fi
140132

141-
# Mark RC as preview
142-
VDIR="versioned_docs/version-${VERSION_DIR}"
133+
# Determine the banner value
143134
if [[ "$IS_RC" == true ]]; then
144-
echo "Marking ${VDIR} as preview (rc)"
145-
echo "preview: true" > "${VDIR}/.preview"
135+
BANNER="unreleased"
136+
else
137+
BANNER="none"
146138
fi
147139

140+
echo "Updating versions_config.json: version ${VERSION_DIR} banner=${BANNER}"
141+
jq --arg version "$VERSION_DIR" --arg banner "$BANNER" \
142+
'.[$version] = {"badge": true, "banner": $banner}' \
143+
"$VERSIONS_CONFIG" > "${VERSIONS_CONFIG}.tmp" && \
144+
mv "${VERSIONS_CONFIG}.tmp" "$VERSIONS_CONFIG"
145+
146+
# Determine if this is the highest version and update docusaurus.config.ts
147+
HIGHEST_VERSION=$(jq -r '.[]' "$VERSIONS_JSON" | sort -V | tail -n1)
148+
149+
if [[ "$VERSION_DIR" == "$HIGHEST_VERSION" ]] && [[ "$IS_RC" == false ]]; then
150+
echo "Version ${VERSION_DIR} is the highest release - updating lastVersion in docusaurus.config.ts"
151+
152+
# Update lastVersion in docusaurus.config.ts
153+
sed -i.bak "s/lastVersion: '[^']*'/lastVersion: '${VERSION_DIR}'/" "$DOCUSAURUS_CONFIG" && \
154+
rm "${DOCUSAURUS_CONFIG}.bak"
155+
156+
echo "Updated lastVersion to ${VERSION_DIR}"
157+
else
158+
echo "Version ${VERSION_DIR} is not the highest release - lastVersion unchanged"
159+
fi

sidebars.ts

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)