documentation/test.sh
2025-02-27 17:49:19 +07:00

44 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# Check if correct number of arguments is provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <source_folder> <destination_folder>"
exit 1
fi
SOURCE_DIR="$1"
DEST_DIR="$2"
# Check if source directory exists
if [ ! -d "$SOURCE_DIR" ]; then
echo "Error: Source directory '$SOURCE_DIR' does not exist"
exit 1
fi
# Create destination directory if it doesn't exist
mkdir -p "$DEST_DIR"
# Find all .rst files and process them
find "$SOURCE_DIR" -type f -name "*.rst" | while read -r rst_file; do
# Get the relative path from source directory
relative_path="${rst_file#$SOURCE_DIR/}"
# Create the output filename by replacing .rst with .md
md_file="$DEST_DIR/${relative_path%.rst}.md"
# Create the output directory structure
mkdir -p "$(dirname "$md_file")"
echo "Converting: $rst_file -> $md_file"
# Convert the file using pandoc
pandoc "$rst_file" -f rst -t markdown -o "$md_file"
if [ $? -eq 0 ]; then
echo "Successfully converted: $relative_path"
else
echo "Error converting: $relative_path"
fi
done
echo "Conversion complete!"