Skip to content

Commit

Permalink
Add a check for preferred docs filetype
Browse files Browse the repository at this point in the history
This checks if the user wants to use md or rst.
After the preferred choice is selected files of the other type in the
target directory will be deleted.
If a filetype is defined in the CI this prompt is skipped.
  • Loading branch information
edibotopic committed Sep 11, 2024
1 parent 0912316 commit c6aec1e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,32 @@ if [ -z "$install_directory" ]; then
read -rp "Enter the installation directory (e.g., '.' or 'docs'): " install_directory
fi

# Check if md or rst is preferred for the documentation being built
promptForFileChoice()
{
while true; do
read -p "Will you be using the 'rst' or 'md' file format for the documentation (default: 'rst'): " filetype_choice

filetype_choice=${filetype_choice:-rst}

if [ "$filetype_choice" = "md" ] || [ "$filetype_choice" = "rst" ]; then
file_type="$filetype_choice"
echo "Setting filetype to: $file_type"
break
else
echo "Invalid input. Please enter either 'md' or 'rst':"
fi
done
}

# If variable filetype choice is defined in CI then don't prompt user for choice
if [ -z "${default_filetype_choice:-}" ]; then
promptForFileChoice
else
file_type="$default_filetype_choice"
echo "Using predefined filetype choice: $file_type"
fi

# Normalise the install_directory path
install_directory=$(realpath -m --relative-to="$(pwd)" "$install_directory")
echo "Installing at $install_directory..."
Expand Down Expand Up @@ -84,6 +110,17 @@ fi
echo "Copying contents to the installation directory..."
cp -R "$temp_directory"/sp-files/* "$temp_directory"/sp-files/.??* "$install_directory"

# Delete files with unpreferred filetype in the installation directory
if [ "$file_type" == 'md' ]; then
echo "Deleting rst files..."
rm "$install_directory"/index.rst
rm "$install_directory"/doc-cheat-sheet.rst
else
echo "Deleting md files..."
rm "$install_directory"/index.md
rm "$install_directory"/doc-cheat-sheet-myst.md
fi

# Ensure GitHub workflows and woke config are placed in the repo root
# if installing in a non-root directory
if [ "$install_directory" != "." ]; then
Expand Down

0 comments on commit c6aec1e

Please sign in to comment.