Moving to Ghost, making it privacy friendly, and URL redirects

I recently migrated all my websites from WordPress to Ghost. It has been a joy so far. Ghost is built for blogging, and it does it well, but my main reason for switching is that it is fast and looks good out of the box. UPDATE: I switched back to WordPress 🙂 No automatic updates and no built in comments were not worth it.

However there was a slight problem initially as I found out that a fresh install of Ghost has several ”unnecessary” features (for me at least), such as subscription systems, email newsletters and analytics. It also loads several files from remote content delivery networks (CDNs), e.g. jQuery, Sodo-search (somewhat dependant on the theme you use) and multiple Stripe scripts, which was a problem as I did not want any third party connections when I or anyone else load my website. (Why can’t it be privacy friendly by default?) Time to fix that!

Modifying the settings

The first thing I did was go to the admin dashboard and disable everything not related to writing or publishing text on my website, meaning off with memberships, newsletters and analytics.

Ghost is also configured to use Unsplash by default as an integration. I disabled that too.

Modifying the server files

The theme I use (Dawn) loads jQuery and Sodo-search from CDNs by default, and the only way to load these locally is to upload the files to the server and load them from there instead (by modifying the Ghost configuration file as well as the theme files).

I opened up my website in the developer console (F12 in Firefox), went to the network tab and refreshed my page to see what loaded from external sites. I downloaded those files locally, uploaded them to my server and did the following;

Copied sodo-search.min.js and jquery-3.5.1.min.js to //content/themes/dawn/assets/js/, and sodo.main.css to /css/ instead of /js/.

Then I modified the theme file default.hbs (//content/themes/dawn/default.hbs) to use the local files instead:

Now jQuery loads locally. Time for Sodo-search. Open up Ghost’s config.production.json file and add the following to the file (in correct json syntax before the last ”}”):

"sodoSearch": {
   "url": "/assets/js/sodo-search.min.js",
   "styles": "/assets/css/sodo.main.css"

Now I did some chmod/chown on all added files to give them correct permissions and ownerships, reloaded Ghost and I was ready to go! I could now see that the scripts were loaded locally instead!

No more privacy-intrusive external scripts! 🙂

Bonus: URL redirects

As my blog posts on WordPress had the URL format, and Ghost use, I had to create a regex redirect to be able to redirect traffic from my old URLs to my new.

This was done by creating a file on my desktop called redirects.yaml and adding the following:

^\/([0-9][0-9][0-9][0-9])\/([0-9][0-9])\/([a-zA-Z0-9-]+)\/$: /$3

and uploading it to Ghost by going to the admin dashboard -> Settings -> Labs -> Upload redirects (YAML/JSON).

I won’t go through regex rules, but it basically rewrites my old URL into my new one. I used this tool to test my way into finding a rule that worked.

There’s a tutorial for this if you want to read more:

Thanks for reading! 🙂

Lämna en kommentar

Din e-postadress kommer inte publiceras. Obligatoriska fält är märkta *