Esse quam videri.

To be rather than to seem to be rather than to seem to be rather than to seem.

By Sanjay Kannan
So what is Skalon?

Slugs With Slashes

Blogging with Ghost is great, but its support for categories is limited. We're stuck with a monolithic format for slugs, and instead of having pretty links like travel/Germany and food/NYC/Ippudo, we get URLs like dogs-are-cute and my-fun-beach-trip. Not a massive deal, but it kills the polish.

This is more of a design choice than a serious technical restriction. In fact, you can change the internals of Ghost to support slugs with slashes, and even if you cannot autogenerate pretty URLs using categories, you should be able to manually specify the full path to each of your posts. Here's how:

  1. Upgrade to the latest LTS version of Ghost. These instructions are confirmed to work with 0.11.11 and some previous versions as well. These instructions do not work for Ghost 1.x.

  2. Navigate to the root folder of your Ghost installation. This should contain folders like core and content.

  3. Download this Gist, and replace core/server/controllers/frontend/post-lookup.js with the downloaded file. The code to look up posts has been amended for slugs with slashes.

  4. Open core/built/assets/ghost.min.js in your favorite text editor (Vim). Search for encodeURIComponent in the file, and you should see a snippet of code starting with api("slugs" and ending with encodeURIComponent(t)). Replace that entire snippet (being sure to include the trailing parenthesis) with api("slugs",e).slice(0,-5)+encodeURIComponent(t).replace(/%2F/g, '/'). Now the post editor will correctly send slugs with slashes to the server.

  5. Open core/server/utils/index.js. Look for a variable called string, and look for an assignment to string with a regular expression in a call to replace. You should see a portion of that expression that looks like |\/. Delete those three characters only! This will stop the server from sanitizing slashes in slugs.

  6. Open core/server/routes/api.js. Find the string that looks like slugs/:type/:name and change it to slugs/:name(*). The API routing handler will correctly capture slugs with slashes in the URL.

  7. Open core/server/api/slugs.js. Look for a return statement that is returning an unknownSlugType error. It should be contained inside an if statement. Comment out the return statement.

  8. Above the commented-out return statement, add a line that looks like options.type = 'post';, and then another line that looks like if ( === '/') =, -1);. This will prevent the server from complaining that there is no post type associated with the slug, and remove a trailing slash from the final output.

Whew! You're done. Now go be pedantic about something else. (Thanks to Matthew Miller for inspiring some of these changes.)

< Previous Post
Frist Psot