fix: Update URL replacement logic to handle runtime paths and add warnings for missing files

This commit is contained in:
Dries Augustyns
2026-01-11 08:26:59 +01:00
parent 73da0a5136
commit c07816c2a1
+39 -13
View File
@@ -40,16 +40,31 @@ replace_urls_in_app() {
# Process files using xargs for better performance # Process files using xargs for better performance
# Use -P 4 to process up to 4 files in parallel # Use -P 4 to process up to 4 files in parallel
# This significantly speeds up processing of many files # This significantly speeds up processing of many files
cat "$manifest_file" | xargs -P 4 -I {} sh -c ' #
file="{}" # IMPORTANT: The manifest contains build-time paths (e.g., /app/apps/web/.next/...)
if [ -f "$file" ]; then # but we need to translate them to runtime standalone paths
sed -e "s|'"$PLACEHOLDER_API"'|'"$API_URI"'|g" \ # (e.g., /app/apps/web/.next/standalone/apps/web/.next/...)
-e "s|'"$PLACEHOLDER_DASHBOARD"'|'"$DASHBOARD_URI"'|g" \ cat "$manifest_file" | while IFS= read -r build_path; do
-e "s|'"$PLACEHOLDER_LANDING"'|'"$LANDING_URI"'|g" \ # Translate build path to runtime standalone path
-e "s|'"$PLACEHOLDER_WIKI"'|'"$WIKI_URI"'|g" \ # Build path format: /app/apps/<app>/.next/...
"$file" > "${file}.tmp" && mv "${file}.tmp" "$file" # Runtime path format: /app/apps/<app>/.next/standalone/apps/<app>/.next/...
# Extract the relative path after /app/apps/<app>/
rel_path="${build_path#/app/apps/${app}/}"
# Construct runtime path in standalone directory
runtime_path="$app_dir/$rel_path"
if [ -f "$runtime_path" ]; then
sed -e "s|$PLACEHOLDER_API|$API_URI|g" \
-e "s|$PLACEHOLDER_DASHBOARD|$DASHBOARD_URI|g" \
-e "s|$PLACEHOLDER_LANDING|$LANDING_URI|g" \
-e "s|$PLACEHOLDER_WIKI|$WIKI_URI|g" \
"$runtime_path" > "${runtime_path}.tmp" && mv "${runtime_path}.tmp" "$runtime_path"
else
echo " ⚠️ Warning: File not found at runtime: $runtime_path"
fi fi
' done
echo " ✅ Successfully replaced URLs in $file_count files" echo " ✅ Successfully replaced URLs in $file_count files"
else else
@@ -61,14 +76,25 @@ replace_urls_in_app() {
local sitemap_manifest="$app_dir/.next/sitemap-manifest.txt" local sitemap_manifest="$app_dir/.next/sitemap-manifest.txt"
if [ -f "$sitemap_manifest" ]; then if [ -f "$sitemap_manifest" ]; then
while IFS= read -r sitemap_file; do while IFS= read -r build_sitemap_path; do
if [ -f "$sitemap_file" ]; then # Translate build path to runtime path
local rel_path="${sitemap_file#$app_dir/}" # Build path format: /app/apps/<app>/public/...
# Runtime path format: /app/apps/<app>/.next/standalone/apps/<app>/public/...
# Extract the relative path after /app/apps/<app>/
rel_path="${build_sitemap_path#/app/apps/${app}/}"
# Construct runtime path in standalone directory
runtime_sitemap_path="$app_dir/$rel_path"
if [ -f "$runtime_sitemap_path" ]; then
sed -e "s|$PLACEHOLDER_API|$API_URI|g" \ sed -e "s|$PLACEHOLDER_API|$API_URI|g" \
-e "s|$PLACEHOLDER_DASHBOARD|$DASHBOARD_URI|g" \ -e "s|$PLACEHOLDER_DASHBOARD|$DASHBOARD_URI|g" \
-e "s|$PLACEHOLDER_LANDING|$LANDING_URI|g" \ -e "s|$PLACEHOLDER_LANDING|$LANDING_URI|g" \
-e "s|$PLACEHOLDER_WIKI|$WIKI_URI|g" \ -e "s|$PLACEHOLDER_WIKI|$WIKI_URI|g" \
"$sitemap_file" > "${sitemap_file}.tmp" && mv "${sitemap_file}.tmp" "$sitemap_file" "$runtime_sitemap_path" > "${runtime_sitemap_path}.tmp" && mv "${runtime_sitemap_path}.tmp" "$runtime_sitemap_path"
else
echo " ⚠️ Warning: Sitemap file not found at runtime: $runtime_sitemap_path"
fi fi
done < "$sitemap_manifest" done < "$sitemap_manifest"
else else