Skip to content

Commit 4f70acd

Browse files
author
GitHub Actions
committed
Clean up documentation structure and update workflow files
1 parent 523420c commit 4f70acd

136 files changed

Lines changed: 633 additions & 19651 deletions

File tree

Some content is hidden

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

.github/scripts/build_docs.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Simple documentation builder for deploy-to-pages.sh
4+
Builds mdBook documentation in software/book/book/ directory.
5+
"""
6+
7+
import sys
8+
import subprocess
9+
from pathlib import Path
10+
11+
def run_command(command: str, cwd: Path) -> bool:
12+
"""Run a shell command and return success status."""
13+
try:
14+
result = subprocess.run(command, shell=True, cwd=cwd, check=True)
15+
return True
16+
except subprocess.CalledProcessError as e:
17+
print(f"ERROR: Command failed: {command}")
18+
return False
19+
20+
def main():
21+
"""Build documentation for GitHub Pages deployment."""
22+
# Get project root (2 levels up from scripts)
23+
project_root = Path(__file__).parent.parent.parent
24+
book_path = project_root / "software" / "book"
25+
extract_script = Path(__file__).parent / "smart-extract-docs.py"
26+
27+
print("Building documentation...")
28+
29+
# Step 1: Extract content from READMEs
30+
print("Extracting content from README files...")
31+
if not run_command(f"python3 {extract_script}", project_root):
32+
sys.exit(1)
33+
34+
# Step 2: Build mdBook
35+
print("Building mdBook...")
36+
if not run_command("mdbook build", book_path):
37+
sys.exit(1)
38+
39+
# Step 3: Verify build
40+
built_path = book_path / "book"
41+
if not built_path.exists():
42+
print("ERROR: Build directory not created")
43+
sys.exit(1)
44+
45+
index_html = built_path / "index.html"
46+
if not index_html.exists():
47+
print("ERROR: index.html not found")
48+
sys.exit(1)
49+
50+
print("SUCCESS: Documentation built successfully")
51+
print(f"Output directory: {built_path}")
52+
53+
if __name__ == "__main__":
54+
main()

.github/scripts/config.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
# Configuration file for documentation deployment
3+
# This file contains all configurable parameters to avoid hardcoded values
4+
5+
# Navigation Links
6+
SHOP_URL="https://uelectronics.com/"
7+
REPO_URL="https://github.com/UNIT-Electronics-MX/unit_jun_r3_development_board"
8+
9+
# Icons (using Unicode emojis)
10+
SHOP_ICON="🛒"
11+
REPO_ICON="📋"
12+
13+
# Titles
14+
SHOP_TITLE="Shop"
15+
REPO_TITLE="Repository"
16+
17+
# Styling
18+
LINK_COLOR="#666"
19+
LINK_PADDING="4px"
20+
LINK_FONT_SIZE="14px"
21+
LINK_MARGIN="4px"
22+
BORDER_COLOR="#ddd"
23+
BORDER_RADIUS="3px"
24+
LINK_WIDTH="24px"
25+
LINK_HEIGHT="24px"
26+
LINE_HEIGHT="16px"
27+
28+
# Hover states
29+
HOVER_BORDER_COLOR="#999"
30+
HOVER_BG_COLOR="#f5f5f5"
31+
32+
# Timing
33+
NAVBAR_INJECTION_DELAY="100"
34+
35+
# Build directories
36+
BUILD_DIR="software/book/book"
37+
DOCS_DIR="docs"
38+
39+
# Git configuration
40+
GIT_BRANCH="main"

.github/scripts/deploy-to-pages.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
# Build documentation for GitHub Actions deployment
3+
# This script builds documentation using configurable parameters (no hardcoded values)
4+
5+
echo " Building documentation for GitHub Actions..."
6+
7+
# Load configuration with robust path handling
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
source "${SCRIPT_DIR}/config.sh"
10+
11+
# Build documentation (does NOT modify docs/ directory)
12+
echo " Building documentation..."
13+
python3 .github/scripts/build_docs.py
14+
15+
if [ $? -ne 0 ]; then
16+
echo " Build failed!"
17+
exit 1
18+
fi
19+
20+
# Check if book directory was created
21+
if [ ! -d "${BUILD_DIR}" ]; then
22+
echo " ${BUILD_DIR}/ directory not found after build!"
23+
exit 1
24+
fi
25+
26+
echo "Files in ${BUILD_DIR}/ directory:"
27+
ls -la "${BUILD_DIR}/"
28+
29+
# Load navbar builder functions
30+
source "$(dirname "$0")/navbar-builder.sh"
31+
32+
# Build navbar using configurable parameters
33+
build_navbar_into_files "${BUILD_DIR}"
34+
35+
echo "Documentation built successfully!"
36+
37+
# Copy to docs/ directory for GitHub Pages deployment
38+
echo "Copying documentation to ${DOCS_DIR}/ directory..."
39+
40+
# Remove existing content from docs/ (except PDFs if any)
41+
find "${DOCS_DIR}" -name "*.html" -delete 2>/dev/null || true
42+
find "${DOCS_DIR}" -name "*.css" -delete 2>/dev/null || true
43+
find "${DOCS_DIR}" -name "*.js" -delete 2>/dev/null || true
44+
find "${DOCS_DIR}" -type d -name "FontAwesome" -exec rm -rf {} + 2>/dev/null || true
45+
find "${DOCS_DIR}" -type d -name "fonts" -exec rm -rf {} + 2>/dev/null || true
46+
find "${DOCS_DIR}" -type d -name "css" -exec rm -rf {} + 2>/dev/null || true
47+
find "${DOCS_DIR}" -type d -name "resources" -exec rm -rf {} + 2>/dev/null || true
48+
find "${DOCS_DIR}" -type d -name "hardware" -exec rm -rf {} + 2>/dev/null || true
49+
find "${DOCS_DIR}" -type d -name "software" -exec rm -rf {} + 2>/dev/null || true
50+
51+
# Copy new built content to docs/
52+
cp -r "${BUILD_DIR}"/* "${DOCS_DIR}/"
53+
54+
echo "Updated ${DOCS_DIR}/ directory contents:"
55+
ls -la "${DOCS_DIR}/" | head -10
56+
57+
# Force commit the updated docs/ directory
58+
echo "Committing updated documentation to ${DOCS_DIR}/..."
59+
git add "${DOCS_DIR}/"
60+
61+
# Check if there are changes to commit
62+
if git diff --cached --quiet; then
63+
echo "ℹNo changes detected in ${DOCS_DIR}/ directory"
64+
else
65+
# Force commit changes
66+
echo "Committing documentation updates..."
67+
git commit -m "Auto-update documentation in ${DOCS_DIR}/
68+
69+
- Built from latest README content
70+
- Generated: $(date)
71+
- Updated navbar with configurable ${SHOP_TITLE} and ${REPO_TITLE} icons
72+
- Commit: $(git rev-parse --short HEAD)"
73+
74+
# Push to repository to trigger deployment
75+
echo "📡 Pushing to trigger GitHub Pages deployment..."
76+
git push origin "${GIT_BRANCH}"
77+
78+
if [ $? -eq 0 ]; then
79+
echo "Documentation successfully updated and pushed!"
80+
echo "GitHub Pages will deploy automatically in a few minutes"
81+
echo "Check deployment status at: ${REPO_URL}/actions"
82+
else
83+
echo "Failed to push to repository!"
84+
exit 1
85+
fi
86+
fi
87+
88+
echo "Documentation deployment process completed!"

.github/scripts/navbar-builder.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
# Navbar builder functions
3+
# This file contains reusable functions for building navbar elements
4+
5+
# Load configuration with robust path handling
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
source "${SCRIPT_DIR}/config.sh"
8+
9+
# Function to generate navbar JavaScript injection
10+
generate_navbar_js() {
11+
cat << EOF
12+
<script>
13+
document.addEventListener("DOMContentLoaded", function() {
14+
setTimeout(function() {
15+
const menuBar = document.querySelector(".menu-bar .right-buttons");
16+
if (menuBar) {
17+
// Shop Link
18+
const shopLink = document.createElement("a");
19+
shopLink.href = "${SHOP_URL}";
20+
shopLink.target = "_blank";
21+
shopLink.innerHTML = "${SHOP_ICON}";
22+
shopLink.title = "${SHOP_TITLE}";
23+
shopLink.style.cssText = "color: ${LINK_COLOR}; text-decoration: none; padding: ${LINK_PADDING}; font-size: ${LINK_FONT_SIZE}; margin-right: ${LINK_MARGIN}; border: 1px solid ${BORDER_COLOR}; border-radius: ${BORDER_RADIUS}; transition: all 0.2s ease; display: inline-block; text-align: center; width: ${LINK_WIDTH}; height: ${LINK_HEIGHT}; line-height: ${LINE_HEIGHT};";
24+
shopLink.onmouseover = function() { this.style.borderColor = "${HOVER_BORDER_COLOR}"; this.style.backgroundColor = "${HOVER_BG_COLOR}"; };
25+
shopLink.onmouseout = function() { this.style.borderColor = "${BORDER_COLOR}"; this.style.backgroundColor = "transparent"; };
26+
27+
// Repository Link
28+
const repoLink = document.createElement("a");
29+
repoLink.href = "${REPO_URL}";
30+
repoLink.target = "_blank";
31+
repoLink.innerHTML = "${REPO_ICON}";
32+
repoLink.title = "${REPO_TITLE}";
33+
repoLink.style.cssText = "color: ${LINK_COLOR}; text-decoration: none; padding: ${LINK_PADDING}; font-size: ${LINK_FONT_SIZE}; margin-right: ${LINK_MARGIN}; border: 1px solid ${BORDER_COLOR}; border-radius: ${BORDER_RADIUS}; transition: all 0.2s ease; display: inline-block; text-align: center; width: ${LINK_WIDTH}; height: ${LINK_HEIGHT}; line-height: ${LINE_HEIGHT};";
34+
repoLink.onmouseover = function() { this.style.borderColor = "${HOVER_BORDER_COLOR}"; this.style.backgroundColor = "${HOVER_BG_COLOR}"; };
35+
repoLink.onmouseout = function() { this.style.borderColor = "${BORDER_COLOR}"; this.style.backgroundColor = "transparent"; };
36+
37+
// Insert links in correct order
38+
menuBar.insertBefore(repoLink, menuBar.firstChild);
39+
menuBar.insertBefore(shopLink, menuBar.firstChild);
40+
}
41+
}, ${NAVBAR_INJECTION_DELAY});
42+
});
43+
</script>
44+
EOF
45+
}
46+
47+
# Function to build navbar into HTML files
48+
build_navbar_into_files() {
49+
local build_dir="$1"
50+
51+
echo " Building configurable navbar links..."
52+
53+
# Generate the JavaScript code
54+
local navbar_js=$(generate_navbar_js)
55+
56+
# Create temporary file with the JavaScript
57+
local temp_js_file=$(mktemp)
58+
echo "$navbar_js" > "$temp_js_file"
59+
60+
# Inject into all HTML files
61+
for html_file in "${build_dir}"/*.html "${build_dir}"/*/*.html "${build_dir}"/*/*/*.html; do
62+
if [ -f "$html_file" ]; then
63+
# Insert navbar JavaScript before closing body tag (without escape characters)
64+
sed -i "/<\/body>/r $temp_js_file" "$html_file"
65+
fi
66+
done
67+
68+
# Clean up
69+
rm "$temp_js_file"
70+
71+
echo "Navbar build completed using configuration variables!"
72+
}

0 commit comments

Comments
 (0)