Skip to content

Commit

Permalink
Improvements to script to generate all image sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stono committed Jan 5, 2019
1 parent 9d86e5c commit 9f2e5fb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Expand Up @@ -2,9 +2,13 @@ FROM centos:7
MAINTAINER Karl Stoney <me@karlstoney.com>

# Get dependencies
RUN yum -y -q install which curl wget gettext patch gcc-c++ make git-core bzip2 unzip && \
RUN yum -y -q install which curl wget gettext patch gcc-c++ make git-core bzip2 unzip gcc python-devel python-setuptools redhat-rpm-config && \
yum -y -q clean all

# Install crcmod
RUN easy_install -U pip && \
pip install -U crcmod

# Get nodejs repos
RUN curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -

Expand Down
38 changes: 36 additions & 2 deletions bin/generate_static_content.sh
@@ -1,11 +1,45 @@
#!/bin/bash
set -e
cd /static
rm -rf *
mkdir content
cp -R $GHOST_HOME/current/content/images content/

echo "Running gssg..."
gssg --domain "http://127.0.0.1" --dest . --url "https://$GHOST_DOMAIN"

echo "Download all sizes of images"
cd /static/content/images
sizes=( "w600" "w1000" "w2000" )

function getImage() {
file=$1
for size in "${sizes[@]}"; do
targetFile="/static/content/images/size/$size/$file"
path=$(dirname $targetFile)
mkdir -p $path
if [ ! -f $targetFile ]; then
echo "Getting: $targetFile"
curl -f --silent -o $targetFile http://127.0.0.1/content/images/size/$size/$file
else
echo "Skipping: $targetFile"
fi
done
}

echo "Downloading images that have already been sized"
cd /static/content/images
for file in $(find size -type f -o -name "*.png"); do
source=$(echo $file | sed 's,^[^/]*/,,' | sed 's,^[^/]*/,,')
getImage $source
done

echo "Downloading images that have not already been sized"
for file in $(find . -path ./size -prune -type f -o -name "*.png"); do
source=$(echo $file | sed 's,^[^/]*/,,')
getImage $source
done

echo "Static content generated!"
echo "Uploading to gcs..."
gsutil -m rsync -R . gs://$GHOST_DOMAIN
cd /static
gsutil -m rsync -d -c -R . gs://$GHOST_DOMAIN
2 changes: 1 addition & 1 deletion docker-compose.yml
Expand Up @@ -10,7 +10,7 @@ services:
args:
GCLOUD_VERSION: 227.0.0
GHOST_VERSION: 2.9.1
SITEMAP_GENERATOR_VERSION: 0.0.15
SITEMAP_GENERATOR_VERSION: 0.1.0-1
restart: always
environment:
NODE_ENV: production
Expand Down

0 comments on commit 9f2e5fb

Please sign in to comment.