Skip to content

Commit

Permalink
Apply automatic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user authored and github-actions[bot] committed Oct 4, 2024
0 parents commit 9facf75
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/refresh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Format

on:
push:
schedule:
- cron: '*/15 * * * *'

env:
UNSPLASH_ACCESS_KEY: ${{ secrets.UNSPLASH_ACCESS_KEY }}

jobs:
format-code:
runs-on: ubuntu-latest

permissions:
contents: write

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: 'Update _redirects'
run: |
chmod +x ./refresher.sh
./refresher.sh
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_author: Author <[email protected]>
commit_options: '--amend --no-edit'
push_options: '--force'
skip_fetch: true
7 changes: 7 additions & 0 deletions _redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/internetztube/raw https://images.unsplash.com/photo-1589186050672-a42c96e47b6b?ixid=M3w2NjExODR8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MjgwNjMxNjB8&ixlib=rb-4.0.3 302
/internetztube/full https://images.unsplash.com/photo-1589186050672-a42c96e47b6b?crop=entropy&cs=srgb&fm=jpg&ixid=M3w2NjExODR8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MjgwNjMxNjB8&ixlib=rb-4.0.3&q=85 302
/internetztube/regular https://images.unsplash.com/photo-1589186050672-a42c96e47b6b?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w2NjExODR8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MjgwNjMxNjB8&ixlib=rb-4.0.3&q=80&w=1080 302
/internetztube/small https://images.unsplash.com/photo-1589186050672-a42c96e47b6b?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w2NjExODR8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MjgwNjMxNjB8&ixlib=rb-4.0.3&q=80&w=400 302
/internetztube/thumb https://images.unsplash.com/photo-1589186050672-a42c96e47b6b?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w2NjExODR8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MjgwNjMxNjB8&ixlib=rb-4.0.3&q=80&w=200 302
/internetztube/small_s3 https://s3.us-west-2.amazonaws.com/images.unsplash.com/small/photo-1589186050672-a42c96e47b6b 302
/* https://github.com/internetztube/unsplash-random 301
36 changes: 36 additions & 0 deletions refresher.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

# Get your Unsplash Access Key it from here:
# https://unsplash.com/oauth/applications/new
# UNSPLASH_ACCESS_KEY=""

# Multi line string of Unsplash usernames.
# The Unsplash Demo API has a Rate Limit of 50 requests per hour. Therefore, you can put up to 50 usernames in here.
# Feel free to add your username!
UNSPLASH_USERNAMES="
internetztube
"

FALLBACK_TARGET="https://github.com/internetztube/unsplash-random"
FILENAME="_redirects"

rm $FILENAME
touch $FILENAME

echo "$UNSPLASH_USERNAMES" | while read -r username; do
username=$(echo "$username" | xargs)

if [ -n "$username" ]; then
response=$(curl -s "https://api.unsplash.com/photos/random?username=${username}&client_id=${UNSPLASH_ACCESS_KEY}")
response=$(echo $response | tr -d '\000-\037')

for url in $(echo $response | jq -r '.urls | to_entries[] | "\(.key)=\(.value)"'); do
echo "/$username/${url%%=*} ${url#*=} 302" >> $FILENAME
done

fi
done

if ! [ -z "$FALLBACK_TARGET" ]; then
echo "/* ${FALLBACK_TARGET} 301" >> $FILENAME
fi

0 comments on commit 9facf75

Please sign in to comment.