Skip to content

Instantly share code, notes, and snippets.

@edrex
Last active May 5, 2016 21:27
Show Gist options
  • Save edrex/7492725 to your computer and use it in GitHub Desktop.
Save edrex/7492725 to your computer and use it in GitHub Desktop.
Upload static site to S3 with clean URLs
#!/bin/sh
# Be sure to set the index and 404 docs to "index" and "404" respectively in your bucket settings
# replace with your compile command
harp compile ./ ./out
# removes the html extension
for f in `ls out/*.html out/**/*.html`; do mv $f "${f%%.*}"; done
# requires s3cmd >= v1.5.0-beta1 for
# https://github.com/s3tools/s3cmd/issues/243
s3cmd sync --default-mime-type="text/html; charset=utf-8" --guess-mime-type --delete-removed out/ s3://eric.pdxhub.org/
@cardoni
Copy link

cardoni commented May 5, 2016

Thanks for this scrip, @edrex!

I should mention that I couldn't get this to work in zsh on Mac OS X. It would rename all the files, stripping off the extension—didn't succeed in copying them into any new folders or renaming them to index.html

Did you ever get this working as you expected? Seems like something more like the code below if necessary to accomplish what you wanted?

for f in `ls out/*.html out/**/*.html`; do mkdir -p "${f%%.*}" && mv $f "${f%%.*}/index.html"; done

Edit

Looking back at the issues page, it seems someone posted this, which looks promising. I'll play around with it:

for FILENAME in public/posts/*.html public/projects/*.html; do
    [[ "$FILENAME" = "index.html" ]] && continue
    DIRNAME="${FILENAME%.html}"
    mkdir -p "$DIRNAME"
    mv "$FILENAME" "$DIRNAME/index.html"
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment