Skip to content

Commit 0f5c0c1

Browse files
refactor fetch and build scripts
1 parent 572eea4 commit 0f5c0c1

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

build.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ else
1919
for file in "${files[@]}"; do
2020
id=$(jq -r '.id' "$file")
2121
author=$(jq -r '.author' "$file")
22-
profile=$(jq -r '.profile' "$file")
23-
unsplash=$(jq -r '.unsplash_url' "$file")
22+
profileUrl=$(jq -r '.profileUrl' "$file")
23+
photoUrl=$(jq -r '.photoUrl' "$file")
2424
image=${IMAGES_DIR}/${id}.webp
2525

2626
read -r -d '' item <<-EOF
@@ -34,8 +34,8 @@ else
3434
<img src="${image}" />
3535
</a>
3636
<figcaption>
37-
by <a href="$profile" target="_blank">$author</a> on
38-
<a href="$unsplash" target="_blank">Unsplash</a>
37+
by <a href="$profileUrl" target="_blank">$author</a> on
38+
<a href="$photoUrl" target="_blank">Unsplash</a>
3939
</figcaption>
4040
</figure>
4141
EOF

fetch.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,30 @@ echo "$response" | jq -c '.[]' | while read -r photo; do
3636
continue
3737
fi
3838

39-
raw_url=$(echo "$photo" | jq -r '.urls.raw')
39+
rawUrl=$(echo "$photo" | jq -r '.urls.raw')
4040
author=$(echo "$photo" | jq -r '.user.name')
4141
username=$(echo "$photo" | jq -r '.user.username')
42-
profile=$(echo "$photo" | jq -r '.user.links.html')
43-
photo_url=$(echo "$photo" | jq -r '.links.html')
44-
download_location=$(echo "$photo" | jq -r '.links.download_location')
42+
profileUrl=$(echo "$photo" | jq -r '.user.links.html')
43+
photoUrl=$(echo "$photo" | jq -r '.links.html')
44+
downloadLocation=$(echo "$photo" | jq -r '.links.download_location')
4545

46-
download_url="${raw_url}&h=${MAX_HEIGHT}&w=${MAX_WIDTH}&fit=max&fm=jpg&q=100"
46+
downloadUrl="${rawUrl}&h=${MAX_HEIGHT}&w=${MAX_WIDTH}&fit=max&fm=jpg&q=100"
4747

4848
echo "Downloading $id..."
4949

5050
# Track download (per Unsplash API guidelines)
51-
curl -s "${download_location}?client_id=${UNSPLASH_ACCESS_KEY}" >/dev/null
51+
curl -s "${downloadLocation}?client_id=${UNSPLASH_ACCESS_KEY}" >/dev/null
5252

53-
curl -fL "$download_url" -o "$OUTPUT_DIR/$id.jpg"
53+
curl -fL "$downloadUrl" -o "$OUTPUT_DIR/$id.jpg"
5454

5555
cat >"$OUTPUT_DIR/$id.json" <<EOF
5656
{
5757
"id": "$id",
5858
"author": "$author",
5959
"username": "$username",
60-
"profile": "$profile",
61-
"unsplash_url": "$photo_url",
62-
"downloaded_at": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
60+
"profileUrl": "$profileUrl",
61+
"photoUrl": "$photoUrl",
62+
"downloadedAt": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
6363
}
6464
EOF
6565
sleep 0.3

images/Uxqlfigh6oE.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "Uxqlfigh6oE",
33
"author": "Inside Weather",
44
"username": "insideweather",
5-
"profile": "https://unsplash.com/@insideweather",
6-
"unsplash_url": "https://unsplash.com/photos/black-and-brown-leather-padded-tub-sofa-Uxqlfigh6oE",
7-
"downloaded_at": "2026-04-18T15:03:40Z"
5+
"profileUrl": "https://unsplash.com/@insideweather",
6+
"photoUrl": "https://unsplash.com/photos/black-and-brown-leather-padded-tub-sofa-Uxqlfigh6oE",
7+
"downloadedAt": "2026-04-22T07:23:26Z"
88
}

0 commit comments

Comments
 (0)