workflow update
This commit is contained in:
parent
2c5b4f55d1
commit
2afea7b273
|
@ -42,56 +42,49 @@ jobs:
|
||||||
# Get the base directory of the readme file
|
# Get the base directory of the readme file
|
||||||
base_dir=$(dirname "./$rel_path")
|
base_dir=$(dirname "./$rel_path")
|
||||||
|
|
||||||
# Get the content of the README file
|
# Read content of the README file
|
||||||
content=$(cat "./$rel_path")
|
content=$(cat "./$rel_path")
|
||||||
|
|
||||||
# Find and process image references
|
# Process image references line by line for more reliable detection
|
||||||
# Look for markdown image syntax: 
|
while IFS= read -r line; do
|
||||||
image_refs=$(grep -o '!\[.*\](.*\)' "./$rel_path" | sed -E 's/!\[.*\]\((.*)\)/\1/')
|
if [[ $line =~ !\[([^]]*)\]\(([^)]+)\) ]]; then
|
||||||
|
img_path="${BASH_REMATCH[2]}"
|
||||||
# For each image reference
|
|
||||||
for img_path in $image_refs; do
|
|
||||||
# Skip URLs
|
|
||||||
if [[ $img_path == http* ]]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Determine the absolute path of the image
|
|
||||||
if [[ $img_path == /* ]]; then
|
|
||||||
# Absolute path within repository
|
|
||||||
abs_img_path="./$img_path"
|
|
||||||
else
|
|
||||||
# Relative path to the README
|
|
||||||
abs_img_path="$base_dir/$img_path"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Extract just the filename
|
|
||||||
img_filename=$(basename "$img_path")
|
|
||||||
wiki_img_path="images/$img_filename"
|
|
||||||
|
|
||||||
# Copy the image to wiki repository if it exists
|
|
||||||
if [ -f "$abs_img_path" ]; then
|
|
||||||
echo "Copying image: $abs_img_path -> ./wiki/$wiki_img_path"
|
|
||||||
cp "$abs_img_path" "./wiki/$wiki_img_path"
|
|
||||||
|
|
||||||
# Replace the image reference in content
|
# Skip URLs
|
||||||
# Escape special characters in the img_path for sed
|
if [[ $img_path == http* ]]; then
|
||||||
escaped_img_path=$(echo "$img_path" | sed 's/[\/&]/\\&/g')
|
continue
|
||||||
escaped_wiki_path=$(echo "$wiki_img_path" | sed 's/[\/&]/\\&/g')
|
fi
|
||||||
content=$(echo "$content" | sed "s/($escaped_img_path)/($escaped_wiki_path)/g")
|
|
||||||
else
|
# Determine the absolute path of the image
|
||||||
echo "Warning: Image file not found: $abs_img_path"
|
if [[ $img_path == /* ]]; then
|
||||||
|
# Absolute path within repository
|
||||||
|
abs_img_path="./$img_path"
|
||||||
|
else
|
||||||
|
# Relative path to the README
|
||||||
|
abs_img_path="$base_dir/$img_path"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extract just the filename
|
||||||
|
img_filename=$(basename "$img_path")
|
||||||
|
wiki_img_path="images/$img_filename"
|
||||||
|
|
||||||
|
# Copy the image to wiki repository if it exists
|
||||||
|
if [ -f "$abs_img_path" ]; then
|
||||||
|
echo "Copying image: $abs_img_path -> ./wiki/$wiki_img_path"
|
||||||
|
cp "$abs_img_path" "./wiki/$wiki_img_path"
|
||||||
|
|
||||||
|
# Replace the image reference in content using a safer delimiter
|
||||||
|
content=$(echo "$content" | sed "s|!\\[\(.*\\)\\]($img_path)||g")
|
||||||
|
echo "Replaced image reference: $img_path → $wiki_img_path"
|
||||||
|
else
|
||||||
|
echo "Warning: Image file not found: $abs_img_path"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done < "./$rel_path"
|
||||||
|
|
||||||
# Write the updated content to the wiki page
|
# Replace the wiki page with the updated content rather than appending
|
||||||
if [ -f "./wiki/$wiki_page" ]; then
|
echo -e "# $(basename "$wiki_page" .md)\n\nContent from $rel_path:\n\n$content" > "./wiki/$wiki_page"
|
||||||
# Append to existing page with a section header
|
echo "Updated wiki page: $wiki_page"
|
||||||
echo -e "\n\n## Content from $rel_path\n\n$content" >> "./wiki/$wiki_page"
|
|
||||||
else
|
|
||||||
# Create new page
|
|
||||||
echo -e "# $(basename "$wiki_page" .md)\n\nContent from $rel_path:\n\n$content" > "./wiki/$wiki_page"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue