"Coming Soon" page + private blogging


#1

I have some WordPress development experience and am trying out Ghost for a new project. The private blogging feature is great for building out the initial content prior to going public with the site, but I’d like the main URL – www.example.com – to display a custom, static HTML, “Coming Soon” page instead of redirecting to www.example.com/private/

I’m aware that I could simply customize the private.hbs template with my “Coming Soon” info, and that would work for me if I could change the redirect path to something more friendly than “/private/”, e.g., www.example.com/coming-soon/

Any ideas how to achieve that?


#2

Currently you can’t do that via config, maybe you should be able to though!

If you want to dig into the code here is where you’ll wanna start - https://github.com/TryGhost/Ghost/blob/master/core/server/apps/private-blogging/lib/middleware.js#L12

Hope this helps :relaxed:


#3

Thanks, @fabien … Yes, it helps a lot! This will be my first go at server-side javascript coding, so I hope you don’t mind a few more questions:

  1. Aside from the evil of hacking core files, would simply changing line 12 from…
    const privateRoute = '/private/';
    …to…
    const privateRoute = '/coming-soon/';
    …be enough to change the URL to which anonymous users are redirected?

  2. Is there a way to change that constant without modifying a core file?

  3. Would I also need to change ‘private’ to ‘coming-soon’ in line 7 of index.js, here:

PS: Yes, I’d love to see this as a config option!


#4

No probs!

Looks like you’re right about 3 - you’ll probably want to change that too :slight_smile:

As for changing it without modifying core files - nope not at the moment, we’re open source and accept PRs though!

Good luck, have fun :tada:


#5

Followup: The above described changes appear to have worked. Here’s a summary for anyone who want’s to replicate what I did:

  1. Download a copy of your active theme from your site’s admin backend, at the bottom of www.yoursite.com/ghost/#/settings/design and unzip it.

  2. In this downloaded copy of your theme, save a copy of private.hbs, https://raw.githubusercontent.com/TryGhost/Ghost/master/core/server/apps/private-blogging/lib/views/private.hbs , then open it in a text editor.

  3. On line 26, add these id and style attributes to hide the password form:
    <section class="gh-flow-content" id="private" style="display:none">.

  4. I put my “Coming Soon” content just above this <section> tag, but it can go anywhere except in that section. It can be a whole page or just a single line, like <h1 style="text-align:center; margin: 25vh 5%">YourSite.com is coming soon!</h1>

  5. At the end of the template, just above </body>, add this link:
    <a style="position:fixed; z-index:9999; bottom:0; left:0; line-height:1; font-size:24px; cursor:pointer" onclick="document.getElementById('private').style.display='block'">&nbsp;&nbsp;</a>
    This will create an invisible link in the lower-left corner of the page, which you can click to unhide the password form.

  6. Re-zip your theme folder and upload it via the same admin panel from which you downloaded it.

If you want the URL redirect path to be /coming-soon/ (or whatever you like) instead of /private/, make the two edits described in the previous posts. I did it via SSH:

ssh root@your-domain-or-ip-address
su - ghost-mgr
# Your file paths may vary:
cd /var/www/ghost
# Edit the files with your preferred editor:
nano /var/www/ghost/versions/2.9.0/core/server/apps/private-blogging/index.js
# In line 7 of index.js, change 'private' to 'coming-soon'. Save changes. Then...
nano /var/www/ghost/versions/2.9.0/core/server/apps/private-blogging/lib/middleware.js
# In line 12 of middleware.js, change '/private/' to '/coming-soon/'.
# Save changes. Then activate the changes by restarting Ghost...
ghost restart
# I assume the site was down during the restart, but it only took a few seconds.

The redirect URL is still a bit ugly because of Ghost’s added query string, /coming-soon/?r=%2F, but it’s tolerable. If I had more time to waste I’d figure out how to lose the query. :slight_smile:

Thanks again, @fabien, for your support.

PS: This approach could also be used for taking a site offline temporarily for maintenance, major upgrades, etc.


#6

Thanks for documenting!