Created
November 26, 2019 23:21
-
-
Save ojame/72548c1591ed24ec3ca0023872f8a419 to your computer and use it in GitHub Desktop.
Webflow to FTP/external host
This file contains hidden or 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
#### | |
# -i the location of the zip file from webflow | |
# -u the username of the sftp user for wpengine | |
# | |
# example: ./webflow-processor.sh -i | |
#### | |
while getopts "i:u:" OPTION | |
do | |
case $OPTION in | |
i) | |
INPUT=$OPTARG;; | |
u) | |
SFTP_USERNAME=$OPTARG;; | |
esac | |
done | |
echo 'Enter the name of the zip file e.g. webflow.zip' | |
read INPUT | |
# Make folder for unzipped files | |
DESTINATION="$(basename $INPUT .zip)-processed" | |
rm -rf $DESTINATION | |
mkdir $DESTINATION | |
# Unzip file | |
unzip -q $INPUT -d $DESTINATION | |
# Replace example.com/index.html with example.com | |
LC_ALL=C find $DESTINATION -type f -name '*.html' -exec sed -i '' s/index\\.html//g {} + | |
echo 'Removed occurances of index.html' | |
# Replace all [name].html references with [name] | |
LC_ALL=C find $DESTINATION -type f -name '*.html' -exec sed -i '' s/\\.html//g {} + | |
echo 'Stripped .html extensions from links' | |
# If there's a file [customers.html] and there's a folder [/customers] | |
# Move that file into that folder and rename it [index.html] | |
for ENTRY in "$DESTINATION"/*/ | |
do | |
FOLDER_NAME=$(basename "${ENTRY}") | |
if test -f "$DESTINATION/$FOLDER_NAME.html"; then | |
mv "$DESTINATION/$FOLDER_NAME.html" "$DESTINATION/$FOLDER_NAME/index.html" | |
echo "Moved $DESTINATION/$FOLDER_NAME.html => $DESTINATION/$FOLDER_NAME/index.html" | |
sed -i.bak 's~<head[^>]*>~&<base href="/">~' "$DESTINATION/$FOLDER_NAME/index.html" | |
rm "$DESTINATION/$FOLDER_NAME/index.html.bak" | |
fi | |
done | |
echo "Processed files located in ${DESTINATION}" | |
open $DESTINATION |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment