I’m trying to make changes to multiple posts at once by exporting everything into a JSON file, making changes to the html entity for the relevant articles, then importing the file back into Ghost.
The changes I have made to the JSON file involve turning specific keywords into links. For example, replacing the words ‘car rental’ with '<a href="https://www.carnextdoor.com.au/car-rental">car rental</a>. I’ve spent the past few days building a Python script to successfully make these changes in the html entity for each article within the JSON file.
Unfortunately, though, the new links aren’t appearing on the blog.
I noticed that there is a ‘plaintext’ entity for each post in the JSON file as well as the ‘html’ entity. Do I need to make the changes to that too? What is the relationship between the ‘plaintext’ entity and ‘html’ entity for each article?
Any help would be much appreciated! (I’ve spent so long creating the ‘find and replace’ Python script and it’s so annoying to be stuck on this final step )
I noticed that there is a ‘plaintext’ entity for each post in the JSON file as well as the ‘html’ entity. Do I need to make the changes to that too? What is the relationship between the ‘plaintext’ entity and ‘html’ entity for each article?
Both the HTML and plaintext fields are generated from the mobiledoc field, which is Ghosts base content format. If you’re doing a full export, editing the html and uploading the full JSON back, the changes to the HTML field won’t be picked up.
For what you’re doing it would make way more sense and be simpler to use the API, not the importer.
FYI there is a demo of a find and replace API script in our api demos repo.
The first section shows how to do a find and replace in the mobiledoc field:
The second (commented) section shows how you can do a find and replace in HTML and tell the API to treat the HTML as the source for the content, rather than mobiledoc:
Given I’m not that experienced with these technical things (APIs etc), and it took me a long time to build the Python script, I think it might be faster for me to stick with the exporting and importing JSON method.
FYI, it’s not a straightforward ‘find and replace’ for a single string. I’m checking the contents of each post against a list of keywords with accompanying URLs, and then updating the keyword in the article with the respective link.
If I amend the code to do the replacement on the mobiledoc object, will that work okay? Or would I need to do the same replacement on the mobiledoc and HTML?