Remove "Publish with Ghost" button on portal

Hello all,

I managed to override Portal (portal.min.js).
I needed it for translation and to remove “Publish with Ghost” button on Portal.

This solution is for self-hosted Ghost instance. I don’t see any possibility to do it in Ghost Pro (I’ve switched to Digital Ocean droplet, so now I can override Portal).

How to override and customize Portal

Check url of your Portal in
/var/www/ghost/versions/{version}/core/shared/config/defaults.json
(can vary on different Ghost versions). In my example it looks like:

"portal": {
    "url": "https://unpkg.com/@tryghost/portal@~1.1.0/umd/portal.min.js",
    "version": "~1.1.0"
}

Open:
/var/www/ghost/config.{environment}.json
on your server and add:

"portal": {
    "url": "/assets/built/portal.js",
    "version": "~1.1.0"
}

You’ll need to restart Ghost in order to see changes made in config.{environment}.json:

ghost restart -d /var/www/ghost

Additional information about config.{environment}.json:

Unminify the JS file from the url you had in your Ghost instance (in my example: https://unpkg.com/@tryghost/portal@~1.1.0/umd/portal.min.js) with some online tool (google it: “unminify js online”).

Paste unminified JS to new portal.js file which should be creted under assets directory of your theme.

Remove code in portal.js responsible for adding “Publish with Ghosts” button on Portal:

Dt.createElement(
	"div",
	{ className: "gh-portal-powered" + (tn(["preview"]) ? " hidden" : "") },
	Dt.createElement(
		"a",
		{
			href: "https://ghost.org",
			target: "_blank",
			rel: "noopener noreferrer",
			onClick: function () {
				window.open("https://ghost.org", "_blank");
			},
		},
		Dt.createElement(At, null),
		" ",
		Dt.createElement("span", null, "Publish with Ghost")
	)
)

or add translations if you want them. CTRL + F is your friend.

Make sure that your theme will compile portal.js into assets/built/portal.js.

Casper Theme 4.0.4 example: portal.js compilation

The portal.js file can be created under /assets/portal/portal.js.

Then you need to modify gulpfile.js, so it will be compiled under /assets/built/portal.js.

Follow the below steps (everything should be done in gulpfile.js):

[1] Add:

function portal(done) {
    pump([
        src([
            'assets/portal/*.js'
        ], {sourcemaps: true}),
        concat('portal.js'),
        uglify(),
        dest('assets/built/', {sourcemaps: '.'}),
        livereload()
    ], handleError(done));
}

after function js(done).

[2] Add:

const portalWatcher = () => watch('assets/portal/**', portal);

after const cssWatcher.

[3] Change:

const watcher = parallel(cssWatcher, hbsWatcher);

to

const watcher = parallel(cssWatcher, portalWatcher, hbsWatcher);

[4] Change:

const build = series(css, js);

to

const build = series(css, js, portal);

And that’s it! Enjoy your customized Portal :)

Cloudflare cache issue

I had an issue where changes were not visible for https://example.com/assets/built/portal.js after Theme update.

I had to login to Cloudflare and go to: CachingConfigurationPurge CachePurge Everything in order to see updated portal.js

Real Ghost site example with Polish translation and without “Publish with Ghost” button

You can see it here: https://javowiec.pl

1 Like