Skip to content

Instantly share code, notes, and snippets.

@Gosev
Last active January 24, 2021 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gosev/e04abeb6079273b3be54ee6496a0b309 to your computer and use it in GitHub Desktop.
Save Gosev/e04abeb6079273b3be54ee6496a0b309 to your computer and use it in GitHub Desktop.
NextJS copy index.html files to their folder name
export S3_BUCKET='<enter s3 bucket>'
export PROFILE='<set your aws profile, or default>'
next build && next export
cd ./out
aws s3 cp . s3://${S3_BUCKET}/ --recursive --profile=${PROFILE} --exclude="*.html" --exclude=".git/*" --acl=public-read --cache-control max-age=7776000,public
aws s3 cp . s3://${S3_BUCKET}/ --recursive --profile=${PROFILE} --exclude "*" --include="*.html" --acl=public-read --cache-control max-age=600,public
find . -type f -name '*.html' | while read HTMLFILE; do
HTMLFILESHORT=${HTMLFILE:2}
#echo $HTMLFILE
#echo $HTMLFILESHORT
if [[ ${#HTMLFILESHORT} > 10 ]];
then
HTMLFILE_WITHOUT_INDEX=${HTMLFILESHORT::${#HTMLFILESHORT}-11}
# cp /about/index.html to /about
aws s3 cp s3://$S3_BUCKET/${HTMLFILESHORT} \
s3://$S3_BUCKET/$HTMLFILE_WITHOUT_INDEX \
--profile=${PROFILE} --acl public-read --cache-control max-age=600,public
if [ $? -ne 0 ]; then
echo "***** Failed renaming build to $S3_BUCKET/$NAMESPACE (html)"
exit 1
fi
fi
done
cd ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment