From c6aec1ed5e10fc36a4dfa15c7226d35933af69c2 Mon Sep 17 00:00:00 2001 From: shanecrowley Date: Tue, 10 Sep 2024 15:45:43 +0100 Subject: [PATCH] Add a check for preferred docs filetype 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. --- init.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/init.sh b/init.sh index dd7926b2..8cd00760 100755 --- a/init.sh +++ b/init.sh @@ -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..." @@ -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