Skip to content

Instantly share code, notes, and snippets.

@jcayouette
Created July 16, 2024 13:32
Show Gist options
  • Save jcayouette/d05d850b91e586c466cd47b25c9a1dcc to your computer and use it in GitHub Desktop.
Save jcayouette/d05d850b91e586c466cd47b25c9a1dcc to your computer and use it in GitHub Desktop.
Section title comparison checks
#!/bin/bash
# Base directory containing Antora documentation
BASE_DIR="path/to/docs"
# Array of navigation files
NAV_FILES=(
"nav-administration-guide.adoc"
"nav-client-configuration-guide.adoc"
"nav-common-workflows-guide.adoc"
"nav-installation-and-upgrade-guide.adoc"
"nav-quickstart-guide.adoc"
"nav-reference-guide.adoc"
"nav-retail-guide.adoc"
"nav-specialized-guides-guide.adoc"
)
# Function to extract section titles from a document
extract_section_titles() {
local file="$1"
grep -E '^=|^==|^===|^====' "$file" | sed 's/^=*\s*//'
}
# Loop through each navigation file
for nav_file in "${NAV_FILES[@]}"; do
# Extract the bookname from the navigation file path
BOOKNAME=$(echo "$nav_file" | sed 's/^nav-\(.*\)-guide\.adoc/\1/')
# Full path to the navigation file
NAV_FILE="${BASE_DIR}/modules/${BOOKNAME}/${nav_file}"
# Check if the navigation file exists
if [[ ! -f "$NAV_FILE" ]]; then
echo "Navigation file '$NAV_FILE' not found."
continue
fi
# Extract navigation titles
NAV_TITLES=$(grep -E '^\* ' "$NAV_FILE" | sed 's/^\*\s*//')
# Initialize an empty array to store section titles
SECTION_TITLES=()
# Loop through all .adoc files in the corresponding module directory
for file in $(find "${BASE_DIR}/modules/${BOOKNAME}" -name '*.adoc' -not -name "$nav_file"); do
# Extract section titles and add them to the SECTION_TITLES array
while IFS= read -r title; do
SECTION_TITLES+=("$title")
done < <(extract_section_titles "$file")
done
# Compare navigation titles with section titles
echo "Comparing navigation titles with section titles for '$nav_file'..."
for nav_title in $NAV_TITLES; do
if [[ ! " ${SECTION_TITLES[@]} " =~ " ${nav_title} " ]]; then
echo "Mismatch: Navigation title '${nav_title}' not found in section titles"
fi
done
# Optionally, check if all section titles are in the navigation
for section_title in "${SECTION_TITLES[@]}"; do
if [[ ! " ${NAV_TITLES} " =~ " ${section_title} " ]]; then
echo "Note: Section title '${section_title}' not found in navigation titles"
fi
done
echo "Comparison complete for '$nav_file'."
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment