diff --git a/generate_pa11y_ci_urls_from_git_diff.sh b/generate_pa11y_ci_urls_from_git_diff.sh index 96e21c466a..cccff755bf 100644 --- a/generate_pa11y_ci_urls_from_git_diff.sh +++ b/generate_pa11y_ci_urls_from_git_diff.sh @@ -3,21 +3,39 @@ # Export the list as a CommonJS module for the pa11y-ci configuration to use. # Typical usage: generate_pa11y_ci_urls_from_git_diff.sh gh-pages > .pa11yci.js -base_ref=$1 -if [ -z "$base_ref" ]; then - echo "No Git base ref provided. Usage: $0 " - exit 1 -fi - -changed_files=$(git diff --name-only $base_ref) - -echo -n "module.exports=["; -for file in $changed_files; do - if [[ $file == _posts/* ]]; then - echo -n "'/$(./url_of_post.sh $file)',"; - elif [[ $file == *.html && ! $file == _includes/* && ! $file == _layouts/* ]]; then - echo -n "'/$(./url_of_page.sh $file)',"; +function generate_pa11y_ci_urls_from_git_diff { + base_ref=$1 + if [ -z "$base_ref" ]; then + echo "No Git base ref provided. Usage: $0 " + exit 1 fi -done -echo -n "];"; + + changed_files=$(git diff --name-only $base_ref) + + echo -n "module.exports=["; + for file in $changed_files; do + if [[ $file == _posts/* ]]; then + echo -n "'/$(url_of_post $file)',"; + elif [[ $file == *.html && ! $file == _includes/* && ! $file == _layouts/* ]]; then + echo -n "'/$(url_of_page $file)',"; + fi + done + echo -n "];"; +} + +function url_of_page { + echo $1 | sed "s/\(\/\?index\)\?\.html$//"; +} + +function url_of_post { + year="\([0-9][0-9][0-9][0-9]\)" + month="\([0-9][0-9]\)" + day="\([0-9][0-9]\)" + slug="\(.*\)" + file_ext="\(html\|markdown\|md\)" + + echo $1 | sed "s/^_posts\/$year-$month-$day-$slug\.$file_ext$/\1\/\2\/\3\/\4.html/"; +} + +generate_pa11y_ci_urls_from_git_diff $1 diff --git a/url_of_page.sh b/url_of_page.sh deleted file mode 100644 index 7d245a4258..0000000000 --- a/url_of_page.sh +++ /dev/null @@ -1,2 +0,0 @@ -echo $1 | sed "s/\(\/\?index\)\?\.html$//"; - diff --git a/url_of_post.sh b/url_of_post.sh deleted file mode 100644 index a639436393..0000000000 --- a/url_of_post.sh +++ /dev/null @@ -1,8 +0,0 @@ -year="\([0-9][0-9][0-9][0-9]\)" -month="\([0-9][0-9]\)" -day="\([0-9][0-9]\)" -slug="\(.*\)" -file_ext="\(html\|markdown\|md\)" - -echo $1 | sed "s/^_posts\/$year-$month-$day-$slug\.$file_ext$/\1\/\2\/\3\/\4.html/"; -