To develop my custom theme, I run a local Ghost instance. To populate the local instance with content, I import the content from my production website via the “Export your content” feature in Settings>Labs.
There are some issues with this approach. For example, the “Export” feature does not include images, and to get the images I need to take some additional steps. Furthermore, as I keep adding content, keeping local content up-to-date becomes a chore.
I am looking for a way to “connect” my local Ghost instance to my production instance so that all content on my production server is mirrored in the local, and I have an up-to-date view of my content as I develop my theme.
This should be possible with the Content API, but what would be a reasonable way to implement it?
This is a great question, and I’m excited to hear how other devs approach this challenge.
First, does your development site need to be 1:1 copy of the original? If it has similar data, is that enough to do theme development?
Alternatively, you could edit your export file to use the production image URLs. Your Ghost export will use __GHOST_URL__ for the first part of the path. If you find and replace this to https://www.designdisciplin.com/, then your images should load without having to download them.
I recently came across the same challenge and found a solution by running a shell script to download production images.
Here’s a Gist with the script, along with the gist of what to do below.
1. Import content
Export production content as a single, glorious JSON file from the admin settings. Import the JSON file from time to time, whenever you’d like to keep content in sync.
2. Download images
In the production admin settings, creating a new custom integration—name whatever you’d like—to obtain a Content API key. Add your API key, URL, and directory paths to the environment file, .env.
Make the script executable, then run the in the command line. If all goes well, sit back and enjoy seeing all the images download.
chmod +x download-images.sh
./download-images.sh
Run this script from time to time, whenever you’d like to keep images in sync.
While not a mirrored setup, this solution works for my purposes and seems to be 1:1 with production.
Update: I implemented a simple sync service. It fetches all posts from a remote Ghost instance and recreates them locally (with remote images) + keeps them in sync every
X minutes (5 by default, changeable over .env file)
Here’s the code, to give you an idea
It’s currently part of a theme but I could abstract it into a separate docker container, if that helps and people still have this problem.
Cheers.
PS: You need an admin-api key for this to work properly