Skip to content

Commit

Permalink
Support the .redirectweb file format for list.json.
Browse files Browse the repository at this point in the history
  • Loading branch information
mshibanami committed Nov 19, 2023
1 parent 418ee1e commit ab8f888
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions docs/scripts/generate-rule-set-list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,33 @@

cd "$(dirname "${BASH_SOURCE:-$0}")"

combined='[]'
supported_json_files=(
"rule-set.json"
"rule-set.redirectweb"
)

combined='[]'
for dir in ../rules-in-library/*; do
if [ -d "$dir" ] && [ -f "$dir/rule-set.json" ]; then
if [ -d "$dir" ]; then
id=$(basename "$dir" | cut -d'_' -f1)

if ! [[ $id =~ ^[0-9]+$ ]]; then
echo "❌ Error: Directory $dir does not start with '<number>_' format."
exit 1
fi

processed_json=$(jq --argjson id "$id" '{id: $id|tonumber, redirectList: .}' "$dir/rule-set.json")
combined=$(echo "$combined" | jq --argjson newElement "$processed_json" '. += [$newElement]')
json_file=""
for file in "${supported_json_files[@]}"; do
if [ -f "$dir/$file" ]; then
json_file="$dir/$file"
break
fi
done

if [ -n "$json_file" ]; then
processed_json=$(jq --argjson id "$id" '{id: $id|tonumber, redirectList: .}' "$json_file")
combined=$(echo "$combined" | jq --argjson newElement "$processed_json" '. += [$newElement]')
fi
fi
done

Expand Down

0 comments on commit ab8f888

Please sign in to comment.