forked from ScottLogic/blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bash script generates URLs for pa11y-ci from git diff
- Loading branch information
1 parent
45dfe7f
commit 5acdb7f
Showing
4 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env bash | ||
# Take in a base ref. Gets the files that have changed from the base to the HEAD. | ||
# 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 <base_ref>" | ||
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)',"; | ||
fi | ||
done | ||
echo -n "];"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
echo $1 | sed "s/\(\/\?index\)\?\.html$//"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
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/"; | ||
|