Skip to content

Commit 3ad8480

Browse files
committed
docs: improve docs generation
1 parent 2d9228c commit 3ad8480

2 files changed

Lines changed: 73 additions & 27 deletions

File tree

.github/actions/generate-index/action.yml

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ author: 'Nikita Vasilev'
55
inputs:
66
version:
77
required: true
8+
description: 'Documentation version'
89
project-name:
910
required: true
11+
description: 'Project display name'
1012
project-description:
1113
required: true
14+
description: 'Project description'
15+
modules:
16+
required: false
17+
description: 'JSON array of modules (e.g., [{"name":"ValidatorCore","path":"validatorcore","description":"Core validation functionality"}])'
18+
default: '[]'
1219

1320
runs:
1421
using: 'composite'
@@ -17,15 +24,56 @@ runs:
1724
shell: bash
1825
run: |
1926
CURRENT_VERSION="${{ inputs.version }}"
27+
PROJECT_NAME="${{ inputs.project-name }}"
28+
PROJECT_DESC="${{ inputs.project-description }}"
29+
MODULES='${{ inputs.modules }}'
2030
REPO_NAME=$(basename "$GITHUB_REPOSITORY")
2131
22-
cat > docs/index.html << 'EOF'
32+
# Create docs directory if it doesn't exist
33+
mkdir -p docs
34+
35+
# Generate module cards HTML
36+
MODULE_CARDS=""
37+
if [ "$MODULES" != "[]" ] && [ -n "$MODULES" ]; then
38+
# Parse JSON with Python
39+
MODULE_CARDS=$(python3 << PYTHON_EOF
40+
import json
41+
modules = json.loads('''$MODULES''')
42+
for m in modules:
43+
badge = m.get('badge', 'Module')
44+
print(f"""<a href="${CURRENT_VERSION}/{m['name']}/documentation/{m['path']}" class="doc-card">
45+
<span class="module-badge">{badge}</span>
46+
<h2>{m['name']}</h2>
47+
<p>{m['description']}</p>
48+
<span class="link">View documentation</span>
49+
</a>
50+
""")
51+
PYTHON_EOF
52+
)
53+
else
54+
# Default modules for ValidatorCore/ValidatorUI
55+
MODULE_CARDS="<a href=\"${CURRENT_VERSION}/ValidatorCore/documentation/validatorcore\" class=\"doc-card\">
56+
<span class="module-badge">Core Module</span>
57+
<h2>ValidatorCore</h2>
58+
<p>Core validation functionality and rules for Swift applications. Contains base types, protocols, and validator implementations.</p>
59+
<span class="link">View documentation</span>
60+
</a>
61+
62+
<a href=\"${CURRENT_VERSION}/ValidatorUI/documentation/validatorui\" class=\"doc-card\">
63+
<span class="module-badge">UI Module</span>
64+
<h2>ValidatorUI</h2>
65+
<p>UI components and helpers for building validation interfaces. Ready-to-use solutions for SwiftUI and UIKit.</p>
66+
<span class="link">View documentation</span>
67+
</a>"
68+
fi
69+
70+
cat > docs/index.html << EOF
2371
<!DOCTYPE html>
2472
<html lang="en">
2573
<head>
2674
<meta charset="UTF-8">
2775
<meta name="viewport" content="width=device-width, initial-scale=1.0">
28-
<title>$REPO_NAME Documentation</title>
76+
<title>$PROJECT_NAME Documentation</title>
2977
<style>
3078
* {
3179
margin: 0;
@@ -163,25 +211,13 @@ runs:
163211
<body>
164212
<div class="container">
165213
<header>
166-
<h1>${{ inputs.project_name }}</h1>
167-
<p class="subtitle">${{ inputs.project_descritpion }}</p>
168-
<span class="version-badge">VERSION_PLACEHOLDER</span>
214+
<h1>$PROJECT_NAME</h1>
215+
<p class="subtitle">$PROJECT_DESC</p>
216+
<span class="version-badge">$CURRENT_VERSION</span>
169217
</header>
170218
171219
<div class="docs-grid">
172-
<a href="VERSION_PLACEHOLDER/ValidatorCore/documentation/validatorcore" class="doc-card">
173-
<span class="module-badge">Core Module</span>
174-
<h2>ValidatorCore</h2>
175-
<p>Core validation functionality and rules for Swift applications. Contains base types, protocols, and validator implementations.</p>
176-
<span class="link">View documentation</span>
177-
</a>
178-
179-
<a href="VERSION_PLACEHOLDER/ValidatorUI/documentation/validatorui" class="doc-card">
180-
<span class="module-badge">UI Module</span>
181-
<h2>ValidatorUI</h2>
182-
<p>UI components and helpers for building validation interfaces. Ready-to-use solutions for SwiftUI and UIKit.</p>
183-
<span class="link">View documentation</span>
184-
</a>
220+
$MODULE_CARDS
185221
</div>
186222
187223
<footer>
@@ -192,9 +228,4 @@ runs:
192228
</html>
193229
EOF
194230
195-
# Replace VERSION_PLACEHOLDER with actual version
196-
sed -i '' "s/VERSION_PLACEHOLDER/$CURRENT_VERSION/g" docs/index.html || \
197-
sed -i "s/VERSION_PLACEHOLDER/$CURRENT_VERSION/g" docs/index.html
198-
199-
echo "✅ Index page created with version $CURRENT_VERSION"
200-
231+
echo "✅ Index page created for $PROJECT_NAME version $CURRENT_VERSION"

.github/workflows/docs.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,24 @@ jobs:
5252
- name: Generate Index Page
5353
uses: ./.github/actions/generate-index
5454
with:
55-
version: ${{ steps.build.outputs.version }}
56-
project-name: "Validator"
57-
project-description: "Swift validation framework"
55+
version: ${{ steps.version.outputs.version }}
56+
project-name: 'Validator'
57+
project-description: 'Swift validation framework'
58+
modules: |
59+
[
60+
{
61+
"name": "ValidatorCore",
62+
"path": "ValidatorCore",
63+
"description": "Core validation functionality and rules for Swift applications. Contains base types, protocols, and validator implementations.",
64+
"badge": "Core Module"
65+
},
66+
{
67+
"name": "ValidatorUI",
68+
"path": "ValidatorUI",
69+
"description": "UI components and helpers for building validation interfaces. Ready-to-use solutions for SwiftUI and UIKit.",
70+
"badge": "UI Module"
71+
}
72+
]
5873
5974
- name: Deploy
6075
uses: peaceiris/actions-gh-pages@v3

0 commit comments

Comments
 (0)