Skip to content

Commit

Permalink
Random bdocs improvements (during time off)
Browse files Browse the repository at this point in the history
  • Loading branch information
internetisaiah committed Oct 11, 2024
1 parent c7839bd commit 66e3eee
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 39 deletions.
64 changes: 27 additions & 37 deletions bdocs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#!/bin/bash

# This is a bash script for interacting with the various files in './scripts/'.
# This is a wrapper script for interacting with the files in './scripts/'.
#
# Usage: ./bdocs [option]

set -e

# The project's root directory.
export PROJECT_ROOT
PROJECT_ROOT="$(dirname "$(realpath "$0")")"
export PROJECT_ROOT="$(dirname "$(realpath "$0")")"

# All scripts exported so they can source bdocs and call each other if needed.
export DEPLOY="$PROJECT_ROOT/scripts/create_deploy_text.sh"
export RELEASE="$PROJECT_ROOT/scripts/create_release_text.sh"
export TLINKS="$PROJECT_ROOT/scripts/transform_reference_links.py"
export RLINKS="$PROJECT_ROOT/scripts/remove_unused_reference_links.rb"
export REDIRECTS="$PROJECT_ROOT/scripts/list_redirect_urls.sh"

# Displays usage for bdocs
display_help() {
Expand All @@ -29,6 +35,14 @@ OPTIONS:
EOF
}

# If a file or directory is required, check if it was passed and block if not.
require_path_or_file() {
if [[ -z "$1" ]]; then
echo "Error: A file or directory path is required."
exit 1
fi
}

# Check if no arguments were provided
if [[ $# -eq 0 ]]; then
display_help
Expand All @@ -39,52 +53,28 @@ fi
case $1 in
deploy)
if [[ $# -eq 3 ]]; then
"$PROJECT_ROOT/scripts/create_deploy_text.sh" "$2" "$3"
"$DEPLOY" "$2" "$3"
else
"$PROJECT_ROOT/scripts/create_deploy_text.sh"
"$DEPLOY"
fi
;;
release)
"$PROJECT_ROOT/scripts/create_release_text.sh"
"$RELEASE"
;;
tlinks)
if [[ -z "$2" ]]; then
echo "Error: A file or directory path is required."
exit 1
fi
python3 "$PROJECT_ROOT/scripts/transform_reference_links.py" "$2"
echo "Success!"
while true; do
echo "Do you want to remove the unused reference links? [Y/n]."
read -r opt
case $opt in
y*|Y*)
ruby "$PROJECT_ROOT/scripts/remove_unused_reference_links.rb" "$2"
echo "Success!"
break
;;
n*|N*)
echo "The unused reference links were left untouched."
break
;;
*) echo "Error: Invalid choice."
echo ""
;;
esac
done
require_path_or_file "$2" && "$TLINKS" "$2"

# Run rlinks next to clean up unused reference links.
"$RLINKS" "$2"
;;
rlinks)
if [[ -z "$2" ]]; then
echo "Error: The path to file or directory is required."
exit 1
fi
ruby "$PROJECT_ROOT/scripts/remove_unused_reference_links.rb" "$2"
require_path_or_file "$2" && "$RLINKS" "$2"
;;
redirects)
if [[ $# -eq 2 ]]; then
"$PROJECT_ROOT/scripts/list_redirect_urls.sh" "$2"
"$REDIRECTS" "$2"
else
"$PROJECT_ROOT/scripts/list_redirect_urls.sh"
"$REDIRECTS"
fi
;;
help)
Expand Down
6 changes: 4 additions & 2 deletions scripts/create_release_text.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#
# Usage: ./bdocs release

source "$PROJECT_ROOT/bdocs"

main() {
# Run script from the root of the git repository.
cd "$PROJECT_ROOT"
Expand Down Expand Up @@ -38,9 +40,9 @@ main() {
COMMIT_TITLE=$(echo "$commit" | jq -r '.title')
COMMIT_BODY=$(echo "$commit" | jq -r '.body')

# Print the deploy text for each deployment.
# Print the deploy text for each deployment using the sourced DEPLOY.
echo "## $COMMIT_BODY"
./scripts/create_deploy_text.sh "$PREV_COMMIT_DATE" "$COMMIT_DATE"
"$DEPLOY" "$PREV_COMMIT_DATE" "$COMMIT_DATE"
echo ""

# Get the next range of commits by increasing 'PREV_COMMIT_DATE'.
Expand Down
2 changes: 2 additions & 0 deletions scripts/remove_unused_reference_links.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env ruby

# Removes unused reference-style links from the bottom of a file, such as:
# [1]: {{site.baseurl}}/contributing/your_first_contribution/
#
Expand Down
2 changes: 2 additions & 0 deletions scripts/transform_reference_links.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3

# Converts Markdown reference links to in-line links. Created because
# reference links cannot be placed inside Liquid {% tab %} tags.
#
Expand Down

0 comments on commit 66e3eee

Please sign in to comment.