Skip to content

Commit 8d20c5c

Browse files
committed
chore: enhance documentation generation with link fixing and front matter updates
- Added a JavaScript file to fix links in the generated documentation, ensuring they include the correct baseurl. - Updated the fix-schema-links.sh script to handle absolute and relative links more effectively. - Enhanced process-docs.sh to add front matter to root markdown files, improving navigation and organization. - Adjusted the test-docs-generation.yml workflow to ensure proper execution of scripts and verification of documentation output.
1 parent 84a8e7c commit 8d20c5c

4 files changed

Lines changed: 126 additions & 96 deletions

File tree

.github/scripts/docs/create-jekyll-config.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,33 @@ table {
162162
}
163163
EOF
164164

165+
# Add Javascript to fix any remaining links
166+
echo "📝 Creating link-fixer JavaScript..."
167+
mkdir -p site-src/assets/js
168+
cat > site-src/assets/js/fix-links.js << 'EOF'
169+
document.addEventListener('DOMContentLoaded', function() {
170+
// Fix all links that should have the baseurl
171+
document.querySelectorAll('a[href^="/"]').forEach(function(link) {
172+
if (!link.href.includes('/forms-engine-plugin') &&
173+
!link.href.match(/^https?:\/\//) &&
174+
!link.getAttribute('href').startsWith('/forms-engine-plugin')) {
175+
const href = link.getAttribute('href');
176+
link.href = '/forms-engine-plugin' + href;
177+
}
178+
});
179+
});
180+
EOF
181+
182+
# Add it to the config
183+
echo "" >> site-src/_config.yml
184+
echo "# Custom scripts" >> site-src/_config.yml
185+
echo "head_scripts:" >> site-src/_config.yml
186+
echo " - /assets/js/fix-links.js" >> site-src/_config.yml
187+
188+
# Create custom includes directory to add baseurl meta tag
189+
mkdir -p site-src/_includes
190+
cat > site-src/_includes/head_custom.html << 'EOF'
191+
<meta name="baseurl" content="{{ site.baseurl }}">
192+
EOF
193+
165194
echo "✅ Jekyll configuration files created successfully!"

.github/scripts/docs/fix-schema-links.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,27 @@ else
66
SED_INPLACE=(-i "")
77
fi
88

9-
# Use relative path from script directory
10-
BASE_DIR="../../../site-src"
11-
cd $(dirname "$0")
12-
echo "Working from $(pwd)"
9+
# Working directly in the site-src directory
10+
BASE_DIR="."
11+
echo "Working from $(pwd) - processing files in $BASE_DIR"
1312

1413
echo "🔍 Starting comprehensive schema link fixing process..."
1514

1615
# 1. Process all files recursively, with special handling for schema files
17-
find "$BASE_DIR" -type f -name "*.md" | while read file; do
16+
find "$BASE_DIR" -type f -name "*.md" | grep -v "node_modules" | while read file; do
1817
if [[ "$file" == *"/schemas/"* ]]; then
1918
echo -n "."
2019
else
2120
echo "Processing: $file"
2221
fi
2322

24-
# === Fix all .md links to match Jekyll's pretty permalinks ===
23+
# === Fix all .md links to match Jekyll's pretty permalinks AND add baseurl ===
2524
sed "${SED_INPLACE[@]}" -E 's|\[([^]]+)\]\(([^)]+)\.md(#[^)]+)?\)|\[\1\]\(/forms-engine-plugin/\2\3\)|g' "$file"
2625
sed "${SED_INPLACE[@]}" -E 's|\[([^]]+)\]\(([^)]+)\.md\)|\[\1\]\(/forms-engine-plugin/\2\)|g' "$file"
26+
# Fix plain / roots to include baseurl
27+
sed "${SED_INPLACE[@]}" -E 's|\[([^]]+)\]\(\/([^)]+)\)|\[\1\]\(/forms-engine-plugin/\2\)|g' "$file"
28+
# Fix relative links to be absolute with baseurl
29+
sed "${SED_INPLACE[@]}" -E 's|\[([^]]+)\]\(\./([^)]+)\)|\[\1\]\(/forms-engine-plugin/\2\)|g' "$file"
2730

2831
# === Specific handling for schema files ===
2932
if [[ "$file" == *"/schemas/"* ]]; then

.github/scripts/docs/process-docs.sh

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fi
1313
echo "🔄 Processing documentation files..."
1414

1515
# Set the correct base path
16-
BASE_DIR="site-src"
16+
BASE_DIR="."
1717

1818
# Define core schemas - these will be shown in navigation
1919
CORE_SCHEMAS=(
@@ -26,6 +26,80 @@ CORE_SCHEMAS=(
2626
"page-schema-v2"
2727
)
2828

29+
# ====== NEW: Process root documentation files ======
30+
echo "🔧 Processing root documentation files..."
31+
# Convert INDEX.md to index.md for Jekyll compatibility
32+
if [ -f "INDEX.md" ] && [ ! -f "index.md" ]; then
33+
echo " Converting INDEX.md to index.md..."
34+
cp "INDEX.md" "index.md"
35+
36+
# Ensure index.md has proper front matter
37+
if ! grep -q "^---" "index.md"; then
38+
echo " Adding front matter to index.md..."
39+
temp_file="index.md.tmp"
40+
echo "---" > "$temp_file"
41+
echo "layout: default" >> "$temp_file"
42+
echo "title: DXT Documentation" >> "$temp_file"
43+
echo "nav_order: 1" >> "$temp_file"
44+
echo "permalink: /" >> "$temp_file"
45+
echo "---" >> "$temp_file"
46+
echo "" >> "$temp_file"
47+
cat "index.md" >> "$temp_file"
48+
mv "$temp_file" "index.md"
49+
fi
50+
fi
51+
52+
# Process all root markdown files
53+
for doc_file in $(find . -maxdepth 1 -name "*.md"); do
54+
base_name=$(basename "$doc_file" .md)
55+
56+
# Skip files that already have front matter
57+
if grep -q "^---" "$doc_file"; then
58+
echo " Front matter exists in $doc_file"
59+
continue
60+
fi
61+
62+
# Add front matter based on filename
63+
case "$base_name" in
64+
"index"|"INDEX")
65+
nav_order=1
66+
title="DXT Documentation"
67+
;;
68+
"GETTING_STARTED")
69+
nav_order=2
70+
title="Getting Started"
71+
;;
72+
"PLUGIN_OPTIONS")
73+
nav_order=3
74+
title="Plugin Options"
75+
;;
76+
"CONTRIBUTING")
77+
nav_order=4
78+
title="Contributing"
79+
;;
80+
"SCHEMA_REFERENCE")
81+
nav_order=5
82+
title="Schema Reference"
83+
;;
84+
*)
85+
nav_order=10
86+
title=$(echo "$base_name" | sed 's/_/ /g')
87+
;;
88+
esac
89+
90+
echo " Adding front matter to $doc_file..."
91+
temp_file="${doc_file}.tmp"
92+
echo "---" > "$temp_file"
93+
echo "layout: default" >> "$temp_file"
94+
echo "title: $title" >> "$temp_file"
95+
echo "nav_order: $nav_order" >> "$temp_file"
96+
echo "---" >> "$temp_file"
97+
echo "" >> "$temp_file"
98+
cat "$doc_file" >> "$temp_file"
99+
mv "$temp_file" "$doc_file"
100+
done
101+
102+
# ===== Continue with existing schema processing =====
29103
# Check if directories exist and display useful messages
30104
if [ ! -d "$BASE_DIR/schemas" ]; then
31105
echo "⚠️ Directory $BASE_DIR/schemas not found. Skipping schema processing."

.github/workflows/test-docs-generation.yml

Lines changed: 13 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ jobs:
8585
- name: Fix documentation links
8686
run: |
8787
echo "🔄 Fixing documentation links..."
88-
chmod +x .github/scripts/docs/fix-schema-links.sh
89-
.github/scripts/docs/fix-schema-links.sh
88+
cd site-src
89+
chmod +x ../.github/scripts/docs/fix-schema-links.sh
90+
../.github/scripts/docs/fix-schema-links.sh
91+
cd ..
9092
9193
- name: Create Jekyll configuration
9294
run: |
@@ -103,103 +105,36 @@ jobs:
103105
JEKYLL_ENV=production bundle exec jekyll build --destination ../_site
104106
cd ..
105107
106-
# Fix capitalization issues
107-
echo "🔧 Fixing case sensitivity issues..."
108-
if [ -f "_site/INDEX.html" ] && [ ! -f "_site/index.html" ]; then
109-
echo "🔄 Renaming INDEX.html to index.html..."
110-
cp "_site/INDEX.html" "_site/index.html"
111-
fi
112-
113-
# Fix unconverted markdown files - with proper paths
114-
echo "🔧 Handling unconverted markdown files..."
115-
for md_file in $(find _site -name "*.md"); do
116-
html_file="${md_file%.md}.html"
117-
dir_name=$(dirname "$md_file")
118-
base_name=$(basename "$md_file" .md)
119-
120-
echo " Converting $md_file to HTML..."
121-
122-
# Create a minimal HTML version of the markdown file that uses the baseurl
123-
cat > "$html_file" << EOF
124-
<html>
125-
<head>
126-
<title>$base_name</title>
127-
<meta http-equiv="refresh" content="0; url='/forms-engine-plugin$dir_name/$base_name/'">
128-
</head>
129-
<body>
130-
<h1>$base_name</h1>
131-
<p>Redirecting to <a href="/forms-engine-plugin$dir_name/$base_name/">/forms-engine-plugin$dir_name/$base_name/</a></p>
132-
</body>
133-
</html>
134-
EOF
135-
136-
# Create directory and index.html for pretty URLs
137-
mkdir -p "_site$dir_name/$base_name"
138-
139-
# Create an index.html in the subdirectory with the actual content
140-
cat > "_site$dir_name/$base_name/index.html" << EOF
141-
<html>
142-
<head>
143-
<title>$base_name</title>
144-
<link rel="stylesheet" href="/forms-engine-plugin/assets/css/just-the-docs-default.css">
145-
</head>
146-
<body>
147-
<div class="main-content">
148-
<h1>$base_name</h1>
149-
<div class="content">
150-
$(cat "$md_file" | sed 's|](/|](/forms-engine-plugin/|g')
151-
</div>
152-
</div>
153-
</body>
154-
</html>
155-
EOF
156-
157-
# Remove the original markdown file
158-
rm "$md_file"
159-
done
160-
161-
# Ensure lowercase 'index' directory exists for assets
162-
if [ -d "_site/INDEX" ]; then
163-
echo "🔄 Creating lowercase version of INDEX directory..."
164-
mkdir -p "_site/index"
165-
cp -r "_site/INDEX/"* "_site/index/" 2>/dev/null || echo "No files to copy (empty directory)"
166-
fi
167-
168108
# Verification steps
169109
echo "🔍 Verifying build results..."
170110
171111
# Show root files explicitly
172-
echo "📄 Files at site root after fixes:"
112+
echo "📄 Files at site root:"
173113
ls -la _site/
174114
175115
# Check for HTML files
176-
echo "✓ HTML files generated from markdown and fixes:"
116+
echo "✓ HTML files generated from markdown:"
177117
find _site -name "*.html" | grep -v "assets" | head -n 15
178118
html_count=$(find _site -name "*.html" | wc -l)
179119
echo " Total HTML files: $html_count"
180120
181-
# List remaining markdown files (if any)
121+
# Check if any markdown files remain in output (there shouldn't be any)
182122
md_files=$(find _site -name "*.md" | wc -l)
183123
if [ "$md_files" -gt 0 ]; then
184-
echo "⚠️ WARNING: Still found $md_files markdown files in output:"
124+
echo "⚠️ WARNING: Found $md_files markdown files in output (should be 0):"
185125
find _site -name "*.md" | head -n 10
186126
else
187127
echo "✅ No markdown files found in output (good!)"
188128
fi
189129
190-
# Check for previously failed files
191-
for check_file in "features/configuration-based/PAGE_TEMPLATES" "features/configuration-based/PAGE_EVENTS" "features/code-based/PAGE_VIEWS"; do
192-
if [ -f "_site/$check_file.html" ] || [ -d "_site/$check_file" ]; then
193-
echo "✅ Successfully handled: $check_file"
130+
# Check for specific problematic files to make sure they were converted
131+
for check_file in "features/configuration-based/PAGE_TEMPLATES.html" "features/configuration-based/PAGE_EVENTS.html" "features/code-based/PAGE_VIEWS.html"; do
132+
if [ -f "_site/$check_file" ]; then
133+
echo "✅ Successfully converted: $check_file"
194134
else
195-
echo "❌ FAILED to handle: $check_file"
135+
echo "❌ FAILED to convert: $check_file"
196136
fi
197137
done
198-
199-
# Final output structure
200-
echo "📊 Final site structure:"
201-
find _site -type f | grep -e "index.html" -e "features" | sort | head -n 15
202-
echo "... (and more files)"
203138
204139
- name: Setup Pages
205140
uses: actions/configure-pages@v5
@@ -214,14 +149,3 @@ jobs:
214149
uses: actions/deploy-pages@v4
215150
with:
216151
timeout: 600000 # 10 minutes in milliseconds
217-
218-
run: |
219-
echo "🔧 Verifying Jekyll baseurl configuration..."
220-
if ! grep -q "baseurl: \"/forms-engine-plugin\"" site-src/_config.yml; then
221-
sed -i.bak 's|baseurl: ""|baseurl: "/forms-engine-plugin"|g' site-src/_config.yml
222-
sed -i.bak 's|baseurl: "/"|baseurl: "/forms-engine-plugin"|g' site-src/_config.yml
223-
rm -f site-src/_config.yml.bak
224-
echo "✅ Updated baseurl in _config.yml"
225-
else
226-
echo "✅ baseurl already correctly configured"
227-
fi

0 commit comments

Comments
 (0)