Last active
September 12, 2024 21:32
-
-
Save Gosev/e04abeb6079273b3be54ee6496a0b309 to your computer and use it in GitHub Desktop.
NextJS copy index.html files to their folder name
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
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